diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Tests/MultipleSessionTest.php b/core/modules/simpletest/lib/Drupal/simpletest/Tests/MultipleSessionTest.php
new file mode 100644
index 0000000..9fd5314
--- /dev/null
+++ b/core/modules/simpletest/lib/Drupal/simpletest/Tests/MultipleSessionTest.php
@@ -0,0 +1,86 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\simpletest\Tests\MultipleSessionTest.
+ */
+
+namespace Drupal\simpletest\Tests;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests that SimpleTests multiple session handling works.
+ */
+class MultipleSessionTest extends WebTestBase {
+
+  /**
+   * getInfo() returns properties that are displayed in the test selection form.
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Multiple Session Tests',
+      'description' => 'Ensure the multi session tests for SimpleTest work as expected',
+      'group' => 'SimpleTest',
+    );
+  }
+
+  /**
+   * setUp() performs any pre-requisite tasks that need to happen.
+   */
+  public function setUp() {
+    parent::setUp();
+  }
+
+  /**
+   * Test session stash and restore.
+   *
+   * This test checks that multiple sessions are working in SimpleTest by
+   * logging in as two different users simultaneously via two cUrl sessions.
+   */
+  public function testSessionStashAndRestore() {
+
+    // Create and log in our privileged user.
+    $user1 = $this->drupalCreateUser(array('access content'));
+    $user2 = $this->drupalCreateUser(array('access content'));
+
+    // Login under session 1.
+    $this->drupalLogin($user1);
+    $this->drupalGet('user');
+    $this->assertText(t('Log out'), 'User is logged in under session 1.');
+    $this->assertText($user1->name, 'User1 is logged in under session 1.');
+
+    // Backup session 1.
+    $session_1 = $this->stashSession();
+
+    // Check session 2 is logged out.
+    $this->drupalGet('node');
+    $this->assertNoText(t('Log out'), 'Session 1 is shelved.');
+
+    // Login under session 2.
+    $this->drupalLogin($user2);
+    $this->drupalGet('user');
+    $this->assertText(t('Log out'), 'User is logged in under session 2.');
+    $this->assertText($user2->name, 'User2 is logged in under session 2.');
+
+    // Backup session 2.
+    $session_2 = $this->stashSession();
+
+    // Switch to session 1.
+    $this->restoreSession($session_1);
+
+    // Check still logged in as session 1.
+    $this->drupalGet('user');
+    $this->assertText(t('Log out'), 'User is logged in under session 1.');
+    $this->assertText($user1->name, 'User1 is logged in under session 1.');
+
+    // Switch to session 2.
+    $this->restoreSession($session_2);
+
+    // Check still logged in as session 2.
+    $this->drupalGet('user');
+    $this->assertText(t('Log out'), 'User is logged in under session 2.');
+    $this->assertText($user2->name, 'User2 is logged in under session 2.');
+  }
+
+}
diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php
index e44979f..7ee5d03 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -10,22 +10,19 @@
 use Drupal\Component\Serialization\Json;
 use Drupal\Component\Serialization\Yaml;
 use Drupal\Component\Utility\Crypt;
-use Drupal\Component\Utility\NestedArray;
+use Drupal\Component\Utility\Random;
 use Drupal\Component\Utility\String;
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\DependencyInjection\YamlFileLoader;
 use Drupal\Core\DrupalKernel;
 use Drupal\Core\Database\Database;
-use Drupal\Core\Database\ConnectionNotDefinedException;
 use Drupal\Core\Entity\EntityInterface;
-use Drupal\Core\Language\LanguageInterface;
 use Drupal\Core\Render\Element;
 use Drupal\Core\Session\AccountInterface;
 use Drupal\Core\Session\AnonymousUserSession;
 use Drupal\Core\Session\UserSession;
 use Drupal\Core\Site\Settings;
 use Drupal\Core\StreamWrapper\PublicStream;
-use Drupal\Core\Datetime\DrupalDateTime;
 use Drupal\block\Entity\Block;
 use Symfony\Component\HttpFoundation\Request;
 use Drupal\user\Entity\Role;
@@ -61,6 +58,11 @@
   protected $curlHandle;
 
   /**
+   * An array of other session curlHandles.
+   */
+  protected $curlHandles = array();
+
+  /**
    * The headers of the page currently loaded in the internal browser.
    *
    * @var Array
@@ -85,6 +87,11 @@
   protected $loggedInUser = FALSE;
 
   /**
+   * A collection of other logged in users.
+   */
+  protected $loggedInUsers = array();
+
+  /**
    * The current cookie file used by cURL.
    *
    * We do not reuse the cookies in further runs, so we do not need a file
@@ -2717,4 +2724,82 @@ protected function prepareRequestForGenerator($clean_urls = TRUE, $override_serv
 
     return $request;
   }
+
+  /**
+   * Initialise a new unique session.
+   *
+   * @return string
+   *   Unique identifier for the session just stored.
+   *   It is the cookiefile name.
+   */
+  protected function stashSession() {
+    if (empty($this->cookieFile)) {
+      // No session to stash.
+      return;
+    }
+
+    // The session_id is the current cookieFile.
+    $session_id = $this->cookieFile;
+
+    $this->curlHandles[$session_id] = $this->curlHandle;
+    $this->loggedInUsers[$session_id] = $this->loggedInUser;
+
+    // Reset Curl.
+    unset($this->curlHandle);
+    $this->loggedInUser = FALSE;
+    $random = new Random();
+    // Set a new unique cookie filename.
+    do {
+      $this->cookieFile = $this->public_files_directory . '/' . $random->name() . '.jar';
+    }
+    while (isset($this->curlHandles[$this->cookieFile]));
+
+    return $session_id;
+  }
+
+  /**
+   * Restore a previously stashed session.
+   *
+   * @param string $session_id
+   *   The session to restore as returned by stashSession();
+   *   This is also the path to the cookie file.
+   *
+   * @return string
+   *   The old session id that was replaced.
+   */
+  protected function restoreSession($session_id) {
+    $old_session_id = NULL;
+
+    if (isset($this->curlHandle)) {
+      $old_session_id = $this->stashSession();
+    }
+
+    // Restore the specified session.
+    $this->curlHandle = $this->curlHandles[$session_id];
+    $this->cookieFile = $session_id;
+    $this->loggedInUser = $this->loggedInUsers[$session_id];
+
+    return $old_session_id;
+  }
+
+  /**
+   * Close all stashed sessions and the current session.
+   */
+  protected function closeAllSessions() {
+    foreach ($this->curlHandles as $cookie_file => $curl_handle) {
+      if (isset($curl_handle)) {
+        curl_close($curl_handle);
+      }
+    }
+
+    // Make the server forget all sessions.
+    db_truncate('sessions')->execute();
+
+    $random = new Random();
+    $this->curlHandles = array();
+    $this->loggedInUsers = array();
+    $this->loggedInUser = FALSE;
+    $this->cookieFile = $this->public_files_directory . '/' . $random->name() . '.jar';
+    unset($this->curlHandle);
+  }
 }
