Revert "Make wfGetDB() return a MaintainableDBConnRef instance"
authorKrinkle <krinklemail@gmail.com>
Wed, 24 Jul 2019 18:07:18 +0000 (18:07 +0000)
committerKrinkle <krinklemail@gmail.com>
Wed, 24 Jul 2019 18:07:18 +0000 (18:07 +0000)
This reverts commit 335066505a3ea6121f3c5b5eae43b0c37ca6e2eb.

The standalone parser test runner, as used by Parsoid Jenkins builds,
is (indirectly) using wfGetDB in a way that isn't supported (changing
the selected database). This needs to be fixed, but we can give it
a few days.

Change-Id: I07ff422dd56d5700e570100747aa49b7764ec80f

includes/GlobalFunctions.php
tests/phpunit/includes/Revision/RevisionStoreTest.php

index 1741958..7b4b502 100644 (file)
@@ -2563,10 +2563,10 @@ function wfWikiID() {
  * @todo Replace calls to wfGetDB with calls to LoadBalancer::getConnection()
  *       on an injected instance of LoadBalancer.
  *
- * @return \Wikimedia\Rdbms\DBConnRef
+ * @return \Wikimedia\Rdbms\Database
  */
 function wfGetDB( $db, $groups = [], $wiki = false ) {
-       return wfGetLB( $wiki )->getMaintenanceConnectionRef( $db, $groups, $wiki );
+       return wfGetLB( $wiki )->getConnection( $db, $groups, $wiki );
 }
 
 /**
index 83872e3..0648bfc 100644 (file)
@@ -12,8 +12,6 @@ use MediaWiki\Revision\RevisionStore;
 use MediaWiki\Revision\SlotRoleRegistry;
 use MediaWiki\Revision\SlotRecord;
 use MediaWiki\Storage\SqlBlobStore;
-use Wikimedia\Rdbms\ILoadBalancer;
-use Wikimedia\Rdbms\MaintainableDBConnRef;
 use MediaWikiTestCase;
 use MWException;
 use Title;
@@ -79,17 +77,6 @@ class RevisionStoreTest extends MediaWikiTestCase {
                        ->disableOriginalConstructor()->getMock();
        }
 
-       /**
-        * @param ILoadBalancer $mockLoadBalancer
-        * @param Database $db
-        * @return callable
-        */
-       private function getMockDBConnRefCallback( ILoadBalancer $mockLoadBalancer, IDatabase $db ) {
-               return function ( $i, $g, $domain, $flg ) use ( $mockLoadBalancer, $db ) {
-                       return new MaintainableDBConnRef( $mockLoadBalancer, $db, $i );
-               };
-       }
-
        /**
         * @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
         */
@@ -171,14 +158,10 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $this->setService( 'DBLoadBalancer', $mockLoadBalancer );
 
                $db = $this->getMockDatabase();
-               // RevisionStore uses getConnectionRef
-               $mockLoadBalancer->expects( $this->any() )
-                       ->method( 'getConnectionRef' )
-                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
-               // Title calls wfGetDB() which uses getMaintenanceConnectionRef
+               // Title calls wfGetDB() which uses a regular Connection
                $mockLoadBalancer->expects( $this->atLeastOnce() )
-                       ->method( 'getMaintenanceConnectionRef' )
-                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
+                       ->method( 'getConnection' )
+                       ->willReturn( $db );
 
                // First call to Title::newFromID, faking no result (db lag?)
                $db->expects( $this->at( 0 ) )
@@ -209,15 +192,15 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $this->setService( 'DBLoadBalancer', $mockLoadBalancer );
 
                $db = $this->getMockDatabase();
-               // Title calls wfGetDB() which uses getMaintenanceConnectionRef
+               // Title calls wfGetDB() which uses a regular Connection
                // Assert that the first call uses a REPLICA and the second falls back to master
+               $mockLoadBalancer->expects( $this->exactly( 2 ) )
+                       ->method( 'getConnection' )
+                       ->willReturn( $db );
+               // RevisionStore getTitle uses a ConnectionRef
                $mockLoadBalancer->expects( $this->atLeastOnce() )
                        ->method( 'getConnectionRef' )
-                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
-               // Title calls wfGetDB() which uses getMaintenanceConnectionRef
-               $mockLoadBalancer->expects( $this->exactly( 2 ) )
-                       ->method( 'getMaintenanceConnectionRef' )
-                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
+                       ->willReturn( $db );
 
                // First call to Title::newFromID, faking no result (db lag?)
                $db->expects( $this->at( 0 ) )
@@ -268,14 +251,14 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $this->setService( 'DBLoadBalancer', $mockLoadBalancer );
 
                $db = $this->getMockDatabase();
+               // Title calls wfGetDB() which uses a regular Connection
                $mockLoadBalancer->expects( $this->atLeastOnce() )
-                       ->method( 'getConnectionRef' )
-                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
-               // Title calls wfGetDB() which uses getMaintenanceConnectionRef
-               // RevisionStore getTitle uses getMaintenanceConnectionRef
+                       ->method( 'getConnection' )
+                       ->willReturn( $db );
+               // RevisionStore getTitle uses a ConnectionRef
                $mockLoadBalancer->expects( $this->atLeastOnce() )
-                       ->method( 'getMaintenanceConnectionRef' )
-                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
+                       ->method( 'getConnectionRef' )
+                       ->willReturn( $db );
 
                // First call to Title::newFromID, faking no result (db lag?)
                $db->expects( $this->at( 0 ) )
@@ -316,15 +299,15 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $this->setService( 'DBLoadBalancer', $mockLoadBalancer );
 
                $db = $this->getMockDatabase();
+               // Title calls wfGetDB() which uses a regular Connection
                // Assert that the first call uses a REPLICA and the second falls back to master
-               // RevisionStore uses getMaintenanceConnectionRef
+               $mockLoadBalancer->expects( $this->exactly( 2 ) )
+                       ->method( 'getConnection' )
+                       ->willReturn( $db );
+               // RevisionStore getTitle uses a ConnectionRef
                $mockLoadBalancer->expects( $this->atLeastOnce() )
                        ->method( 'getConnectionRef' )
-                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
-               // Title calls wfGetDB() which uses getMaintenanceConnectionRef
-               $mockLoadBalancer->expects( $this->exactly( 2 ) )
-                       ->method( 'getMaintenanceConnectionRef' )
-                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
+                       ->willReturn( $db );
 
                // First call to Title::newFromID, faking no result (db lag?)
                $db->expects( $this->at( 0 ) )
@@ -385,14 +368,12 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $this->setService( 'DBLoadBalancer', $mockLoadBalancer );
 
                $db = $this->getMockDatabase();
-               // Title calls wfGetDB() which uses getMaintenanceConnectionRef
+               // Title calls wfGetDB() which uses a regular Connection
                // Assert that the first call uses a REPLICA and the second falls back to master
 
                // RevisionStore getTitle uses getConnectionRef
-               // Title::newFromID uses getMaintenanceConnectionRef
-               foreach ( [
-                       'getConnectionRef', 'getMaintenanceConnectionRef'
-               ] as $method ) {
+               // Title::newFromID uses getConnection
+               foreach ( [ 'getConnection', 'getConnectionRef' ] as $method ) {
                        $mockLoadBalancer->expects( $this->exactly( 2 ) )
                                ->method( $method )
                                ->willReturnCallback( function ( $masterOrReplica ) use ( $db ) {