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
* @todo Replace calls to wfGetDB with calls to LoadBalancer::getConnection()
* on an injected instance of LoadBalancer.
*
* @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 ) {
*/
function wfGetDB( $db, $groups = [], $wiki = false ) {
- return wfGetLB( $wiki )->getMaintenanceConnectionRef( $db, $groups, $wiki );
+ return wfGetLB( $wiki )->getConnection( $db, $groups, $wiki );
use MediaWiki\Revision\SlotRoleRegistry;
use MediaWiki\Revision\SlotRecord;
use MediaWiki\Storage\SqlBlobStore;
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;
use MediaWikiTestCase;
use MWException;
use Title;
->disableOriginalConstructor()->getMock();
}
->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
*/
/**
* @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
*/
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
$db = $this->getMockDatabase();
$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() )
$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 ) )
// First call to Title::newFromID, faking no result (db lag?)
$db->expects( $this->at( 0 ) )
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
$db = $this->getMockDatabase();
$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
// 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' )
$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 ) );
// First call to Title::newFromID, faking no result (db lag?)
$db->expects( $this->at( 0 ) )
// First call to Title::newFromID, faking no result (db lag?)
$db->expects( $this->at( 0 ) )
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
$db = $this->getMockDatabase();
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
$db = $this->getMockDatabase();
+ // Title calls wfGetDB() which uses a regular Connection
$mockLoadBalancer->expects( $this->atLeastOnce() )
$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() )
$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 ) )
// First call to Title::newFromID, faking no result (db lag?)
$db->expects( $this->at( 0 ) )
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
$db = $this->getMockDatabase();
$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
// 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' )
$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 ) );
// First call to Title::newFromID, faking no result (db lag?)
$db->expects( $this->at( 0 ) )
// First call to Title::newFromID, faking no result (db lag?)
$db->expects( $this->at( 0 ) )
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
$db = $this->getMockDatabase();
$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
// 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 ) {
$mockLoadBalancer->expects( $this->exactly( 2 ) )
->method( $method )
->willReturnCallback( function ( $masterOrReplica ) use ( $db ) {