summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/SiteStatsTest.php
blob: 56bde5da08623343576a90a874b8a80fabab45bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?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 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' );

		$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() );
	}

}