2017-05-29 21:58:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-04-26 23:16:29 +00:00
|
|
|
use MediaWiki\SiteStats\SiteStats;
|
|
|
|
|
|
2023-02-04 21:37:40 +00:00
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class SiteStatsTest extends MediaWikiIntegrationTestCase {
|
2017-05-29 21:58:33 +00:00
|
|
|
|
|
|
|
|
/**
|
2023-05-27 09:43:12 +00:00
|
|
|
* @covers MediaWiki\SiteStats\SiteStats::jobs
|
2017-05-29 21:58:33 +00:00
|
|
|
*/
|
2019-10-09 18:24:07 +00:00
|
|
|
public function testJobsCountGetCached() {
|
2018-04-23 23:46:11 +00:00
|
|
|
$cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
|
|
|
|
|
$this->setService( 'MainWANObjectCache', $cache );
|
2022-01-27 20:19:18 +00:00
|
|
|
$jobq = $this->getServiceContainer()->getJobQueueGroup();
|
2017-05-29 21:58:33 +00:00
|
|
|
|
2023-01-20 09:51:14 +00:00
|
|
|
$jobq->push( new NullJob( [] ) );
|
2020-05-30 10:36:42 +00:00
|
|
|
$this->assertSame( 1, SiteStats::jobs(),
|
2021-09-03 22:52:31 +00:00
|
|
|
'A single job enqueued bumps jobscount stat to 1' );
|
2017-05-29 21:58:33 +00:00
|
|
|
|
2023-01-20 09:51:14 +00:00
|
|
|
$jobq->push( new NullJob( [] ) );
|
2020-05-30 10:36:42 +00:00
|
|
|
$this->assertSame( 1, SiteStats::jobs(),
|
2017-05-29 21:58:33 +00:00
|
|
|
'SiteStats::jobs() count does not reflect addition ' .
|
|
|
|
|
'of a second job (cached)'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$jobq->get( 'null' )->delete(); // clear jobqueue
|
2019-09-17 14:31:49 +00:00
|
|
|
$this->assertSame( 0, $jobq->get( 'null' )->getSize(),
|
2017-05-29 21:58:33 +00:00
|
|
|
'Job queue for NullJob has been cleaned' );
|
|
|
|
|
|
|
|
|
|
$cache->delete( $cache->makeKey( 'SiteStats', 'jobscount' ) );
|
2020-05-30 10:36:42 +00:00
|
|
|
$this->assertSame( 1, SiteStats::jobs(),
|
2017-05-29 21:58:33 +00:00
|
|
|
'jobs count is kept in process cache' );
|
|
|
|
|
|
|
|
|
|
$cache->clearProcessCache();
|
2019-09-17 14:31:49 +00:00
|
|
|
$this->assertSame( 0, SiteStats::jobs() );
|
2017-05-29 21:58:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-04 21:37:40 +00:00
|
|
|
/**
|
2023-05-27 09:43:12 +00:00
|
|
|
* @covers MediaWiki\SiteStats\SiteStats
|
2023-02-04 21:37:40 +00:00
|
|
|
*/
|
|
|
|
|
public function testInit() {
|
|
|
|
|
$this->db->delete( 'site_stats', IDatabase::ALL_ROWS, __METHOD__ );
|
|
|
|
|
SiteStats::unload();
|
|
|
|
|
|
|
|
|
|
SiteStats::edits();
|
|
|
|
|
$this->assertNotFalse( $this->db->selectRow( 'site_stats', '1', IDatabase::ALL_ROWS, __METHOD__ ) );
|
|
|
|
|
}
|
2017-05-29 21:58:33 +00:00
|
|
|
}
|