Skip to content

Commit 0e023c1

Browse files
committed
MC-33275: Stale cache implementation
1 parent 7cbcb84 commit 0e023c1

File tree

7 files changed

+17
-998
lines changed

7 files changed

+17
-998
lines changed

dev/tests/integration/framework/Magento/TestFramework/Application.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,19 @@ public function initialize($overriddenParams = [])
389389
);
390390
}
391391
$objectManager->configure($objectManagerConfiguration);
392-
392+
/** Register event observer of Integration Framework */
393+
/** @var \Magento\Framework\Event\Config\Data $eventConfigData */
394+
$eventConfigData = $objectManager->get(\Magento\Framework\Event\Config\Data::class);
395+
$eventConfigData->merge(
396+
[
397+
'core_app_init_current_store_after' => [
398+
'integration_tests' => [
399+
'instance' => \Magento\TestFramework\Event\Magento::class,
400+
'name' => 'integration_tests'
401+
]
402+
]
403+
]
404+
);
393405
if ($this->canLoadArea) {
394406
$this->loadArea(\Magento\TestFramework\Application::DEFAULT_APP_AREA);
395407
}

dev/tests/integration/testsuite/Magento/Config/App/Config/Type/SystemTest.php

Lines changed: 2 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@
55
*/
66
namespace Magento\Config\App\Config\Type;
77

8-
use Magento\Config\Model\Config\Factory;
9-
use Magento\Framework\Lock\Backend\Cache;
10-
use Magento\Framework\App\Cache\Type\Config;
11-
use Magento\Framework\Cache\FrontendInterface;
12-
use Magento\Framework\Lock\LockManagerInterface;
138
use Magento\Framework\ObjectManagerInterface;
14-
use Magento\Store\Model\ScopeInterface;
159
use Magento\TestFramework\Helper\Bootstrap;
1610

1711
/**
1812
* @magentoDataFixture Magento/Config/_files/config_data.php
1913
* @magentoAppIsolation enabled
20-
* @magentoCache config enabled
2114
*/
2215
class SystemTest extends \PHPUnit\Framework\TestCase
2316
{
@@ -34,145 +27,24 @@ class SystemTest extends \PHPUnit\Framework\TestCase
3427
protected function setUp(): void
3528
{
3629
$this->objectManager = Bootstrap::getObjectManager();
37-
$this->system = $this->createSystemConfig();
30+
$this->system = $this->objectManager->create(System::class);
3831
}
3932

40-
public function testGetValueForDefaultScope()
33+
public function testGetValueDefaultScope()
4134
{
4235
$this->assertEquals(
4336
'value1.db.default.test',
4437
$this->system->get('default/web/test/test_value_1')
4538
);
46-
}
4739

48-
public function testGetValueForWebsiteScope()
49-
{
5040
$this->assertEquals(
5141
'value1.db.website_base.test',
5242
$this->system->get('websites/base/web/test/test_value_1')
5343
);
54-
}
5544

56-
public function testGetValueForStoreScope()
57-
{
5845
$this->assertEquals(
5946
'value1.db.store_default.test',
6047
$this->system->get('stores/default/web/test/test_value_1')
6148
);
6249
}
63-
64-
public function testCachingDoesNotBreakValueRetrievalForStoreScope()
65-
{
66-
// First uncached call to configuration
67-
$this->createSystemConfig()->get('stores/default/web/test/test_value_1');
68-
69-
// Second call after cache data is stored
70-
$this->assertEquals(
71-
'value1.db.store_default.test',
72-
$this->createSystemConfig()->get('stores/default/web/test/test_value_1')
73-
);
74-
}
75-
76-
public function testCachingDoesNotBreakValueRetrievalForWebsiteScope()
77-
{
78-
// First uncached call to configuration
79-
$this->createSystemConfig()->get('websites/base/web/test/test_value_1');
80-
81-
// Second call after cache data is stored
82-
$this->assertEquals(
83-
'value1.db.website_base.test',
84-
$this->createSystemConfig()->get('websites/base/web/test/test_value_1')
85-
);
86-
}
87-
88-
public function testCachingDoesNotBreakValueRetrievalForDefaultScope()
89-
{
90-
// First uncached call to configuration
91-
$this->createSystemConfig()->get('default/web/test/test_value_1');
92-
93-
// Second call after cache data is stored
94-
$this->assertEquals(
95-
'value1.db.default.test',
96-
$this->createSystemConfig()->get('default/web/test/test_value_1')
97-
);
98-
}
99-
100-
public function testClearingCachePrefixAndLockingItReturnsStaleCachedValue()
101-
{
102-
// First uncached call to configuration
103-
$this->createSystemConfig()->get('default/web/test/test_value_1');
104-
105-
$this->clearConfigCachePrefix();
106-
$this->accessLock()->lock('SYSTEM_CONFIG');
107-
// Second call after cache data is stored
108-
$configValue = $this->createSystemConfig()->get('default/web/test/test_value_1');
109-
$this->accessLock()->unlock('SYSTEM_CONFIG');
110-
111-
$this->assertEquals(
112-
'value1.db.default.test',
113-
$configValue
114-
);
115-
}
116-
117-
public function testClearingConfigurationCacheAndLockingFallsBackToStaleCache()
118-
{
119-
// First uncached call to configuration
120-
$this->createSystemConfig()->get('stores/default/web/test/test_value_1');
121-
122-
$this->accessCacheFrontend()->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [System::CACHE_TAG]);
123-
124-
$this->accessLock()->lock('SYSTEM_CONFIG');
125-
// Second call after cache data is stored
126-
$configValue = $this->createSystemConfig()->get('stores/default/web/test/test_value_1');
127-
$this->accessLock()->unlock('SYSTEM_CONFIG');
128-
129-
$this->assertEquals(
130-
'value1.db.store_default.test',
131-
$configValue
132-
);
133-
}
134-
135-
public function testChangingConfigurationValueRefreshesACache()
136-
{
137-
$systemConfig = $this->objectManager->get(System::class);
138-
139-
// First uncached call to configuration
140-
$systemConfig->get('stores/default/web/test/test_value_1');
141-
142-
/** @var Factory $configFactory */
143-
$configFactory = $this->objectManager->create(Factory::class);
144-
$config = $configFactory->create();
145-
$config->setScope(ScopeInterface::SCOPE_STORES);
146-
$config->setStore('default');
147-
148-
$config->setDataByPath('web/test/test_value_1', 'new_uncached_value');
149-
$config->save();
150-
151-
$this->assertEquals(
152-
'new_uncached_value',
153-
$systemConfig->get('stores/default/web/test/test_value_1')
154-
);
155-
}
156-
157-
private function clearConfigCachePrefix()
158-
{
159-
$cache = $this->accessCacheFrontend();
160-
161-
$cache->remove(System::STALE_CACHE_KEY_FOR_PREFIX);
162-
}
163-
164-
private function accessCacheFrontend(): FrontendInterface
165-
{
166-
return $this->objectManager->get(Config::class);
167-
}
168-
169-
private function createSystemConfig(): System
170-
{
171-
return $this->objectManager->create(System::class);
172-
}
173-
174-
private function accessLock(): LockManagerInterface
175-
{
176-
return $this->objectManager->get(Cache::class);
177-
}
17850
}

0 commit comments

Comments
 (0)