SiteStatsTest::testJobsCountGetCached() is somewhat flaky in that if it runs after a test that adds a page (thereby producing htmlCacheUpdate and recentChangesUpdate jobs) but doesn't have the CI framework reset the `page` tables (which has the side effect of clearing all such jobs), it will fail. This change manually clears those jobs so it doesn't depend on test ordering. Change-Id: I1277e633c81b29bda7564fa12d23f13ded7298c7
41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
class SiteStatsTest extends MediaWikiTestCase {
|
|
|
|
/**
|
|
* @covers SiteStats::jobs
|
|
*/
|
|
function testJobsCountGetCached() {
|
|
$this->setService( 'MainWANObjectCache',
|
|
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ) );
|
|
$cache = \MediaWiki\MediaWikiServices::getInstance()->getMainWANObjectCache();
|
|
$jobq = JobQueueGroup::singleton();
|
|
|
|
// Delete EditPage jobs that might have been left behind by other tests
|
|
$jobq->get( 'htmlCacheUpdate' )->delete();
|
|
$jobq->get( 'recentChangesUpdate' )->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' );
|
|
|
|
$jobq->push( new NullJob( Title::newMainPage(), [] ) );
|
|
$this->assertEquals( 1, SiteStats::jobs(),
|
|
'SiteStats::jobs() count does not reflect addition ' .
|
|
'of a second job (cached)'
|
|
);
|
|
|
|
$jobq->get( 'null' )->delete(); // clear jobqueue
|
|
$this->assertEquals( 0, $jobq->get( 'null' )->getSize(),
|
|
'Job queue for NullJob has been cleaned' );
|
|
|
|
$cache->delete( $cache->makeKey( 'SiteStats', 'jobscount' ) );
|
|
$this->assertEquals( 1, SiteStats::jobs(),
|
|
'jobs count is kept in process cache' );
|
|
|
|
$cache->clearProcessCache();
|
|
$this->assertEquals( 0, SiteStats::jobs() );
|
|
}
|
|
|
|
}
|