diff --git a/core/lib/Drupal/Core/Test/TestDatabase.php b/core/lib/Drupal/Core/Test/TestDatabase.php index 682c792..9bfa25d 100644 --- a/core/lib/Drupal/Core/Test/TestDatabase.php +++ b/core/lib/Drupal/Core/Test/TestDatabase.php @@ -115,7 +115,10 @@ protected function getTestLock() { // tests are run concurrently. do { $lock_id = mt_rand(10000000, 99999999); - if (@symlink(__FILE__, $this->getLockFile($lock_id)) === FALSE) { + // If we're only running with a concurrency of 1 there's no need to create + // a test lock file as there is no chance of the random number generated + // clashing. + if (getenv('RUN_TESTS_CONCURRENCY') > 1 && @symlink(__FILE__, $this->getLockFile($lock_id)) === FALSE) { $lock_id = NULL; } } while ($lock_id === NULL); @@ -123,20 +126,6 @@ protected function getTestLock() { } /** - * Releases a test lock. - * - * This should only be called once the related test fixtures have been cleaned - * up. - */ - public function releaseTestLock() { - $concurrency = getenv('RUN_TESTS_CONCURRENCY'); - // If we're doing concurrent testing then ensure no dupes in the whole run. - if (!$concurrency || $concurrency == 1) { - unlink($this->getLockFile($this->lockId)); - } - } - - /** * Releases all test locks. * * This should only be called once all the test fixtures have been cleaned up. diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php index 5fb36a4..fe25f95 100644 --- a/core/modules/simpletest/src/TestBase.php +++ b/core/modules/simpletest/src/TestBase.php @@ -1366,10 +1366,6 @@ private function restoreEnvironment() { // Delete test site directory. file_unmanaged_delete_recursive($this->siteDirectory, array($this, 'filePreDeleteCallback')); - // Release the test lock. - $test_db = new TestDatabase($test_prefix); - $test_db->releaseTestLock(); - // Restore original database connection. Database::removeConnection('default'); Database::renameConnection('simpletest_original_default', 'default'); diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index d064331..c025f7d 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -5,6 +5,7 @@ * This script runs Drupal tests from command line. */ +use Drupal\Component\FileSystem\FileSystem; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Timer; use Drupal\Component\Uuid\Php; @@ -455,6 +456,12 @@ function simpletest_script_init() { $_SERVER['HTTP_USER_AGENT'] = 'Drupal command line'; if ($args['concurrency'] > 1) { + $directory = FileSystem::getOsTemporaryDirectory(); + $test_symlink = @symlink(__FILE__, $directory . '/test_symlink'); + if (!$test_symlink) { + throw new \RuntimeException('In order to use a concurrency higher than 1 the test system needs to be able to create symlinks in ' . $directory); + } + unlink($directory . '/test_symlink'); putenv('RUN_TESTS_CONCURRENCY=' . $args['concurrency']); } diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index c34e45f..8c2492a 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -701,10 +701,6 @@ protected function tearDown() { $this->vfsRoot = NULL; $this->configImporter = NULL; - // Release the prefix. - $test_db = new TestDatabase($test_prefix); - $test_db->releaseTestLock(); - // Free up memory: Custom test class properties. // Note: Private properties cannot be cleaned up. $rc = new \ReflectionClass(__CLASS__); diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index f9f443c..d0fabd3 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -601,10 +601,6 @@ protected function cleanupEnvironment() { // Delete test site directory. file_unmanaged_delete_recursive($this->siteDirectory, array($this, 'filePreDeleteCallback')); - - // Release the prefix. - $test_db = new TestDatabase($test_prefix); - $test_db->releaseTestLock(); } /**