r102652 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102651‎ | r102652 | r102653 >
Date:13:29, 10 November 2011
Author:freakolowsky
Status:ok
Tags:
Comment:
some more oracle-phpunit-fu (should not affect non-oracle)
* CloneDatabase - already droping tables in internal function, removed duplicate action
* DatabaseOracle - stopped ignoring "temporary" parameter
* added two parameters to phpunit (use-normal-tables & reuse-db), default actions stay the same
* with reuse-db oracle phpunit test run on oracle down to 1m 20s ;)
Modified paths:
  • /trunk/phase3/includes/db/CloneDatabase.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/tests/phpunit/MediaWikiPHPUnitCommand.php (modified) (history)
  • /trunk/phase3/tests/phpunit/MediaWikiTestCase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/MediaWikiTestCase.php
@@ -11,6 +11,7 @@
1212 protected $db;
1313 protected $oldTablePrefix;
1414 protected $useTemporaryTables = true;
 15+ protected $reuseDB = false;
1516 private static $dbSetup = false;
1617
1718 /**
@@ -41,8 +42,10 @@
4243 ObjectCache::$instances[CACHE_DB] = new HashBagOStuff;
4344
4445 if( $this->needsDB() ) {
45 -
4646 global $wgDBprefix;
 47+
 48+ $this->useTemporaryTables = !$this->getCliArg( 'use-normal-tables' );
 49+ $this->reuseDB = $this->getCliArg('reuse-db');
4750
4851 $this->db = wfGetDB( DB_MASTER );
4952
@@ -82,7 +85,31 @@
8386 function addDBData() {}
8487
8588 private function addCoreDBData() {
 89+ if ( $this->db->getType() == 'oracle' ) {
8690
 91+ # Insert 0 user to prevent FK violations
 92+ # Anonymous user
 93+ $this->db->insert( 'user', array(
 94+ 'user_id' => 0,
 95+ 'user_name' => 'Anonymous' ), __METHOD__, array( 'IGNORE' ) );
 96+
 97+ # Insert 0 page to prevent FK violations
 98+ # Blank page
 99+ $this->db->insert( 'page', array(
 100+ 'page_id' => 0,
 101+ 'page_namespace' => 0,
 102+ 'page_title' => ' ',
 103+ 'page_restrictions' => NULL,
 104+ 'page_counter' => 0,
 105+ 'page_is_redirect' => 0,
 106+ 'page_is_new' => 0,
 107+ 'page_random' => 0,
 108+ 'page_touched' => $this->db->timestamp(),
 109+ 'page_latest' => 0,
 110+ 'page_len' => 0 ), __METHOD__, array( 'IGNORE' ) );
 111+
 112+ }
 113+
87114 User::resetIdByNameCache();
88115
89116 //Make sysop user
@@ -115,32 +142,17 @@
116143
117144 $dbClone = new CloneDatabase( $this->db, $this->listTables(), $this->dbPrefix() );
118145 $dbClone->useTemporaryTables( $this->useTemporaryTables );
119 - $dbClone->cloneTableStructure();
120146
 147+ if ( ( $this->db->getType() == 'oracle' || !$this->useTemporaryTables ) && $this->reuseDB ) {
 148+ CloneDatabase::changePrefix( $this->dbPrefix() );
 149+ $this->resetDB();
 150+ return;
 151+ } else {
 152+ $dbClone->cloneTableStructure();
 153+ }
 154+
121155 if ( $this->db->getType() == 'oracle' ) {
122156 $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' );
123 -
124 - # Insert 0 user to prevent FK violations
125 - # Anonymous user
126 - $this->db->insert( 'user', array(
127 - 'user_id' => 0,
128 - 'user_name' => 'Anonymous' ) );
129 -
130 - # Insert 0 page to prevent FK violations
131 - # Blank page
132 - $this->db->insert( 'page', array(
133 - 'page_id' => 0,
134 - 'page_namespace' => 0,
135 - 'page_title' => ' ',
136 - 'page_restrictions' => NULL,
137 - 'page_counter' => 0,
138 - 'page_is_redirect' => 0,
139 - 'page_is_new' => 0,
140 - 'page_random' => 0,
141 - 'page_touched' => $this->db->timestamp(),
142 - 'page_latest' => 0,
143 - 'page_len' => 0 ) );
144 -
145157 }
146158 }
147159
@@ -149,35 +161,29 @@
150162 */
151163 private function resetDB() {
152164 if( $this->db ) {
153 - foreach( $this->listTables() as $tbl ) {
154 - if( $tbl == 'interwiki' || $tbl == 'user' || $tbl == 'MWUSER' ) continue;
155 - if ( $this->db->getType() == 'oracle' )
156 - $this->db->query( 'TRUNCATE TABLE '.$this->db->tableName($tbl), __METHOD__ );
157 - else
158 - $this->db->delete( $tbl, '*', __METHOD__ );
 165+ if ( $this->db->getType() == 'oracle' ) {
 166+ if ( $this->useTemporaryTables ) {
 167+ wfGetLB()->closeAll();
 168+ $this->db = wfGetDB( DB_MASTER );
 169+ } else {
 170+ foreach( $this->listTables() as $tbl ) {
 171+ if( $tbl == 'interwiki') continue;
 172+ $this->db->query( 'TRUNCATE TABLE '.$this->db->tableName($tbl), __METHOD__ );
 173+ }
 174+ }
 175+ } else {
 176+ foreach( $this->listTables() as $tbl ) {
 177+ if( $tbl == 'interwiki' || $tbl == 'user' ) continue;
 178+ $this->db->delete( $tbl, '*', __METHOD__ );
 179+ }
159180 }
160 -
161 - if ( $this->db->getType() == 'oracle' ) {
162 - # Insert 0 page to prevent FK violations
163 - # Blank page
164 - $this->db->insert( 'page', array(
165 - 'page_id' => 0,
166 - 'page_namespace' => 0,
167 - 'page_title' => ' ',
168 - 'page_restrictions' => NULL,
169 - 'page_counter' => 0,
170 - 'page_is_redirect' => 0,
171 - 'page_is_new' => 0,
172 - 'page_random' => 0,
173 - 'page_touched' => $this->db->timestamp(),
174 - 'page_latest' => 0,
175 - 'page_len' => 0 ) );
176 - }
177181 }
178182 }
179183
180184 protected function destroyDB() {
181 - if ( $this->useTemporaryTables || is_null( $this->db ) ) {
 185+ if ( is_null( $this->db ) ||
 186+ ( $this->useTemporaryTables && $this->db->getType() != 'oracle' ) ||
 187+ ( $this->reuseDB ) ) {
182188 # Don't need to do anything
183189 return;
184190 }
Index: trunk/phase3/tests/phpunit/MediaWikiPHPUnitCommand.php
@@ -6,6 +6,8 @@
77 'regex=' => false,
88 'file=' => false,
99 'keep-uploads' => false,
 10+ 'use-normal-tables' => false,
 11+ 'reuse-db' => false,
1012 );
1113
1214 public function __construct() {
@@ -62,6 +64,11 @@
6365 --keep-uploads Re-use the same upload directory for each test, don't delete it
6466
6567
 68+Database options:
 69+ --use-normal-tables Use normal DB tables.
 70+ --reuse-db Init DB only if tables are missing and keep after finish.
 71+
 72+
6673 EOT;
6774 }
6875
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -746,7 +746,7 @@
747747 }
748748
749749 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseOracle::duplicateTableStructure' ) {
750 - $temporary = 'FALSE'; //$temporary ? 'TRUE' : 'FALSE';
 750+ $temporary = $temporary ? 'TRUE' : 'FALSE';
751751
752752 $newName = strtoupper( $newName );
753753 $oldName = strtoupper( $oldName );
Index: trunk/phase3/includes/db/CloneDatabase.php
@@ -98,7 +98,7 @@
9999 self::changePrefix( $this->newTablePrefix );
100100 $newTableName = $this->db->tableName( $tbl, 'raw' );
101101
102 - if( $this->dropCurrentTables && !in_array( $this->db->getType(), array( 'postgres' ) ) ) {
 102+ if( $this->dropCurrentTables && !in_array( $this->db->getType(), array( 'postgres', 'oracle' ) ) ) {
103103 $this->db->dropTable( $tbl, __METHOD__ );
104104 wfDebug( __METHOD__." dropping {$newTableName}\n", true);
105105 //Dropping the oldTable because the prefix was changed

Status & tagging log