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 $jobq->push( new NullJob( Title
::newMainPage(), [] ) );
15 $this->assertEquals( 1, SiteStats
::jobs(),
16 'A single job enqueued bumps jobscount stat to 1' );
18 $jobq->push( new NullJob( Title
::newMainPage(), [] ) );
19 $this->assertEquals( 1, SiteStats
::jobs(),
20 'SiteStats::jobs() count does not reflect addition ' .
21 'of a second job (cached)'
24 $jobq->get( 'null' )->delete(); // clear jobqueue
25 $this->assertEquals( 0, $jobq->get( 'null' )->getSize(),
26 'Job queue for NullJob has been cleaned' );
28 $cache->delete( $cache->makeKey( 'SiteStats', 'jobscount' ) );
29 $this->assertEquals( 1, SiteStats
::jobs(),
30 'jobs count is kept in process cache' );
32 $cache->clearProcessCache();
33 $this->assertEquals( 0, SiteStats
::jobs() );