* @see resetGlobalServices()
*/
private function doLightweightServiceReset() {
- global $wgRequest;
+ global $wgRequest, $wgJobClasses;
+ foreach ( $wgJobClasses as $type => $class ) {
+ JobQueueGroup::singleton()->get( $type )->delete();
+ }
JobQueueGroup::destroySingletons();
+
ObjectCache::clear();
$services = MediaWikiServices::getInstance();
$services->resetServiceForTesting( 'MainObjectStash' );
$services->resetServiceForTesting( 'LocalServerObjectCache' );
$services->getMainWANObjectCache()->clearProcessCache();
FileBackendGroup::destroySingleton();
+ DeferredUpdates::clearPendingUpdates();
// TODO: move global state into MediaWikiServices
RequestContext::resetMain();
}
public function run( PHPUnit_Framework_TestResult $result = null ) {
- // Reset all caches between tests.
- $this->doLightweightServiceReset();
-
$needsResetDB = false;
if ( !self::$dbSetup || $this->needsDB() ) {
}
}
- DeferredUpdates::clearPendingUpdates();
- ObjectCache::getMainWANInstance()->clearProcessCache();
+ // Reset all caches between tests.
+ $this->doLightweightServiceReset();
// XXX: reset maintenance triggers
// Hook into period lag checks which often happen in long-running scripts
* setupTestDB() was called. Useful if we need to perform database operations
* after the test run has finished (such as saving logs or profiling info).
*
+ * This is called by phpunit/bootstrap.php after the last test.
+ *
* @since 1.21
*/
public static function teardownTestDB() {
* @covers SiteStats::jobs
*/
function testJobsCountGetCached() {
- $this->setService( 'MainWANObjectCache',
- new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ) );
- $cache = \MediaWiki\MediaWikiServices::getInstance()->getMainWANObjectCache();
+ $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
+ $this->setService( 'MainWANObjectCache', $cache );
$jobq = JobQueueGroup::singleton();
- // Delete jobs that might have been left behind by other tests
- $jobq->get( 'htmlCacheUpdate' )->delete();
- $jobq->get( 'recentChangesUpdate' )->delete();
- $jobq->get( 'userGroupExpiry' )->delete();
- $cache->delete( $cache->makeKey( 'SiteStats', 'jobscount' ) );
-
$jobq->push( new NullJob( Title::newMainPage(), [] ) );
$this->assertEquals( 1, SiteStats::jobs(),
'A single job enqueued bumps jobscount stat to 1' );