3 namespace MediaWiki\Tests\Maintenance
;
5 use Wikimedia\Rdbms\ILoadBalancer
;
11 class DatabaseLagTest
extends MaintenanceBaseTestCase
{
13 public function getMaintenanceClass() {
14 return \DatabaseLag
::class;
17 public static function provideLagTimes() {
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'
29 * @dataProvider provideLagTimes
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 );
36 $this->setService( 'DBLoadBalancer', $lb );
38 $this->maintenance
->setOption( '-r', false );
39 $this->maintenance
->execute();
41 $this->maintenance
->setOption( '-r', true );
42 $this->maintenance
->stopReporting
= true;
43 $this->maintenance
->execute();
45 $this->expectOutputRegex( $expected );