Debian Codegraph @

tests/phpunit/maintenance/DatabaseLagTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Maintenance;
4
5 use Wikimedia\Rdbms\ILoadBalancer;
6
7 /**
8 * @covers \DatabaseLag
9 * @group Maintenance
10 */
11 class DatabaseLagTest extends MaintenanceBaseTestCase {
12
13 public function getMaintenanceClass() {
14 return \DatabaseLag::class;
15 }
16
17 public static function provideLagTimes() {
18 return [
19 'No lag' => [ 0, 'db-nolag-01', '/^db-nolag-01\s+0$/m' ],
20 'Some lag' => [ 42, 'db-somelag-02', '/^db-somelag-02\s+42$/m' ],
21 'Not replicating' => [
22 false, 'db-not-replicating-03',
23 '/db-not-replicating-03\s+replication stopped or errored$/m'
24 ],
25 ];
26 }
27
28 /**
29 * @dataProvider provideLagTimes
30 */
31 public function testReportedOutput( $lag, $servername, $expected ) {
32 $lb = $this->createMock( ILoadBalancer::class );
33 $lb->method( 'getLagTimes' )->willReturn( [ $lag ] );
34 $lb->method( 'getServerName' )->willReturn( $servername );
35
36 $this->setService( 'DBLoadBalancer', $lb );
37
38 $this->maintenance->setOption( '-r', false );
39 $this->maintenance->execute();
40
41 $this->maintenance->setOption( '-r', true );
42 $this->maintenance->stopReporting = true;
43 $this->maintenance->execute();
44
45 $this->expectOutputRegex( $expected );
46 }
47
48 }