summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Rowlands2018-01-03 21:37:32 (GMT)
committerLee Rowlands2018-01-03 21:37:32 (GMT)
commit9d552cad6cfbe8383b96b74ffc6176503a7b0c2e (patch)
tree91f777ba067f6f85e13a9598c1ffd0d3a0ab7640
parentcf805af249c160e5d8da632c72ee4d12719ff8f5 (diff)
Issue #2926309 by vaplas, alexpott, mpdonadio, tacituseu, Mixologic: Random fail due to APCu not being able to allocate memory
-rw-r--r--core/lib/Drupal/Core/Site/Settings.php6
-rw-r--r--core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php16
-rw-r--r--core/modules/system/tests/src/Functional/Module/ClassLoaderTest.php5
-rw-r--r--core/tests/Drupal/Tests/Core/Site/SettingsTest.php2
4 files changed, 26 insertions, 3 deletions
diff --git a/core/lib/Drupal/Core/Site/Settings.php b/core/lib/Drupal/Core/Site/Settings.php
index a1a6c38..bdd2609 100644
--- a/core/lib/Drupal/Core/Site/Settings.php
+++ b/core/lib/Drupal/Core/Site/Settings.php
@@ -156,8 +156,8 @@ final class Settings {
* cache. By default, this method will produce a unique prefix per site using
* the hash salt. If the setting 'apcu_ensure_unique_prefix' is set to FALSE
* then if the caller does not provide a $site_path only the Drupal root will
- * be used. This allows WebTestBase to use the same prefix ensuring that the
- * number of APCu items created during a full test run is kept to a minimum.
+ * be used. This allows tests to use the same prefix ensuring that the number
+ * of APCu items created during a full test run is kept to a minimum.
* Additionally, if a multi site implementation does not use site specific
* module directories setting apcu_ensure_unique_prefix would allow the sites
* to share APCu cache items.
@@ -168,6 +168,8 @@ final class Settings {
*
* @return string
* The prefix for APCu user cache keys.
+ *
+ * @see https://www.drupal.org/project/drupal/issues/2926309
*/
public static function getApcuPrefix($identifier, $root, $site_path = '') {
if (static::get('apcu_ensure_unique_prefix', TRUE)) {
diff --git a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
index f9f97ec..3165815 100644
--- a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
+++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
@@ -42,6 +42,18 @@ trait FunctionalTestSetupTrait {
protected $configDirectories = [];
/**
+ * The flag to set 'apcu_ensure_unique_prefix' setting.
+ *
+ * Wide use of a unique prefix can lead to problems with memory, if tests are
+ * run with a concurrency higher than 1. Therefore, FALSE by default.
+ *
+ * @var bool
+ *
+ * @see \Drupal\Core\Site\Settings::getApcuPrefix().
+ */
+ protected $apcuEnsureUniquePrefix = FALSE;
+
+ /**
* Prepares site settings and services before installation.
*/
protected function prepareSettings() {
@@ -83,6 +95,10 @@ trait FunctionalTestSetupTrait {
'value' => $this->originalProfile,
'required' => TRUE,
];
+ $settings['settings']['apcu_ensure_unique_prefix'] = (object) [
+ 'value' => $this->apcuEnsureUniquePrefix,
+ 'required' => TRUE,
+ ];
$this->writeSettings($settings);
// Allow for test-specific overrides.
$settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php';
diff --git a/core/modules/system/tests/src/Functional/Module/ClassLoaderTest.php b/core/modules/system/tests/src/Functional/Module/ClassLoaderTest.php
index 93c0bf3..335a03a 100644
--- a/core/modules/system/tests/src/Functional/Module/ClassLoaderTest.php
+++ b/core/modules/system/tests/src/Functional/Module/ClassLoaderTest.php
@@ -19,6 +19,11 @@ class ClassLoaderTest extends BrowserTestBase {
protected $expected = 'Drupal\\module_autoload_test\\SomeClass::testMethod() was invoked.';
/**
+ * {@inheritdoc}
+ */
+ protected $apcuEnsureUniquePrefix = TRUE;
+
+ /**
* Tests that module-provided classes can be loaded when a module is enabled.
*
* @see \Drupal\module_autoload_test\SomeClass
diff --git a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php
index 5e4f1d0..f72e4ce 100644
--- a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php
+++ b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php
@@ -117,7 +117,7 @@ class SettingsTest extends UnitTestCase {
* @covers ::getApcuPrefix
*/
public function testGetApcuPrefix() {
- $settings = new Settings(['hash_salt' => 123]);
+ $settings = new Settings(['hash_salt' => 123, 'apcu_ensure_unique_prefix' => TRUE]);
$this->assertNotEquals($settings::getApcuPrefix('cache_test', '/test/a'), $settings::getApcuPrefix('cache_test', '/test/b'));
$settings = new Settings(['hash_salt' => 123, 'apcu_ensure_unique_prefix' => FALSE]);