| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\SiteStats\SiteStats; |
| 4 |
use Wikimedia\ObjectCache\HashBagOStuff; |
| 5 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 6 |
use Wikimedia\Rdbms\Platform\ISQLPlatform; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class SiteStatsTest extends MediaWikiIntegrationTestCase { |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public function testJobsCountGetCached() { |
| 17 |
$cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ); |
| 18 |
$this->setService( 'MainWANObjectCache', $cache ); |
| 19 |
$jobq = $this->getServiceContainer()->getJobQueueGroup(); |
| 20 |
|
| 21 |
$jobq->push( new NullJob( [] ) ); |
| 22 |
$this->assertSame( 1, SiteStats::jobs(), |
| 23 |
'A single job enqueued bumps jobscount stat to 1' ); |
| 24 |
|
| 25 |
$jobq->push( new NullJob( [] ) ); |
| 26 |
$this->assertSame( 1, SiteStats::jobs(), |
| 27 |
'SiteStats::jobs() count does not reflect addition ' . |
| 28 |
'of a second job (cached)' |
| 29 |
); |
| 30 |
|
| 31 |
$jobq->get( 'null' )->delete(); |
| 32 |
$this->assertSame( 0, $jobq->get( 'null' )->getSize(), |
| 33 |
'Job queue for NullJob has been cleaned' ); |
| 34 |
|
| 35 |
$cache->delete( $cache->makeKey( 'SiteStats', 'jobscount' ) ); |
| 36 |
$this->assertSame( 1, SiteStats::jobs(), |
| 37 |
'jobs count is kept in process cache' ); |
| 38 |
|
| 39 |
$cache->clearProcessCache(); |
| 40 |
$this->assertSame( 0, SiteStats::jobs() ); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public function testInit() { |
| 47 |
$this->getDb()->newDeleteQueryBuilder() |
| 48 |
->deleteFrom( 'site_stats' ) |
| 49 |
->where( ISQLPlatform::ALL_ROWS ) |
| 50 |
->caller( __METHOD__ ) |
| 51 |
->execute(); |
| 52 |
SiteStats::unload(); |
| 53 |
|
| 54 |
SiteStats::edits(); |
| 55 |
$row = $this->getDb()->newSelectQueryBuilder() |
| 56 |
->select( '1' ) |
| 57 |
->from( 'site_stats' ) |
| 58 |
->caller( __METHOD__ )->fetchRow(); |
| 59 |
|
| 60 |
$this->assertNotFalse( $row ); |
| 61 |
} |
| 62 |
} |