diff --git a/core/includes/batch.inc b/core/includes/batch.inc index 2eddb0f..8e06a3a 100644 --- a/core/includes/batch.inc +++ b/core/includes/batch.inc @@ -280,12 +280,12 @@ function _batch_process() { $queue = _batch_queue($current_set); if ($batch['progressive']) { - if (drupal_valid_test_ua()) { + 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::SIMPLETEST_MAXIMUM_MEMORY_USAGE; + $maximum_memory = DRUPAL_TEST_MEMORY_USAGE_TRIGGER; } else { $maximum_memory = ini_get('memory_limit'); diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index ce872d4..f259c6d 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -618,8 +618,11 @@ function drupal_valid_test_ua($new_prefix = NULL) { // string. $http_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 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 (isset($user_agent) && preg_match("/^(simpletest\d+);(.+);(.+);(.+);(.+)$/", $user_agent, $matches)) { + list(, $prefix, $time, $salt, $hmac, $memory_usage_trigger) = $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 @@ -648,7 +651,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) { @@ -678,7 +681,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.php b/core/lib/Drupal.php index 9bd2ee2..ad525dd 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -94,14 +94,6 @@ class Drupal { const CORE_MINIMUM_SCHEMA_VERSION = 8000; /** - * Simpletest maximum target memory usage. - * - * This is defined here because it is used by child sites which do not have - * Simpletest installed. - */ - const SIMPLETEST_MAXIMUM_MEMORY_USAGE = '64M'; - - /** * The currently active container object, or NULL if not initialized yet. * * @var \Symfony\Component\DependencyInjection\ContainerInterface|null diff --git a/core/modules/simpletest/src/BrowserTestBase.php b/core/modules/simpletest/src/BrowserTestBase.php index ed64f08..7b659ef 100644 --- a/core/modules/simpletest/src/BrowserTestBase.php +++ b/core/modules/simpletest/src/BrowserTestBase.php @@ -217,6 +217,20 @@ protected $mink; /** + * 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'; + + /** * Initializes Mink sessions. */ protected function initMink() { @@ -449,7 +463,7 @@ public function assertSession($name = NULL) { */ protected function prepareRequest() { $session = $this->getSession(); - $session->setCookie('SIMPLETEST_USER_AGENT', drupal_generate_test_ua($this->databasePrefix)); + $session->setCookie('SIMPLETEST_USER_AGENT', drupal_generate_test_ua($this->databasePrefix, $this->memoryUsageTrigger)); } /** diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 1d29493..e05b86c 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -76,7 +76,7 @@ * * @var string|FALSE */ - protected $memoryUsageTrigger = \Drupal::SIMPLETEST_MAXIMUM_MEMORY_USAGE; + protected $memoryUsageTrigger = '64M'; /** * The handle of the current cURL connection. @@ -1311,7 +1311,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)); } }