Added profiling to test runner.
authordaniel <daniel.kinzler@wikimedia.de>
Thu, 22 Nov 2012 18:34:32 +0000 (19:34 +0100)
committerdaniel <daniel.kinzler@wikimedia.de>
Thu, 22 Nov 2012 18:34:32 +0000 (19:34 +0100)
MediaWikiTestCase now calls wfProfileIn/wfProfileOut for each call
to a test function. This makes it easy to track down slow tests.

Change-Id: I5ff2fea957c082f41da37936fe44948ad006f573

tests/phpunit/MediaWikiPHPUnitCommand.php
tests/phpunit/MediaWikiTestCase.php

index 473e641..2745c6a 100644 (file)
@@ -54,8 +54,12 @@ class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
        }
 
        public function run( array $argv, $exit = true ) {
+               wfProfileIn( __METHOD__ );
+
                $ret = parent::run( $argv, false );
 
+               wfProfileOut( __METHOD__ );
+
                // Return to real wiki db, so profiling data is preserved
                MediaWikiTestCase::teardownTestDB();
 
index c619dab..f28f379 100644 (file)
@@ -64,6 +64,9 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                 */
                ObjectCache::$instances[CACHE_DB] = new HashBagOStuff;
 
+               $needsResetDB = false;
+               $logName = get_class( $this ) . '::' . $this->getName( false );
+
                if( $this->needsDB() ) {
                        // set up a DB connection for this test to use
 
@@ -75,22 +78,34 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        $this->checkDbIsSupported();
 
                        if( !self::$dbSetup ) {
+                               wfProfileIn( $logName . ' (clone-db)' );
+
                                // switch to a temporary clone of the database
                                self::setupTestDB( $this->db, $this->dbPrefix() );
 
                                if ( ( $this->db->getType() == 'oracle' || !self::$useTemporaryTables ) && self::$reuseDB ) {
                                        $this->resetDB();
                                }
+
+                               wfProfileOut( $logName . ' (clone-db)' );
                        }
 
+                       wfProfileIn( $logName . ' (prepare-db)' );
                        $this->addCoreDBData();
                        $this->addDBData();
+                       wfProfileOut( $logName . ' (prepare-db)' );
+
+                       $needsResetDB = true;
+               }
 
-                       parent::run( $result );
+               wfProfileIn( $logName );
+               parent::run( $result );
+               wfProfileOut( $logName );
 
+               if( $needsResetDB ) {
+                       wfProfileIn( $logName . ' (reset-db)' );
                        $this->resetDB();
-               } else {
-                       parent::run( $result );
+                       wfProfileOut( $logName . ' (reset-db)' );
                }
        }
 
@@ -133,6 +148,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         * happen in reverse order.
         */
        protected function setUp() {
+               wfProfileIn( __METHOD__ );
                parent::setUp();
 
                /*
@@ -161,9 +177,13 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                                $this->db->rollback();
                        }
                }
+
+               wfProfileOut( __METHOD__ );
        }
 
        protected function tearDown() {
+               wfProfileIn( __METHOD__ );
+
                // Cleaning up temporary files
                foreach ( $this->tmpfiles as $fname ) {
                        if ( is_file( $fname ) || ( is_link( $fname ) ) ) {
@@ -187,6 +207,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                $this->mwGlobals = array();
 
                parent::tearDown();
+               wfProfileOut( __METHOD__ );
        }
 
        /**