From: daniel Date: Tue, 13 Nov 2012 16:51:32 +0000 (+0100) Subject: Log profiling data when tests have finished. X-Git-Tag: 1.31.0-rc.0~21586^2 X-Git-Url: http://git.cyclocoop.org/data/%24self?a=commitdiff_plain;h=e606537090ebbd93cc0413d74e8347869336e7d0;p=lhc%2Fweb%2Fwiklou.git Log profiling data when tests have finished. Previously, no profiling data was recorded from unit test runs. That made it impossible to a) use unit tests for selective profiling of individual functions, and b) made it impossibel to profile the tests themselves. This change fixes this problem by calling wfLogProfilingData() after the test runner has finished. Thaks to Hashar for some ideas, especially the fix in GlobalFunctions. Change-Id: Iaa295115f3c4eb3b529388dcd953fe8932448b3e --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 3de25e716d..4763c4af9b 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1214,9 +1214,18 @@ function wfLogProfilingData() { if ( $wgUser->isItemLoaded( 'id' ) && $wgUser->isAnon() ) { $forward .= ' anon'; } + + // Command line script uses a FauxRequest object which does not have + // any knowledge about an URL and throw an exception instead. + try { + $requestUrl = $wgRequest->getRequestURL(); + } catch ( MWException $e ) { + $requestUrl = 'n/a'; + } + $log = sprintf( "%s\t%04.3f\t%s\n", gmdate( 'YmdHis' ), $elapsed, - urldecode( $wgRequest->getRequestURL() . $forward ) ); + urldecode( $requestUrl . $forward ) ); wfErrorLog( $log . $profiler->getOutput(), $wgDebugLogFile ); } diff --git a/tests/phpunit/MediaWikiPHPUnitCommand.php b/tests/phpunit/MediaWikiPHPUnitCommand.php index fca325154a..473e6413b7 100644 --- a/tests/phpunit/MediaWikiPHPUnitCommand.php +++ b/tests/phpunit/MediaWikiPHPUnitCommand.php @@ -53,6 +53,22 @@ class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command { } } + public function run( array $argv, $exit = true ) { + $ret = parent::run( $argv, false ); + + // Return to real wiki db, so profiling data is preserved + MediaWikiTestCase::teardownTestDB(); + + // Log profiling data, e.g. in the database or UDP + wfLogProfilingData(); + + if ( $exit ) { + exit( $ret ); + } else { + return $ret; + } + } + public function showHelp() { parent::showHelp();