function ConnectionUnitTest::testOpenQueryPrefetchClose
7.x database_test.test | ConnectionUnitTest::testOpenQueryPrefetchClose() |
Tests Database::closeConnection() with a query and custom prefetch method.
File
- drupal-7.x/
modules/ simpletest/ tests/ database_test.test, line 4043
Class
- ConnectionUnitTest
- Tests management of database connections.
Code
function testOpenQueryPrefetchClose() {
if ($this->skipTest) {
return;
}
// Add and open a new connection.
$this->addConnection();
$id = $this->getConnectionID();
Database::getConnection($this->target, $this->key);
// Verify that there is a new connection.
$this->assertConnection($id);
// Execute a query.
Database::getConnection($this->target, $this->key)->query('SHOW TABLES')->fetchCol();
// Close the connection.
Database::closeConnection($this->target, $this->key);
// Wait 20ms to give the database engine sufficient time to react.
usleep(20000);
// Verify that we are back to the original connection count.
$this->assertNoConnection($id);
}