X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fdb%2FLBFactoryTest.php;h=58f96546cd9d2f7cb284ceef532e7bce43b5f8ff;hb=d2e1734390fb19fb0f76c2de995811dabf2ac1dd;hp=1616139a0fdd7af062717e57020dad86dab0bc56;hpb=fbc4c39708641f94cbf3a20a4283fc9f448c8175;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/db/LBFactoryTest.php b/tests/phpunit/includes/db/LBFactoryTest.php index 1616139a0f..58f96546cd 100644 --- a/tests/phpunit/includes/db/LBFactoryTest.php +++ b/tests/phpunit/includes/db/LBFactoryTest.php @@ -126,7 +126,7 @@ class LBFactoryTest extends MediaWikiTestCase { 'load' => 0, 'flags' => DBO_TRX // REPEATABLE-READ for consistency ], - [ // emulated slave + [ // emulated replica 'host' => $wgDBserver, 'dbname' => $wgDBname, 'user' => $wgDBuser, @@ -152,7 +152,7 @@ class LBFactoryTest extends MediaWikiTestCase { 'cluster master set' ); $dbr = $lb->getConnection( DB_REPLICA ); - $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'slave shows as slave' ); + $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'replica shows as replica' ); $this->assertEquals( ( $wgDBserver != '' ) ? $wgDBserver : 'localhost', $dbr->getLBInfo( 'clusterMasterHost' ), @@ -169,7 +169,7 @@ class LBFactoryTest extends MediaWikiTestCase { $this->assertTrue( $dbw->getLBInfo( 'master' ), 'master shows as master' ); $dbr = $factory->getMainLB()->getConnection( DB_REPLICA ); - $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'slave shows as slave' ); + $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'replica shows as replica' ); // Destructor should trigger without round stage errors unset( $factory ); @@ -493,7 +493,7 @@ class LBFactoryTest extends MediaWikiTestCase { $lb->reuseConnection( $db ); // don't care $db = $lb->getConnection( DB_MASTER ); // local domain connection - $factory->setDomainPrefix( 'my_' ); + $factory->setLocalDomainPrefix( 'my_' ); $this->assertEquals( $wgDBname, $db->getDBname() ); $this->assertEquals( @@ -556,7 +556,7 @@ class LBFactoryTest extends MediaWikiTestCase { $lb->reuseConnection( $db ); // don't care - $factory->setDomainPrefix( 'my_' ); + $factory->setLocalDomainPrefix( 'my_' ); $db = $lb->getConnection( DB_MASTER, [], "$wgDBname-my_" ); $this->assertEquals( @@ -608,11 +608,63 @@ class LBFactoryTest extends MediaWikiTestCase { $this->assertFalse( $db->isOpen() ); } else { \Wikimedia\suppressWarnings(); - $this->assertFalse( $db->selectDB( 'garbage-db' ) ); + try { + $this->assertFalse( $db->selectDB( 'garbage-db' ) ); + $this->fail( "No error thrown." ); + } catch ( \Wikimedia\Rdbms\DBExpectedError $e ) { + $this->assertEquals( + "Could not select database 'garbage-db'.", + $e->getMessage() + ); + } \Wikimedia\restoreWarnings(); } } + public function testRedefineLocalDomain() { + global $wgDBname; + + if ( wfGetDB( DB_MASTER )->databasesAreIndependent() ) { + self::markTestSkipped( "Skipping tests about selecting DBs: not applicable" ); + return; + } + + $factory = $this->newLBFactoryMulti( + [], + [] + ); + $lb = $factory->getMainLB(); + + $conn1 = $lb->getConnectionRef( DB_MASTER ); + $this->assertEquals( + wfWikiID(), + $conn1->getDomainID() + ); + unset( $conn1 ); + + $factory->redefineLocalDomain( 'somedb-prefix' ); + $this->assertEquals( 'somedb-prefix', $factory->getLocalDomainID() ); + + $domain = new DatabaseDomain( $wgDBname, null, 'pref' ); + $factory->redefineLocalDomain( $domain ); + + $n = 0; + $lb->forEachOpenConnection( function () use ( &$n ) { + ++$n; + } ); + $this->assertEquals( 0, $n, "Connections closed" ); + + $conn2 = $lb->getConnectionRef( DB_MASTER ); + $this->assertEquals( + $domain->getId(), + $conn2->getDomainID() + ); + unset( $conn2 ); + + $factory->closeAll(); + $factory->destroy(); + } + private function quoteTable( Database $db, $table ) { if ( $db->getType() === 'sqlite' ) { return $table;