Skip to content

Commit 44f174b

Browse files
committed
MC-5926: Conflict of simultaneous write in Redis cache
- create ignore list
1 parent 2eb575b commit 44f174b

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

dev/tests/integration/framework/Magento/TestFramework/Isolation/DeploymentConfig.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ class DeploymentConfig
2828
*/
2929
private $config;
3030

31+
/**
32+
* Ignore values in the config nested array, paths are separated by single slash "/".
33+
*
34+
* Example: compiled_config is not set in default mode, and once set it can't be unset
35+
*
36+
* @var array
37+
*/
38+
private $ignoreValues = [
39+
'cache_types/compiled_config',
40+
];
41+
3142
/**
3243
* Memorizes the initial value of configuration reader and the configuration value
3344
*
@@ -57,11 +68,7 @@ public function startTestSuite()
5768
*/
5869
public function endTest(\PHPUnit\Framework\TestCase $test)
5970
{
60-
$config = $this->reader->load();
61-
// ignore compiled_config setting because is not set in default mode
62-
if (isset($config['cache_types']['compiled_config'])) {
63-
unset($config['cache_types']['compiled_config']);
64-
}
71+
$config = $this->filterIgnoredConfigValues($this->reader->load());
6572
if ($this->config != $config) {
6673
$error = "\n\nERROR: deployment configuration is corrupted. The application state is no longer valid.\n"
6774
. 'Further tests may fail.'
@@ -70,4 +77,27 @@ public function endTest(\PHPUnit\Framework\TestCase $test)
7077
$test->fail($error);
7178
}
7279
}
80+
81+
/**
82+
* Filter ignored config values which are not set by default and appear when tests would change state.
83+
*
84+
* Example: compiled_config is not set in default mode, and once set it can't be unset
85+
*
86+
* @param array $config
87+
* @param string $path
88+
* @return array
89+
*/
90+
private function filterIgnoredConfigValues(array $config, string $path = '') {
91+
foreach ($config as $configKeyName => $configValue) {
92+
$newPath = !empty($path) ? $path . '/' . $configKeyName : $configKeyName;
93+
if (is_array($configValue)) {
94+
$config[$configKeyName] = $this->filterIgnoredConfigValues($configValue, $newPath);
95+
} else {
96+
if (array_key_exists($newPath, array_flip($this->ignoreValues))) {
97+
unset($config[$configKeyName]);
98+
}
99+
}
100+
}
101+
return $config;
102+
}
73103
}

0 commit comments

Comments
 (0)