diff --git a/core/lib/Drupal/Core/Site/Settings.php b/core/lib/Drupal/Core/Site/Settings.php index a1a6c38893ea8fe5c677263b1b51dfa79bd59e94..bdd2609a7c020b8fc387e6bc15c01aadaeedbbba 100644 --- a/core/lib/Drupal/Core/Site/Settings.php +++ b/core/lib/Drupal/Core/Site/Settings.php @@ -156,8 +156,8 @@ public static function getHashSalt() { * 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 @@ public static function getHashSalt() { * * @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 f9f97ecaa8c3e9543afc5f2cf0468ba217028bc9..3165815b175575060528ab9a94a4e6f222743c6c 100644 --- a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php +++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php @@ -41,6 +41,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. */ @@ -83,6 +95,10 @@ protected function prepareSettings() { '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 93c0bf3f422a44f6c293a6652e2c40e406b971c3..335a03a329b0f3d22064a24e71cedf22d95f4514 100644 --- a/core/modules/system/tests/src/Functional/Module/ClassLoaderTest.php +++ b/core/modules/system/tests/src/Functional/Module/ClassLoaderTest.php @@ -18,6 +18,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. * diff --git a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php index 5e4f1d084c15f683d42225e5b37122c8e4b6ff5e..f72e4ce9f0e7c5b514d82a0410b6c5b82fdf65ca 100644 --- a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php +++ b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php @@ -117,7 +117,7 @@ public function testSerialize() { * @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]);