diff --git a/core/includes/batch.inc b/core/includes/batch.inc
index a4b5378..4027a3b 100644
--- a/core/includes/batch.inc
+++ b/core/includes/batch.inc
@@ -279,11 +279,27 @@ function _batch_process() {
     // processed or all sets have been completed.
     $queue = _batch_queue($current_set);
 
-    // If we are in progressive mode, break processing after 1 second.
-    if ($batch['progressive'] && Timer::read('batch_processing') > 1000) {
-      // Record elapsed wall clock time.
-      $current_set['elapsed'] = round((microtime(TRUE) - $current_set['start']) * 1000, 2);
-      break;
+    if ($batch['progressive']) {
+      if (defined('DRUPAL_TEST_MEMORY_USAGE_TRIGGER')) {
+        // Limit maximum memory when we're under test to the same value as
+        // \Drupal\simpletest\WebTestBase::$memoryUsageTrigger to ensure that
+        // Drupal works under that limit.
+        // @see \Drupal\simpletest\WebTestBase::curlHeaderCallback
+        $maximum_memory = DRUPAL_TEST_MEMORY_USAGE_TRIGGER;
+      }
+      else {
+        $maximum_memory = ini_get('memory_limit');
+      }
+      // Limit to 60% memory use.
+      $max_bytes = \Drupal\Component\Utility\Bytes::toInt($maximum_memory) * 0.4;
+
+      // If we are in progressive mode, break processing after 1 second or using
+      // 60% of available memory.
+      if (Timer::read('batch_processing') > 1000 || memory_get_usage(TRUE) > $max_bytes) {
+        // Record elapsed wall clock time.
+        $current_set['elapsed'] = round((microtime(TRUE) - $current_set['start']) * 1000, 2);
+        break;
+      }
     }
   }
 
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 2294d47..1ef5525 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -623,6 +623,9 @@ function drupal_valid_test_ua($new_prefix = NULL) {
   $user_agent = isset($_COOKIE['SIMPLETEST_USER_AGENT']) ? $_COOKIE['SIMPLETEST_USER_AGENT'] : $http_user_agent;
   if (isset($user_agent) && preg_match("/^(simpletest\d+):(.+):(.+):(.+)$/", $user_agent, $matches)) {
     list(, $prefix, $time, $salt, $hmac) = $matches;
+    if ($memory_usage_trigger !== '0') {
+      define('DRUPAL_TEST_MEMORY_USAGE_TRIGGER', $memory_usage_trigger);
+    }
     $check_string = $prefix . ':' . $time . ':' . $salt;
     // Read the hash salt prepared by drupal_generate_test_ua().
     // This function is called before settings.php is read and Drupal's error
@@ -651,7 +654,7 @@ function drupal_valid_test_ua($new_prefix = NULL) {
 /**
  * Generates a user agent string with a HMAC and timestamp for simpletest.
  */
-function drupal_generate_test_ua($prefix) {
+function drupal_generate_test_ua($prefix, $memory_usage_trigger = '64M') {
   static $key, $last_prefix;
 
   if (!isset($key) || $last_prefix != $prefix) {
@@ -681,7 +684,10 @@ function drupal_generate_test_ua($prefix) {
   // Generate a moderately secure HMAC based on the database credentials.
   $salt = uniqid('', TRUE);
   $check_string = $prefix . ':' . time() . ':' . $salt;
-  return $check_string . ':' . Crypt::hmacBase64($check_string, $key);
+  if ($memory_usage_trigger === FALSE) {
+    $memory_usage_trigger = '0';
+  }
+  return $check_string . ':' . Crypt::hmacBase64($check_string, $key) . ';' . $memory_usage_trigger;
 }
 
 /**
diff --git a/core/lib/Drupal/Core/EventSubscriber/ExceptionTestSiteSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ExceptionTestSiteSubscriber.php
index f1088bf..a8b1a26 100644
--- a/core/lib/Drupal/Core/EventSubscriber/ExceptionTestSiteSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/ExceptionTestSiteSubscriber.php
@@ -3,7 +3,9 @@
 namespace Drupal\Core\EventSubscriber;
 
 use Drupal\Core\Utility\Error;
+use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
+use Symfony\Component\HttpKernel\KernelEvents;
 
 /**
  * Custom handling of errors when in a system-under-test.
@@ -41,7 +43,7 @@ public function on500(GetResponseForExceptionEvent $event) {
 
     // When running inside the testing framework, we relay the errors
     // to the tested site by the way of HTTP headers.
-    if (DRUPAL_TEST_IN_CHILD_SITE && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS)) {
+    if ($this->canAddHeaders()) {
       // $number does not use drupal_static as it should not be reset
       // as it uniquely identifies each PHP error.
       static $number = 0;
@@ -59,4 +61,38 @@ public function on500(GetResponseForExceptionEvent $event) {
     }
   }
 
+  /**
+   * Handles response being sent.
+   *
+   * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
+   *   The event to process.
+   */
+  public function onResponse(FilterResponseEvent $event) {
+    if ($this->canAddHeaders()) {
+      $event->getResponse()->headers->add([
+        'X-Drupal-Memory-Peak' => memory_get_peak_usage(TRUE),
+      ]);
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getSubscribedEvents() {
+    $events = parent::getSubscribedEvents();
+    // Add a listener for outputting peak memory usage.
+    $events[KernelEvents::RESPONSE][] = ['onResponse', 100];
+    return $events;
+  }
+
+  /**
+   * Indicates whether headers should be added.
+   *
+   * @return bool
+   *   TRUE if headers should be added.
+   */
+  protected function canAddHeaders() {
+    return (defined('DRUPAL_TEST_IN_CHILD_SITE') && DRUPAL_TEST_IN_CHILD_SITE && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS));
+  }
+
 }
diff --git a/core/modules/simpletest/src/Tests/BrokenSetUpTest.php b/core/modules/simpletest/src/Tests/BrokenSetUpTest.php
index e988f4d..af3ed5a 100644
--- a/core/modules/simpletest/src/Tests/BrokenSetUpTest.php
+++ b/core/modules/simpletest/src/Tests/BrokenSetUpTest.php
@@ -25,6 +25,11 @@ class BrokenSetUpTest extends WebTestBase {
   public static $modules = array('simpletest');
 
   /**
+   * Set no memory limit for this test. The SimpleTest UI is very expensive.
+   */
+  protected $memoryUsageTrigger = FALSE;
+
+  /**
    * The path to the shared trigger file.
    *
    * @var string
diff --git a/core/modules/simpletest/src/Tests/InstallationProfileModuleTestsTest.php b/core/modules/simpletest/src/Tests/InstallationProfileModuleTestsTest.php
index a1063e7..bc9932d 100644
--- a/core/modules/simpletest/src/Tests/InstallationProfileModuleTestsTest.php
+++ b/core/modules/simpletest/src/Tests/InstallationProfileModuleTestsTest.php
@@ -26,6 +26,11 @@ class InstallationProfileModuleTestsTest extends WebTestBase {
   protected $adminUser;
 
   /**
+   * Set no memory limit for this test. The SimpleTest UI is very expensive.
+   */
+  protected $memoryUsageTrigger = FALSE;
+
+  /**
    * Use the Testing profile.
    *
    * The Testing profile contains drupal_system_listing_compatible_test.test,
diff --git a/core/modules/simpletest/src/Tests/MissingCheckedRequirementsTest.php b/core/modules/simpletest/src/Tests/MissingCheckedRequirementsTest.php
index 0b21d54..aa83d2c 100644
--- a/core/modules/simpletest/src/Tests/MissingCheckedRequirementsTest.php
+++ b/core/modules/simpletest/src/Tests/MissingCheckedRequirementsTest.php
@@ -18,6 +18,11 @@ class MissingCheckedRequirementsTest extends WebTestBase {
    */
   public static $modules = array('simpletest');
 
+  /**
+   * Set no memory limit for this test. The SimpleTest UI is very expensive.
+   */
+  protected $memoryUsageTrigger = FALSE;
+
   protected function setUp() {
     parent::setUp();
     $admin_user = $this->drupalCreateUser(array('administer unit tests'));
diff --git a/core/modules/simpletest/src/Tests/OtherInstallationProfileTestsTest.php b/core/modules/simpletest/src/Tests/OtherInstallationProfileTestsTest.php
index b4263f1..df772bc 100644
--- a/core/modules/simpletest/src/Tests/OtherInstallationProfileTestsTest.php
+++ b/core/modules/simpletest/src/Tests/OtherInstallationProfileTestsTest.php
@@ -34,6 +34,11 @@ class OtherInstallationProfileTestsTest extends WebTestBase {
   protected $profile = 'minimal';
 
   /**
+   * Set no memory limit for this test. The SimpleTest UI is very expensive.
+   */
+  protected $memoryUsageTrigger = FALSE;
+
+  /**
    * An administrative user with permission to administer unit tests.
    *
    * @var \Drupal\user\UserInterface
diff --git a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php
index 89ed6d2..6465feb 100644
--- a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php
+++ b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php
@@ -19,6 +19,11 @@ class SimpleTestBrowserTest extends WebTestBase {
    */
   public static $modules = array('simpletest', 'test_page_test');
 
+  /**
+   * Set no memory limit for this test. The SimpleTest UI is very expensive.
+   */
+  protected $memoryUsageTrigger = FALSE;
+
   protected function setUp() {
     parent::setUp();
     // Create and log in an admin user.
@@ -100,6 +105,7 @@ public function testUserAgentValidation() {
     $this->assertResponse(200, 'Requesting https.php with a legitimate simpletest User-Agent returns OK.');
 
     // Now slightly modify the HMAC on the header, which should not validate.
+    $test_ua = substr_replace($test_ua, 'X;', strrpos($test_ua, ';'), 1);
     $this->additionalCurlOptions = array(CURLOPT_USERAGENT => $test_ua . 'X');
     $this->drupalGet($HTTP_path);
     $this->assertResponse(403, 'Requesting http.php with a bad simpletest User-Agent fails.');
diff --git a/core/modules/simpletest/src/Tests/SimpleTestTest.php b/core/modules/simpletest/src/Tests/SimpleTestTest.php
index 19ab17f..f654d8e 100644
--- a/core/modules/simpletest/src/Tests/SimpleTestTest.php
+++ b/core/modules/simpletest/src/Tests/SimpleTestTest.php
@@ -3,7 +3,9 @@
 namespace Drupal\simpletest\Tests;
 
 use Drupal\Component\Utility\Crypt;
+use Drupal\Core\Url;
 use Drupal\simpletest\WebTestBase;
+use Drupal\user\Entity\User;
 
 /**
  * Tests SimpleTest's web interface: check that the intended tests were run and
@@ -22,6 +24,11 @@ class SimpleTestTest extends WebTestBase {
   public static $modules = ['simpletest'];
 
   /**
+   * Set no memory limit for this test. The SimpleTest UI is very expensive.
+   */
+  protected $memoryUsageTrigger = FALSE;
+
+  /**
    * The results array that has been parsed by getTestResults().
    *
    * @var array
@@ -225,6 +232,14 @@ function stubTest() {
 
     // This causes the debug message asserted in confirmStubResults().
     debug('Foo', 'Debug', FALSE);
+
+    // This causes \Drupal\simpletest\WebTestBase::curlHeaderCallback() to fail.
+    // Set an absurdly low limit and get a page.
+    $old_limit = $this->memoryUsageTrigger;
+    $this->memoryUsageTrigger = '1M';
+    // Getting the front page will result in a redirect to /user/2.
+    $this->drupalGet('<front>');
+    $this->memoryUsageTrigger = $old_limit;
   }
 
   /**
@@ -263,7 +278,12 @@ function confirmStubTestResults() {
 
     $this->assertAssertion("Debug: 'Foo'", 'Debug', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
 
-    $this->assertEqual('16 passes, 3 fails, 2 exceptions, 3 debug messages', $this->childTestResults['summary']);
+    // Check that we have two exceeded memory errors. One for the frontpage and
+    // one for the user page which the request is redirected to.
+    $this->assertAssertion('exceeded acceptable maximum (1M) on url ' . Url::fromRoute('<front>')->setAbsolute()->toString(), 'Other', 'Fail', 'WebTestBase.php', 'Drupal\simpletest\WebTestBase->curlExec()');
+    $this->assertAssertion('exceeded acceptable maximum (1M) on url ' . User::load(2)->urlInfo()->setAbsolute()->toString(), 'Other', 'Fail', 'WebTestBase.php', 'Drupal\simpletest\WebTestBase->curlExec()');
+
+    $this->assertEqual('18 passes, 5 fails, 2 exceptions, 4 debug messages', $this->childTestResults['summary']);
 
     $this->testIds[] = $test_id = $this->getTestIdFromResults();
     $this->assertTrue($test_id, 'Found test ID in results.');
diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php
index eb1ad73..8f28b20 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -6,6 +6,7 @@
 use Drupal\Component\FileCache\FileCacheFactory;
 use Drupal\Component\Serialization\Json;
 use Drupal\Component\Serialization\Yaml;
+use Drupal\Component\Utility\Bytes;
 use Drupal\Component\Utility\Html;
 use Drupal\Component\Utility\NestedArray;
 use Drupal\Component\Utility\UrlHelper;
@@ -72,6 +73,20 @@
   protected $url;
 
   /**
+   * The maximum memory usage to allow on the child site, in MB.
+   *
+   * The minimum amount of memory Drupal expects to have available is defined by
+   * DRUPAL_MINIMUM_PHP_MEMORY_LIMIT. This default value on the base class
+   * should be less than or equal to DRUPAL_MINIMUM_PHP_MEMORY_LIMIT. If a
+   * module requires more memory than this limit, the module should add a
+   * check to its hook_requirements() and use the higher value in its tests.
+   * The check can be disabled for a specific test by setting it to FALSE.
+   *
+   * @var string|FALSE
+   */
+  protected $memoryUsageTrigger = '64M';
+
+  /**
    * The handle of the current cURL connection.
    *
    * @var resource
@@ -1165,7 +1180,7 @@ protected function curlInitialize() {
     // We set the user agent header on each request so as to use the current
     // time and a new uniqid.
     if (preg_match('/simpletest\d+/', $this->databasePrefix, $matches)) {
-      curl_setopt($this->curlHandle, CURLOPT_USERAGENT, drupal_generate_test_ua($matches[0]));
+      curl_setopt($this->curlHandle, CURLOPT_USERAGENT, drupal_generate_test_ua($matches[0], $this->memoryUsageTrigger));
     }
   }
 
@@ -1324,6 +1339,13 @@ protected function curlHeaderCallback($curlHandler, $header) {
       // the header.
       call_user_func_array(array(&$this, 'error'), unserialize(urldecode($matches[1])));
     }
+    if ($this->memoryUsageTrigger && preg_match('/^X-Drupal-Memory-Peak: (.*)$/', $header, $matches) && (float) $matches[1] >= Bytes::toInt($this->memoryUsageTrigger)) {
+      $this->fail(SafeMarkup::format('Child site memory usage (@site_usage) exceeded acceptable maximum (@max_usage) on url @url', [
+        '@url' => curl_getinfo($curlHandler, CURLINFO_EFFECTIVE_URL),
+        '@site_usage' => format_size($matches[1]),
+        '@max_usage' => $this->memoryUsageTrigger,
+      ]));
+    }
 
     // Save cookies.
     if (preg_match('/^Set-Cookie: ([^=]+)=(.+)/', $header, $matches)) {
