Merge "Exclude redirects from Special:Fewestrevisions"
[lhc/web/wiklou.git] / tests / phpunit / includes / db / LBFactoryTest.php
index b79cdf3..424c64b 100644 (file)
@@ -30,7 +30,6 @@ use Wikimedia\Rdbms\LBFactorySimple;
 use Wikimedia\Rdbms\LBFactoryMulti;
 use Wikimedia\Rdbms\LoadBalancer;
 use Wikimedia\Rdbms\ChronologyProtector;
-use Wikimedia\Rdbms\DatabaseMysqli;
 use Wikimedia\Rdbms\MySQLMasterPos;
 use Wikimedia\Rdbms\DatabaseDomain;
 
@@ -47,7 +46,7 @@ class LBFactoryTest extends MediaWikiTestCase {
         * @dataProvider getLBFactoryClassProvider
         */
        public function testGetLBFactoryClass( $expected, $deprecated ) {
-               $mockDB = $this->getMockBuilder( DatabaseMysqli::class )
+               $mockDB = $this->getMockBuilder( IDatabase::class )
                        ->disableOriginalConstructor()
                        ->getMock();
 
@@ -291,7 +290,7 @@ class LBFactoryTest extends MediaWikiTestCase {
                $m2Pos = new MySQLMasterPos( 'db1064-bin.002400/794074907', $now );
 
                // Master DB 1
-               $mockDB1 = $this->getMockBuilder( DatabaseMysqli::class )
+               $mockDB1 = $this->getMockBuilder( IDatabase::class )
                        ->disableOriginalConstructor()
                        ->getMock();
                $mockDB1->method( 'writesOrCallbacksPending' )->willReturn( true );
@@ -303,6 +302,8 @@ class LBFactoryTest extends MediaWikiTestCase {
                        ->getMock();
                $lb1->method( 'getConnection' )->willReturn( $mockDB1 );
                $lb1->method( 'getServerCount' )->willReturn( 2 );
+               $lb1->method( 'hasReplicaServers' )->willReturn( true );
+               $lb1->method( 'hasStreamingReplicaServers' )->willReturn( true );
                $lb1->method( 'getAnyOpenConnection' )->willReturn( $mockDB1 );
                $lb1->method( 'hasOrMadeRecentMasterChanges' )->will( $this->returnCallback(
                                function () use ( $mockDB1 ) {
@@ -314,9 +315,10 @@ class LBFactoryTest extends MediaWikiTestCase {
                                }
                        ) );
                $lb1->method( 'getMasterPos' )->willReturn( $m1Pos );
+               $lb1->method( 'getReplicaResumePos' )->willReturn( $m1Pos );
                $lb1->method( 'getServerName' )->with( 0 )->willReturn( 'master1' );
                // Master DB 2
-               $mockDB2 = $this->getMockBuilder( DatabaseMysqli::class )
+               $mockDB2 = $this->getMockBuilder( IDatabase::class )
                        ->disableOriginalConstructor()
                        ->getMock();
                $mockDB2->method( 'writesOrCallbacksPending' )->willReturn( true );
@@ -328,6 +330,8 @@ class LBFactoryTest extends MediaWikiTestCase {
                        ->getMock();
                $lb2->method( 'getConnection' )->willReturn( $mockDB2 );
                $lb2->method( 'getServerCount' )->willReturn( 2 );
+               $lb2->method( 'hasReplicaServers' )->willReturn( true );
+               $lb2->method( 'hasStreamingReplicaServers' )->willReturn( true );
                $lb2->method( 'getAnyOpenConnection' )->willReturn( $mockDB2 );
                $lb2->method( 'hasOrMadeRecentMasterChanges' )->will( $this->returnCallback(
                        function () use ( $mockDB2 ) {
@@ -339,6 +343,7 @@ class LBFactoryTest extends MediaWikiTestCase {
                        }
                ) );
                $lb2->method( 'getMasterPos' )->willReturn( $m2Pos );
+               $lb2->method( 'getReplicaResumePos' )->willReturn( $m2Pos );
                $lb2->method( 'getServerName' )->with( 0 )->willReturn( 'master2' );
 
                $bag = new HashBagOStuff();
@@ -357,11 +362,11 @@ class LBFactoryTest extends MediaWikiTestCase {
                $mockDB2->expects( $this->exactly( 1 ) )->method( 'lastDoneWrites' );
 
                // Nothing to wait for on first HTTP request start
-               $cp->initLB( $lb1 );
-               $cp->initLB( $lb2 );
+               $cp->applySessionReplicationPosition( $lb1 );
+               $cp->applySessionReplicationPosition( $lb2 );
                // Record positions in stash on first HTTP request end
-               $cp->shutdownLB( $lb1 );
-               $cp->shutdownLB( $lb2 );
+               $cp->storeSessionReplicationPosition( $lb1 );
+               $cp->storeSessionReplicationPosition( $lb2 );
                $cpIndex = null;
                $cp->shutdown( null, 'sync', $cpIndex );
 
@@ -374,6 +379,8 @@ class LBFactoryTest extends MediaWikiTestCase {
                        ->disableOriginalConstructor()
                        ->getMock();
                $lb1->method( 'getServerCount' )->willReturn( 2 );
+               $lb1->method( 'hasReplicaServers' )->willReturn( true );
+               $lb1->method( 'hasStreamingReplicaServers' )->willReturn( true );
                $lb1->method( 'getServerName' )->with( 0 )->willReturn( 'master1' );
                $lb1->expects( $this->once() )
                        ->method( 'waitFor' )->with( $this->equalTo( $m1Pos ) );
@@ -382,6 +389,8 @@ class LBFactoryTest extends MediaWikiTestCase {
                        ->disableOriginalConstructor()
                        ->getMock();
                $lb2->method( 'getServerCount' )->willReturn( 2 );
+               $lb2->method( 'hasReplicaServers' )->willReturn( true );
+               $lb2->method( 'hasStreamingReplicaServers' )->willReturn( true );
                $lb2->method( 'getServerName' )->with( 0 )->willReturn( 'master2' );
                $lb2->expects( $this->once() )
                        ->method( 'waitFor' )->with( $this->equalTo( $m2Pos ) );
@@ -396,11 +405,11 @@ class LBFactoryTest extends MediaWikiTestCase {
                );
 
                // Wait for last positions to be reached on second HTTP request start
-               $cp->initLB( $lb1 );
-               $cp->initLB( $lb2 );
+               $cp->applySessionReplicationPosition( $lb1 );
+               $cp->applySessionReplicationPosition( $lb2 );
                // Shutdown (nothing to record)
-               $cp->shutdownLB( $lb1 );
-               $cp->shutdownLB( $lb2 );
+               $cp->storeSessionReplicationPosition( $lb1 );
+               $cp->storeSessionReplicationPosition( $lb2 );
                $cpIndex = null;
                $cp->shutdown( null, 'sync', $cpIndex );