diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteReleaseLockCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteReleaseLockCommand.php deleted file mode 100644 index b78c55f8d2..0000000000 --- a/core/tests/Drupal/TestSite/Commands/TestSiteReleaseLockCommand.php +++ /dev/null @@ -1,49 +0,0 @@ -setName('release-lock') - ->setDescription('Releases all test site locks') - ->setHelp('The locks ensure test site database prefixes are not reused.') - ->addArgument('db_prefix', InputArgument::OPTIONAL, 'The database prefix for the test site') - ->addOption('all', NULL, InputOption::VALUE_NONE, 'Use to release all the test locks') - ->addUsage('test12345678') - ->addUsage('--all'); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) { - if ($input->getOption('all')) { - TestDatabase::releaseAllTestLocks(); - } - elseif ($input->getArgument('db_prefix')) { - $test_db = new TestDatabase($input->getArgument('db_prefix')); - $test_db->releaseLock(); - } - else { - throw new \RuntimeException('The release-lock command should be called with a database prefix or --all'); - } - $output->writeln("Successfully released all the test database locks"); - } - -} diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteReleaseLocksCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteReleaseLocksCommand.php new file mode 100644 index 0000000000..173342ceb7 --- /dev/null +++ b/core/tests/Drupal/TestSite/Commands/TestSiteReleaseLocksCommand.php @@ -0,0 +1,34 @@ +setName('release-locks') + ->setDescription('Releases all test site locks') + ->setHelp('The locks ensure test site database prefixes are not reused.'); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) { + TestDatabase::releaseAllTestLocks(); + $output->writeln("Successfully released all the test database locks"); + } + +} diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php index be4d6bda1a..52ac0dea6d 100644 --- a/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php @@ -28,8 +28,10 @@ protected function configure() { ->setHelp('All the database tables and files will be removed.') ->addArgument('db_prefix', InputArgument::REQUIRED, 'The database prefix for the test site') ->addOption('db_url', NULL, InputOption::VALUE_OPTIONAL, 'URL for database or SIMPLETEST_DB', getenv('SIMPLETEST_DB')) + ->addOption('keep_lock', 'k', InputOption::VALUE_NONE, 'Keeps the database prefix lock. Useful for ensuring test isolation when running concurrent tests.') ->addUsage('test12345678') - ->addUsage('test12345678 --db_url "mysql://username:password@localhost/databasename#table_prefix"'); + ->addUsage('test12345678 --db_url "mysql://username:password@localhost/databasename#table_prefix"') + ->addUsage('test12345678 --keep_lock'); } /** @@ -54,6 +56,12 @@ protected function execute(InputInterface $input, OutputInterface $output) { // Handle the cleanup of the test site. $this->tearDown($test_database, $db_url); + + // Release the test database prefix lock. + if (!$input->getOption('keep_lock')) { + $test_database->releaseLock(); + } + $output->writeln("Successfully uninstalled $db_prefix test site"); } diff --git a/core/tests/Drupal/TestSite/TestSiteApplication.php b/core/tests/Drupal/TestSite/TestSiteApplication.php index 87a5ca56d3..aff7c1dc9e 100644 --- a/core/tests/Drupal/TestSite/TestSiteApplication.php +++ b/core/tests/Drupal/TestSite/TestSiteApplication.php @@ -3,7 +3,7 @@ namespace Drupal\TestSite; use Drupal\TestSite\Commands\TestSiteInstallCommand; -use Drupal\TestSite\Commands\TestSiteReleaseLockCommand; +use Drupal\TestSite\Commands\TestSiteReleaseLocksCommand; use Drupal\TestSite\Commands\TestSiteTearDownCommand; use Symfony\Component\Console\Application; @@ -25,7 +25,7 @@ protected function getDefaultCommands() { $default_commands = parent::getDefaultCommands(); $default_commands[] = new TestSiteInstallCommand(); $default_commands[] = new TestSiteTearDownCommand(); - $default_commands[] = new TestSiteReleaseLockCommand(); + $default_commands[] = new TestSiteReleaseLocksCommand(); return $default_commands; } diff --git a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php index d1df6dcff1..9136f61cf4 100644 --- a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php +++ b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php @@ -139,7 +139,7 @@ public function testInstallScript() { $this->assertFileExists($this->getTestLockFile($other_db_prefix)); // Now test the tear down process as well. - $command_line = $php_binary_path . ' core/scripts/test-site.php tear-down ' . $db_prefix . ' --db_url "' . getenv('SIMPLETEST_DB') . '"'; + $command_line = $php_binary_path . ' core/scripts/test-site.php tear-down ' . $db_prefix . ' --keep_lock --db_url "' . getenv('SIMPLETEST_DB') . '"'; $process = new Process($command_line, $this->root); // Set the timeout to a value that allows debugging. $process->setTimeout(500); @@ -173,20 +173,9 @@ public function testInstallScript() { $this->assertCount(0, Database::getConnection('default', $other_key)->schema()->findTables('%')); $this->assertFileNotExists($test_file); - // The locks should still exist. + // The lock for the first site should still exist but the second site is + // clean up during tear down. $this->assertFileExists($this->getTestLockFile($db_prefix)); - $this->assertFileExists($this->getTestLockFile($other_db_prefix)); - - // Test releasing a lock. We can't test releasing all locks because this - // would affect the DrupalCI test run. - $command_line = $php_binary_path . ' core/scripts/test-site.php release-lock ' . $db_prefix; - $process = new Process($command_line, $this->root); - $process->run(); - $this->assertFileNotExists($this->getTestLockFile($db_prefix)); - $this->assertFileExists($this->getTestLockFile($other_db_prefix)); - $command_line = $php_binary_path . ' core/scripts/test-site.php release-lock ' . $other_db_prefix; - $process = new Process($command_line, $this->root); - $process->run(); $this->assertFileNotExists($this->getTestLockFile($other_db_prefix)); } @@ -227,14 +216,6 @@ public function testInstallInDifferentLanguage() { // Ensure that all the tables for this DB prefix are gone. $this->assertCount(0, Database::getConnection('default', $this->addTestDatabase($db_prefix))->schema()->findTables('%')); - - // Clean up the test site lock. - $this->assertFileExists($this->getTestLockFile($db_prefix)); - $command_line = $php_binary_path . ' core/scripts/test-site.php release-lock ' . $db_prefix; - $process = new Process($command_line, $this->root); - $process->run(); - $this->assertSame(0, $process->getExitCode()); - $this->assertFileNotExists($this->getTestLockFile($db_prefix)); } /** @@ -252,20 +233,6 @@ public function testTearDownDbPrefixValidation() { $this->assertContains('Invalid database prefix: not-a-valid-prefix', $process->getErrorOutput()); } - /** - * @coversNothing - */ - public function testReleaseLockValidation() { - $php_binary_finder = new PhpExecutableFinder(); - $php_binary_path = $php_binary_finder->find(); - - $command_line = $php_binary_path . ' core/scripts/test-site.php release-lock'; - $process = new Process($command_line, $this->root); - $process->run(); - $this->assertSame(1, $process->getExitCode()); - $this->assertContains('The release-lock command should be called with a database prefix or --all', $process->getErrorOutput()); - } - /** * Adds the installed test site to the database connection info. *