// See https://bugs.php.net/bug.php?id=36514
ob_start();
+ $this->measureResponseTime( RequestContext::getMain()->getTiming() );
+
// Find out which modules are missing and instantiate the others
$modules = [];
$missing = [];
echo $response;
}
+ protected function measureResponseTime( Timing $timing ) {
+ DeferredUpdates::addCallableUpdate( function () use ( $timing ) {
+ $measure = $timing->measure( 'responseTime', 'requestStart', 'requestShutdown' );
+ if ( $measure !== false ) {
+ $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
+ $stats->timing( 'resourceloader.responseTime', $measure['duration'] * 1000 );
+ }
+ } );
+ }
+
/**
* Send main response headers to the client.
*
'Extra headers'
);
}
+
+ /**
+ * @covers ResourceLoader::respond
+ */
+ public function testRespond() {
+ $rl = $this->getMockBuilder( EmptyResourceLoader::class )
+ ->setMethods( [
+ 'tryRespondNotModified',
+ 'sendResponseHeaders',
+ 'measureResponseTime',
+ ] )
+ ->getMock();
+ $context = $this->getResourceLoaderContext( [ 'modules' => '' ], $rl );
+
+ $rl->expects( $this->once() )->method( 'measureResponseTime' );
+ $this->expectOutputRegex( '/no modules were requested/' );
+
+ $rl->respond( $context );
+ }
+
+ /**
+ * @covers ResourceLoader::measureResponseTime
+ */
+ public function testMeasureResponseTime() {
+ $stats = $this->getMockBuilder( NullStatsdDataFactory::class )
+ ->setMethods( [ 'timing' ] )->getMock();
+ $this->setService( 'StatsdDataFactory', $stats );
+
+ $stats->expects( $this->once() )->method( 'timing' )
+ ->with( 'resourceloader.responseTime', $this->anything() );
+
+ $timing = new Timing();
+ $timing->mark( 'requestShutdown' );
+ $rl = TestingAccessWrapper::newFromObject( new EmptyResourceLoader );
+ $rl->measureResponseTime( $timing );
+ DeferredUpdates::doUpdates();
+ }
}