global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBtype, $wgSQLiteDataDir;
$factory = new LBFactoryMulti( [
- 'sectionsByDB' => [],
+ 'sectionsByDB' => [
+ 's1wiki' => 's1',
+ ],
'sectionLoads' => [
+ 's1' => [
+ 'test-db3' => 0,
+ 'test-db4' => 100,
+ ],
'DEFAULT' => [
'test-db1' => 0,
'test-db2' => 100,
- ],
+ ]
],
'serverTemplate' => [
'dbname' => $wgDBname,
],
'hostsByName' => [
'test-db1' => $wgDBserver,
- 'test-db2' => $wgDBserver
+ 'test-db2' => $wgDBserver,
+ 'test-db3' => $wgDBserver,
+ 'test-db4' => $wgDBserver
],
'loadMonitorClass' => LoadMonitorNull::class
] );
$dbr = $lb->getConnection( DB_REPLICA );
$this->assertTrue( $dbr->getLBInfo( 'replica' ), 'slave shows as slave' );
+ // Test that LoadBalancer instances made during commitMasterChanges() do not throw
+ // DBTransactionError due to transaction ROUND_* stages being mismatched.
+ $factory->beginMasterChanges( __METHOD__ );
+ $dbw->onTransactionPreCommitOrIdle( function () use ( $factory ) {
+ // Trigger s1 LoadBalancer instantiation during "finalize" stage.
+ // There is no s1wiki DB to select so it is not in getConnection(),
+ // but this fools getMainLB() at least.
+ $factory->getMainLB( 's1wiki' )->getConnection( DB_MASTER );
+ } );
+ $factory->commitMasterChanges( __METHOD__ );
+
+ $count = 0;
+ $factory->forEachLB( function () use ( &$count ) {
+ ++$count;
+ } );
+ $this->assertEquals( 2, $count );
+
$factory->shutdown();
- $lb->closeAll();
+ $factory->closeAll();
}
/**