Merge "Log profiling data when tests have finished."
authorHashar <hashar@free.fr>
Mon, 19 Nov 2012 13:12:16 +0000 (13:12 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 19 Nov 2012 13:12:16 +0000 (13:12 +0000)
includes/GlobalFunctions.php
tests/phpunit/MediaWikiPHPUnitCommand.php

index 7dc9a70..982e965 100644 (file)
@@ -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 );
 }
index fca3251..473e641 100644 (file)
@@ -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();