Unverified Commit 9d552cad authored by larowlan's avatar larowlan

Issue #2926309 by vaplas, alexpott, mpdonadio, tacituseu, Mixologic: Random...

Issue #2926309 by vaplas, alexpott, mpdonadio, tacituseu, Mixologic: Random fail due to APCu not being able to allocate memory
parent cf805af2
......@@ -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)) {
......
......@@ -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';
......
......@@ -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.
*
......
......@@ -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]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment