Skip to content

Commit

Permalink
tests: fixed race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Apr 14, 2015
1 parent 239fa5f commit e63515a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions tests/cases/integration/transactions.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TransactionsTest extends IntegrationTestCase

public function testRollback()
{
Environment::lock('data', TEMP_DIR);
$this->lockConnection($this->connection);
$this->connection->beginTransaction();

$this->connection->query('INSERT INTO tags %values', [
Expand All @@ -38,7 +38,7 @@ class TransactionsTest extends IntegrationTestCase

public function testCommit()
{
Environment::lock('data', TEMP_DIR);
$this->lockConnection($this->connection);
$this->connection->beginTransaction();

$this->connection->query('INSERT INTO tags %values', [
Expand All @@ -56,6 +56,7 @@ class TransactionsTest extends IntegrationTestCase

public function testTransactionalFail()
{
$this->lockConnection($this->connection);
Assert::exception(function() {
$this->connection->transactional(function(Connection $connection) {
$connection->query('INSERT INTO tags %values', [
Expand All @@ -75,6 +76,7 @@ class TransactionsTest extends IntegrationTestCase

public function testTransactionalOk()
{
$this->lockConnection($this->connection);
$this->connection->transactional(function(Connection $connection) {
$connection->query('INSERT INTO tags %values', [
'name' => '_TRANS_TRANSACTIONAL_OK_'
Expand Down
13 changes: 11 additions & 2 deletions tests/inc/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@ class IntegrationTestCase extends TestCase

public function initData(Connection $connection)
{
$this->lockConnection($connection);
if ($connection->getPlatform() instanceof PostgreSqlPlatform) {
Environment::lock('data-pgsql', TEMP_DIR);
FileImporter::executeFile($connection, __DIR__ . '/../data/pgsql-data.sql');
} else {
Environment::lock('data-mysql', TEMP_DIR);
FileImporter::executeFile($connection, __DIR__ . '/../data/mysql-data.sql');
}
}


protected function lockConnection(Connection $connection)
{
if ($connection->getPlatform() instanceof PostgreSqlPlatform) {
Environment::lock('data-pgsql', TEMP_DIR);
} else {
Environment::lock('data-mysql', TEMP_DIR);
}
}


protected function createConnection($params = [])
{
$options = array_merge([
Expand Down

0 comments on commit e63515a

Please sign in to comment.