diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index 543105f..3b9b56e 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -29,6 +29,12 @@
  * \Drupal\simpletest\WebTestBase or \Drupal\simpletest\UnitTestBase.
  */
 abstract class TestBase {
+
+  /**
+   * The time that the test suffix is locked for (in seconds).
+   */
+  const TEST_SUFFIX_LOCK_TIME = 600;
+
   /**
    * The test run ID.
    *
@@ -187,6 +193,13 @@
   protected $randomGenerator;
 
   /**
+   * A unique test suffix.
+   *
+   * @var string
+   */
+  private $testSuffix;
+
+  /**
    * Constructor for Test.
    *
    * @param $test_id
@@ -884,7 +897,7 @@ public function run(array $methods = array()) {
    * @see drupal_valid_test_ua()
    */
   private function prepareDatabasePrefix() {
-    $suffix = mt_rand(1000, 1000000);
+    $suffix = $this->createTestSuffix();
     $this->siteDirectory = 'sites/simpletest/' . $suffix;
     $this->databasePrefix = 'simpletest' . $suffix;
 
@@ -901,6 +914,25 @@ private function prepareDatabasePrefix() {
   }
 
   /**
+   * Creates a unique test suffix.
+   *
+   * Uniqueness is guaranteed by using the lock system on the parent site. The
+   * lock is released during \Drupal\simpletest\TestBase::restoreEnvironment().
+   *
+   * @return int
+   *   The unique test suffix.
+   */
+  private function createTestSuffix() {
+    // Ensure that the suffix is unique.
+    do {
+      // Ensure that the value is 6 characters long.
+      $suffix = (string) mt_rand(100000, 999999);
+    } while ((!\Drupal::lock()->acquire('simpletest.test_suffix.' . $suffix, $this::TEST_SUFFIX_LOCK_TIME)));
+    $this->testSuffix = $suffix;
+    return $suffix;
+  }
+
+  /**
    * Changes the database connection to the prefixed one.
    *
    * @see TestBase::prepareEnvironment()
@@ -1208,6 +1240,9 @@ private function restoreEnvironment() {
     // Restore original user session.
     $user = $this->originalUser;
     drupal_save_session(TRUE);
+    // Releases test suffix lock.
+    // @see \Drupal\simpletest\TestBase::createTestSuffix()
+    \Drupal::lock()->release('simpletest.test_suffix.' . $this->testSuffix);
   }
 
   /**
