diff --git a/core/lib/Drupal/Core/Test/TestDatabase.php b/core/lib/Drupal/Core/Test/TestDatabase.php index 42a90c0fd6..e126b3aca4 100644 --- a/core/lib/Drupal/Core/Test/TestDatabase.php +++ b/core/lib/Drupal/Core/Test/TestDatabase.php @@ -118,18 +118,19 @@ public function getDatabasePrefix() { * The unique lock ID for the test method. */ protected function getTestLock($create_lock = FALSE) { - // If we're only running with a concurrency of greater than 1 there is a - // risk the random number generated clashing. Therefore we need to create - // a lock. + // There is a risk that the generated random number is a duplicate. This + // would cause different tests to try to use the same database prefix. + // Therefore, if running with a concurrency of greater than 1, we need to + // create a lock. if (getenv('RUN_TESTS_CONCURRENCY') > 1) { $create_lock = TRUE; } - // Ensure that the generated lock ID is not in use, which may happen when - // tests are run concurrently. do { $lock_id = mt_rand(10000000, 99999999); if ($create_lock && @symlink(__FILE__, $this->getLockFile($lock_id)) === FALSE) { + // If we can't create a symlink, the lock ID is in use. Generate another + // one. Symlinks are used because they are atomic and reliable. $lock_id = NULL; } } while ($lock_id === NULL); diff --git a/core/scripts/test-site.php b/core/scripts/test-site.php index 3e33fabcda..1244f4bf29 100644 --- a/core/scripts/test-site.php +++ b/core/scripts/test-site.php @@ -18,5 +18,7 @@ putenv('SYMFONY_DEPRECATIONS_HELPER=disabled'); require_once __DIR__ . '/../tests/bootstrap.php'; +// The application version is 0.1.0 to indicate that it is for internal use only +// and not currently API. $app = new TestSiteApplication('test-site', '0.1.0'); $app->run(); diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php index 6f122d8a19..c93823fa65 100644 --- a/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php @@ -41,6 +41,8 @@ class TestSiteInstallCommand extends Command { /** * Time limit in seconds for the test. * + * Used by \Drupal\Core\Test\FunctionalTestSetupTrait::prepareEnvironment(). + * * @var int */ protected $timeLimit = 500; diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteReleaseLocksCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteReleaseLocksCommand.php index 4be43788f7..5c64df38e0 100644 --- a/core/tests/Drupal/TestSite/Commands/TestSiteReleaseLocksCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteReleaseLocksCommand.php @@ -10,6 +10,9 @@ /** * Command to release all test site database prefix locks. * + * Note that this command can't be safely tested by DrupalCI without potentially + * causing random failures. + * * @internal */ class TestSiteReleaseLocksCommand extends Command { diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php index e2f355b603..ea776c3061 100644 --- a/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php @@ -94,7 +94,7 @@ protected function tearDown(TestDatabase $test_database, $db_url) { /** * Deletes all files and directories in the specified path recursively. * - * Note this version has no dependencies on Drupal core to ensure that the + * Note this method has no dependencies on Drupal core to ensure that the * test site can be torn down even if something in the test site is broken. * * @param string $path diff --git a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php index 4c2444ef08..0eff417d29 100644 --- a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php +++ b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php @@ -177,19 +177,6 @@ public function testInstallScript() { // is released during tear down. $this->assertFileExists($this->getTestLockFile($db_prefix)); $this->assertFileNotExists($this->getTestLockFile($other_db_prefix)); - - // Release all locks. - $command_line = $php_binary_path . ' core/scripts/test-site.php release-locks'; - $process = new Process($command_line, $this->root); - // Set the timeout to a value that allows debugging. - $process->setTimeout(500); - $process->run(); - $this->assertSame(0, $process->getExitCode()); - $this->assertContains("Successfully released all the test database locks", $process->getOutput()); - - // Both tests sites' locks should no longer exist now. - $this->assertFileNotExists($this->getTestLockFile($db_prefix)); - $this->assertFileNotExists($this->getTestLockFile($other_db_prefix)); } /**