+
+ /**
+ * @covers LoadBalancer::openConnection()
+ * @covers LoadBalancer::getAnyOpenConnection()
+ */
+ function testOpenConnection() {
+ global $wgDBname;
+
+ $lb = new LoadBalancer( [
+ 'servers' => [ $this->makeServerConfig() ],
+ 'localDomain' => new DatabaseDomain( $wgDBname, null, $this->dbPrefix() )
+ ] );
+
+ $i = $lb->getWriterIndex();
+ $this->assertEquals( null, $lb->getAnyOpenConnection( $i ) );
+ $conn1 = $lb->getConnection( $i );
+ $this->assertNotEquals( null, $conn1 );
+ $this->assertEquals( $conn1, $lb->getAnyOpenConnection( $i ) );
+ $conn2 = $lb->getConnection( $i, [], false, $lb::CONN_TRX_AUTOCOMMIT );
+ $this->assertNotEquals( null, $conn2 );
+ if ( $lb->getServerAttributes( $i )[Database::ATTR_DB_LEVEL_LOCKING] ) {
+ $this->assertEquals( null,
+ $lb->getAnyOpenConnection( $i, $lb::CONN_TRX_AUTOCOMMIT ) );
+ $this->assertEquals( $conn1,
+ $lb->getConnection(
+ $i, [], false, $lb::CONN_TRX_AUTOCOMMIT ), $lb::CONN_TRX_AUTOCOMMIT );
+ } else {
+ $this->assertEquals( $conn2,
+ $lb->getAnyOpenConnection( $i, $lb::CONN_TRX_AUTOCOMMIT ) );
+ $this->assertEquals( $conn2,
+ $lb->getConnection( $i, [], false, $lb::CONN_TRX_AUTOCOMMIT ) );
+ }
+
+ $lb->closeAll();
+ }