From e2bb376dd7a357b77e937a09ced55f832ae99049 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 22 Nov 2012 19:34:32 +0100 Subject: [PATCH] Added profiling to test runner. 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 | 4 ++++ tests/phpunit/MediaWikiTestCase.php | 27 ++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/MediaWikiPHPUnitCommand.php b/tests/phpunit/MediaWikiPHPUnitCommand.php index 473e6413b7..2745c6a0f4 100644 --- a/tests/phpunit/MediaWikiPHPUnitCommand.php +++ b/tests/phpunit/MediaWikiPHPUnitCommand.php @@ -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(); diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index c619dab805..f28f379793 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -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__ ); } /** -- 2.20.1