X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fdb%2FLoadBalancerTest.php;h=54aa2acbdfee06568320512bba7149d7a06b6814;hb=cf3bdd40a3fd22045703c1e188115fc87386fa65;hp=a7b097541a54727411f0190b2165d7f8ac44fc83;hpb=e213462f7c61cf9547c07d919c401dddebe3577e;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/db/LoadBalancerTest.php b/tests/phpunit/includes/db/LoadBalancerTest.php index a7b097541a..54aa2acbdf 100644 --- a/tests/phpunit/includes/db/LoadBalancerTest.php +++ b/tests/phpunit/includes/db/LoadBalancerTest.php @@ -1,8 +1,9 @@ $wgDBserver, 'dbname' => $wgDBname, + 'tablePrefix' => $this->dbPrefix(), 'user' => $wgDBuser, 'password' => $wgDBpassword, 'type' => $wgDBtype, @@ -44,9 +48,13 @@ class LoadBalancerTest extends MediaWikiTestCase { $lb = new LoadBalancer( [ 'servers' => $servers, - 'localDomain' => wfWikiID() + 'localDomain' => new DatabaseDomain( $wgDBname, null, $this->dbPrefix() ) ] ); + $ld = DatabaseDomain::newFromId( $lb->getLocalDomainID() ); + $this->assertEquals( $wgDBname, $ld->getDatabase(), 'local domain DB set' ); + $this->assertEquals( $this->dbPrefix(), $ld->getTablePrefix(), 'local domain prefix set' ); + $dbw = $lb->getConnection( DB_MASTER ); $this->assertTrue( $dbw->getLBInfo( 'master' ), 'master shows as master' ); $this->assertTrue( $dbw->getFlag( $dbw::DBO_TRX ), "DBO_TRX set on master" ); @@ -79,6 +87,7 @@ class LoadBalancerTest extends MediaWikiTestCase { [ // master 'host' => $wgDBserver, 'dbname' => $wgDBname, + 'tablePrefix' => $this->dbPrefix(), 'user' => $wgDBuser, 'password' => $wgDBpassword, 'type' => $wgDBtype, @@ -89,6 +98,7 @@ class LoadBalancerTest extends MediaWikiTestCase { [ // emulated replica 'host' => $wgDBserver, 'dbname' => $wgDBname, + 'tablePrefix' => $this->dbPrefix(), 'user' => $wgDBuser, 'password' => $wgDBpassword, 'type' => $wgDBtype, @@ -100,7 +110,7 @@ class LoadBalancerTest extends MediaWikiTestCase { $lb = new LoadBalancer( [ 'servers' => $servers, - 'localDomain' => wfWikiID(), + 'localDomain' => new DatabaseDomain( $wgDBname, null, $this->dbPrefix() ), 'loadMonitorClass' => 'LoadMonitorNull' ] ); @@ -138,15 +148,15 @@ class LoadBalancerTest extends MediaWikiTestCase { $lb->closeAll(); } - private function assertWriteForbidden( IDatabase $db ) { + private function assertWriteForbidden( Database $db ) { try { - $db->delete( 'user', [ 'user_id' => 57634126 ], 'TEST' ); + $db->delete( 'some_table', [ 'id' => 57634126 ], __METHOD__ ); $this->fail( 'Write operation should have failed!' ); } catch ( DBError $ex ) { // check that the exception message contains "Write operation" - $constriant = new PHPUnit_Framework_Constraint_StringContains( 'Write operation' ); + $constraint = new PHPUnit_Framework_Constraint_StringContains( 'Write operation' ); - if ( !$constriant->evaluate( $ex->getMessage(), '', true ) ) { + if ( !$constraint->evaluate( $ex->getMessage(), '', true ) ) { // re-throw original error, to preserve stack trace throw $ex; } @@ -155,9 +165,26 @@ class LoadBalancerTest extends MediaWikiTestCase { } } - private function assertWriteAllowed( IDatabase $db ) { + private function assertWriteAllowed( Database $db ) { + $table = $db->tableName( 'some_table' ); try { - $this->assertNotSame( false, $db->delete( 'user', [ 'user_id' => 57634126 ] ) ); + $db->dropTable( 'some_table' ); // clear for sanity + // Use only basic SQL and trivial types for these queries for compatibility + $this->assertNotSame( + false, + $db->query( "CREATE TABLE $table (id INT, time INT)", __METHOD__ ), + "table created" + ); + $this->assertNotSame( + false, + $db->query( "DELETE FROM $table WHERE id=57634126", __METHOD__ ), + "delete query" + ); + $this->assertNotSame( + false, + $db->query( "DROP TABLE $table", __METHOD__ ), + "table dropped" + ); } finally { $db->rollback( __METHOD__, 'flush' ); }