some more oracle-phpunit-fu (should not affect non-oracle)
authorJure Kajzer <freakolowsky@users.mediawiki.org>
Thu, 10 Nov 2011 13:29:32 +0000 (13:29 +0000)
committerJure Kajzer <freakolowsky@users.mediawiki.org>
Thu, 10 Nov 2011 13:29:32 +0000 (13:29 +0000)
* 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 ;)

includes/db/CloneDatabase.php
includes/db/DatabaseOracle.php
tests/phpunit/MediaWikiPHPUnitCommand.php
tests/phpunit/MediaWikiTestCase.php

index f29e0b2..bd0895c 100644 (file)
@@ -98,7 +98,7 @@ class CloneDatabase {
                        self::changePrefix( $this->newTablePrefix );
                        $newTableName = $this->db->tableName( $tbl, 'raw' );
                        
-                       if( $this->dropCurrentTables && !in_array( $this->db->getType(), array( 'postgres' ) ) ) {
+                       if( $this->dropCurrentTables && !in_array( $this->db->getType(), array( 'postgres', 'oracle' ) ) ) {
                                $this->db->dropTable( $tbl, __METHOD__ );
                                wfDebug( __METHOD__." dropping {$newTableName}\n", true);
                                //Dropping the oldTable because the prefix was changed
index a5ceceb..cafd1e9 100644 (file)
@@ -746,7 +746,7 @@ class DatabaseOracle extends DatabaseBase {
        }
 
        function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseOracle::duplicateTableStructure' ) {
-               $temporary = 'FALSE'; //$temporary ? 'TRUE' : 'FALSE';
+               $temporary = $temporary ? 'TRUE' : 'FALSE';
 
                $newName = strtoupper( $newName );
                $oldName = strtoupper( $oldName );
index c6f0420..7d544ea 100644 (file)
@@ -6,6 +6,8 @@ class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
                'regex=' => false,
                'file=' => false,
                'keep-uploads' => false,
+               'use-normal-tables' => false,
+               'reuse-db' => false,
        );
 
        public function __construct() {
@@ -62,6 +64,11 @@ ParserTest-specific options:
   --keep-uploads           Re-use the same upload directory for each test, don't delete it
 
 
+Database options:
+  --use-normal-tables      Use normal DB tables.
+  --reuse-db               Init DB only if tables are missing and keep after finish.
+
+
 EOT;
        }
 
index 0dc32f3..82b2a47 100644 (file)
@@ -11,6 +11,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        protected $db;
        protected $oldTablePrefix;
        protected $useTemporaryTables = true;
+       protected $reuseDB = false;
        private static $dbSetup = false;
 
        /**
@@ -41,8 +42,10 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                ObjectCache::$instances[CACHE_DB] = new HashBagOStuff;
 
                if( $this->needsDB() ) {
-
                        global $wgDBprefix;
+                       
+                       $this->useTemporaryTables = !$this->getCliArg( 'use-normal-tables' );
+                       $this->reuseDB = $this->getCliArg('reuse-db');
 
                        $this->db = wfGetDB( DB_MASTER );
 
@@ -82,6 +85,30 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        function addDBData() {}
 
        private function addCoreDBData() {
+               if ( $this->db->getType() == 'oracle' ) {
+
+                       # Insert 0 user to prevent FK violations
+                       # Anonymous user
+                       $this->db->insert( 'user', array(
+                               'user_id'               => 0,
+                               'user_name'     => 'Anonymous' ), __METHOD__, array( 'IGNORE' ) );
+
+                       # Insert 0 page to prevent FK violations
+                       # Blank page
+                       $this->db->insert( 'page', array(
+                               'page_id' => 0,
+                               'page_namespace' => 0,
+                               'page_title' => ' ',
+                               'page_restrictions' => NULL,
+                               'page_counter' => 0,
+                               'page_is_redirect' => 0,
+                               'page_is_new' => 0,
+                               'page_random' => 0,
+                               'page_touched' => $this->db->timestamp(),
+                               'page_latest' => 0,
+                               'page_len' => 0 ), __METHOD__, array( 'IGNORE' ) );
+
+               }
 
                User::resetIdByNameCache();
 
@@ -115,32 +142,17 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
 
                $dbClone = new CloneDatabase( $this->db, $this->listTables(), $this->dbPrefix() );
                $dbClone->useTemporaryTables( $this->useTemporaryTables );
-               $dbClone->cloneTableStructure();
+
+               if ( ( $this->db->getType() == 'oracle' || !$this->useTemporaryTables ) && $this->reuseDB ) {
+                       CloneDatabase::changePrefix( $this->dbPrefix() );
+                       $this->resetDB();
+                       return;
+               } else {
+                       $dbClone->cloneTableStructure();
+               }
 
                if ( $this->db->getType() == 'oracle' ) {
                        $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' );
-
-                       # Insert 0 user to prevent FK violations
-                       # Anonymous user
-                       $this->db->insert( 'user', array(
-                               'user_id'               => 0,
-                               'user_name'     => 'Anonymous' ) );
-
-                       # Insert 0 page to prevent FK violations
-                       # Blank page
-                       $this->db->insert( 'page', array(
-                               'page_id' => 0,
-                               'page_namespace' => 0,
-                               'page_title' => ' ',
-                               'page_restrictions' => NULL,
-                               'page_counter' => 0,
-                               'page_is_redirect' => 0,
-                               'page_is_new' => 0,
-                               'page_random' => 0,
-                               'page_touched' => $this->db->timestamp(),
-                               'page_latest' => 0,
-                               'page_len' => 0 ) );
-
                }
        }
 
@@ -149,35 +161,29 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         */
        private function resetDB() {
                if( $this->db ) {
-                       foreach( $this->listTables() as $tbl ) {
-                               if( $tbl == 'interwiki' || $tbl == 'user' || $tbl == 'MWUSER' ) continue;
-                               if ( $this->db->getType() == 'oracle' ) 
-                                       $this->db->query( 'TRUNCATE TABLE '.$this->db->tableName($tbl), __METHOD__ );
-                               else
-                                       $this->db->delete( $tbl, '*', __METHOD__ );
-                       }
-
-                       if ( $this->db->getType() == 'oracle' ) {
-                               # Insert 0 page to prevent FK violations
-                               # Blank page
-                               $this->db->insert( 'page', array(
-                                       'page_id' => 0,
-                                       'page_namespace' => 0,
-                                       'page_title' => ' ',
-                                       'page_restrictions' => NULL,
-                                       'page_counter' => 0,
-                                       'page_is_redirect' => 0,
-                                       'page_is_new' => 0,
-                                       'page_random' => 0,
-                                       'page_touched' => $this->db->timestamp(),
-                                       'page_latest' => 0,
-                                       'page_len' => 0 ) );
+                       if ( $this->db->getType() == 'oracle' )  {
+                               if ( $this->useTemporaryTables ) {
+                                       wfGetLB()->closeAll();
+                                       $this->db = wfGetDB( DB_MASTER );
+                               } else {
+                                       foreach( $this->listTables() as $tbl ) {
+                                               if( $tbl == 'interwiki') continue;
+                                               $this->db->query( 'TRUNCATE TABLE '.$this->db->tableName($tbl), __METHOD__ );
+                                       }
+                               }
+                       } else {
+                               foreach( $this->listTables() as $tbl ) {
+                                       if( $tbl == 'interwiki' || $tbl == 'user' ) continue;
+                                               $this->db->delete( $tbl, '*', __METHOD__ );
+                               }
                        }
                }
        }
 
        protected function destroyDB() {
-               if ( $this->useTemporaryTables || is_null( $this->db ) ) {
+               if ( is_null( $this->db ) || 
+                       ( $this->useTemporaryTables && $this->db->getType() != 'oracle' ) ||
+                       ( $this->reuseDB ) ) {
                        # Don't need to do anything
                        return;
                }