3 class SiteStatsTest extends MediaWikiTestCase {
6 * @covers SiteStats::jobs
8 function testJobsCountGetCached() {
9 $this->setService( 'MainWANObjectCache',
10 new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ) );
11 $cache = \MediaWiki\MediaWikiServices::getInstance()->getMainWANObjectCache();
12 $jobq = JobQueueGroup::singleton();
14 // Delete EditPage jobs that might have been left behind by other tests
15 $jobq->get( 'htmlCacheUpdate' )->delete();
16 $jobq->get( 'recentChangesUpdate' )->delete();
17 $cache->delete( $cache->makeKey( 'SiteStats', 'jobscount' ) );
19 $jobq->push( new NullJob( Title::newMainPage(), [] ) );
20 $this->assertEquals( 1, SiteStats::jobs(),
21 'A single job enqueued bumps jobscount stat to 1' );
23 $jobq->push( new NullJob( Title::newMainPage(), [] ) );
24 $this->assertEquals( 1, SiteStats::jobs(),
25 'SiteStats::jobs() count does not reflect addition ' .
26 'of a second job (cached)'
29 $jobq->get( 'null' )->delete(); // clear jobqueue
30 $this->assertEquals( 0, $jobq->get( 'null' )->getSize(),
31 'Job queue for NullJob has been cleaned' );
33 $cache->delete( $cache->makeKey( 'SiteStats', 'jobscount' ) );
34 $this->assertEquals( 1, SiteStats::jobs(),
35 'jobs count is kept in process cache' );
37 $cache->clearProcessCache();
38 $this->assertEquals( 0, SiteStats::jobs() );