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/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index cb4b7c5..dd6629e 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -48,6 +48,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
@@ -100,6 +105,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
@@ -3267,6 +3277,83 @@ protected function verboseEmail($count = 1) {
   }
 
   /**
+   * 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;
+
+    // Set a new unique cookie filename.
+    do {
+      $this->cookieFile = $this->public_files_directory . '/' . $this->randomName() . '.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();
+
+    $this->curlHandles = array();
+    $this->loggedInUsers = array();
+    $this->loggedInUser = FALSE;
+    $this->cookieFile = $this->public_files_directory . '/' . $this->randomName() . '.jar';
+    unset($this->curlHandle);
+  }
+
+  /**
    * Creates a mock request and sets it on the generator.
    *
    * This is used to manipulate how the generator generates paths during tests.
