From: Krinkle Date: Wed, 24 Jul 2019 18:07:18 +0000 (+0000) Subject: Revert "Make wfGetDB() return a MaintainableDBConnRef instance" X-Git-Tag: 1.34.0-rc.0~892^2 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=02b14d31425ce694c9baf5e27456eb1635194f1a;p=lhc%2Fweb%2Fwiklou.git Revert "Make wfGetDB() return a MaintainableDBConnRef instance" 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 --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 1741958681..7b4b502905 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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 ); } /** diff --git a/tests/phpunit/includes/Revision/RevisionStoreTest.php b/tests/phpunit/includes/Revision/RevisionStoreTest.php index 83872e3a37..0648bfce6e 100644 --- a/tests/phpunit/includes/Revision/RevisionStoreTest.php +++ b/tests/phpunit/includes/Revision/RevisionStoreTest.php @@ -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 ) {