Merge "Exclude redirects from Special:Fewestrevisions"
[lhc/web/wiklou.git] / tests / phpunit / includes / db / LoadBalancerTest.php
index 8510109..bf5326a 100644 (file)
@@ -636,6 +636,31 @@ class LoadBalancerTest extends MediaWikiTestCase {
                $rConn->insert( 'test', [ 't' => 1 ], __METHOD__ );
        }
 
+       /**
+        * @covers \Wikimedia\Rdbms\LoadBalancer::getConnection()
+        */
+       public function testGetConnectionRefDefaultGroup() {
+               $lb = $this->newMultiServerLocalLoadBalancer( [ 'defaultGroup' => 'vslow' ] );
+               $lbWrapper = TestingAccessWrapper::newFromObject( $lb );
+
+               $rVslow = $lb->getConnectionRef( DB_REPLICA );
+               $vslowIndexPicked = $rVslow->getLBInfo( 'serverIndex' );
+
+               $this->assertSame( $vslowIndexPicked, $lbWrapper->getExistingReaderIndex( 'vslow' ) );
+       }
+
+       /**
+        * @covers \Wikimedia\Rdbms\LoadBalancer::getConnection()
+        */
+       public function testGetConnectionRefUnknownDefaultGroup() {
+               $lb = $this->newMultiServerLocalLoadBalancer( [ 'defaultGroup' => 'invalid' ] );
+
+               $this->assertInstanceOf(
+                       IDatabase::class,
+                       $lb->getConnectionRef( DB_REPLICA )
+               );
+       }
+
        /**
         * @covers \Wikimedia\Rdbms\LoadBalancer::getConnection()
         * @covers \Wikimedia\Rdbms\LoadBalancer::getMaintenanceConnectionRef()
@@ -648,7 +673,10 @@ class LoadBalancerTest extends MediaWikiTestCase {
                $rGeneric = $lb->getConnectionRef( DB_REPLICA );
                $mainIndexPicked = $rGeneric->getLBInfo( 'serverIndex' );
 
-               $this->assertEquals( $mainIndexPicked, $lbWrapper->getExistingReaderIndex( false ) );
+               $this->assertEquals(
+                       $mainIndexPicked,
+                       $lbWrapper->getExistingReaderIndex( $lb::GROUP_GENERIC )
+               );
                $this->assertTrue( in_array( $mainIndexPicked, [ 1, 2 ] ) );
                for ( $i = 0; $i < 300; ++$i ) {
                        $rLog = $lb->getConnectionRef( DB_REPLICA, [] );