From e63515a6b7f19049ea31298f190997a7d92a958e Mon Sep 17 00:00:00 2001
From: hrach <hrach.cz@gmail.com>
Date: Tue, 14 Apr 2015 20:41:18 +0200
Subject: [PATCH] tests: fixed race condition

---
 tests/cases/integration/transactions.phpt |  6 ++++--
 tests/inc/IntegrationTestCase.php         | 13 +++++++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/tests/cases/integration/transactions.phpt b/tests/cases/integration/transactions.phpt
index 5fc68563..7ab437a8 100644
--- a/tests/cases/integration/transactions.phpt
+++ b/tests/cases/integration/transactions.phpt
@@ -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', [
@@ -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', [
@@ -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', [
@@ -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_'
diff --git a/tests/inc/IntegrationTestCase.php b/tests/inc/IntegrationTestCase.php
index e1ff3cb6..f4511174 100644
--- a/tests/inc/IntegrationTestCase.php
+++ b/tests/inc/IntegrationTestCase.php
@@ -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([