Skip to content

Commit 8bcac2c

Browse files
committed
B2B-2530: Unskip GraphQL cache tests skipped due to DEVOPS-4924
- Addressed comments on CacheId
1 parent 5d45686 commit 8bcac2c

File tree

2 files changed

+65
-26
lines changed

2 files changed

+65
-26
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/PageCache/CacheTagTest.php

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,31 @@ public function testCacheInvalidationForCategoriesWithProduct()
8484

8585
// cache-debug header value should be a MISS when category is loaded first time
8686
$responseMissOnCategoryQuery = $this->graphQlQueryWithResponseHeaders($categoryQuery);
87-
$cacheId = $responseMissOnCategoryQuery['headers'][CacheIdCalculator::CACHE_ID_HEADER];
87+
$cacheIdOfCategoryQuery = $responseMissOnCategoryQuery['headers'][CacheIdCalculator::CACHE_ID_HEADER];
8888
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
89-
$this->assertCacheMissAndReturnResponse($categoryQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
89+
$this->assertCacheMissAndReturnResponse(
90+
$categoryQuery,
91+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdOfCategoryQuery]
92+
);
9093

9194
// Cache-debug header should be a MISS for product 1 on first request
9295
$responseFirstProduct = $this->graphQlQueryWithResponseHeaders($product1Query);
9396
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $responseFirstProduct['headers']);
94-
$cacheId = $responseFirstProduct['headers'][CacheIdCalculator::CACHE_ID_HEADER];
97+
$cacheIdOfFirstProduct = $responseFirstProduct['headers'][CacheIdCalculator::CACHE_ID_HEADER];
9598
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
96-
$this->assertCacheMissAndReturnResponse($product1Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
99+
$this->assertCacheMissAndReturnResponse(
100+
$product1Query,
101+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdOfFirstProduct]
102+
);
97103

98104
// Cache-debug header should be a MISS for product 2 during first load
99105
$responseMissSecondProduct = $this->graphQlQueryWithResponseHeaders($product2Query);
100-
$cacheId = $responseMissSecondProduct['headers'][CacheIdCalculator::CACHE_ID_HEADER];
106+
$cacheIdOfSecondProduct = $responseMissSecondProduct['headers'][CacheIdCalculator::CACHE_ID_HEADER];
101107
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
102-
$this->assertCacheMissAndReturnResponse($product2Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
108+
$this->assertCacheMissAndReturnResponse(
109+
$product2Query,
110+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdOfSecondProduct]
111+
);
103112

104113
$firstProduct->setPrice(20);
105114
$productRepository->save($firstProduct);
@@ -110,21 +119,33 @@ public function testCacheInvalidationForCategoriesWithProduct()
110119
CacheIdCalculator::CACHE_ID_HEADER,
111120
$responseMissCategoryAfterProductUpdate['headers']
112121
);
113-
$cacheId = $responseMissCategoryAfterProductUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
122+
$cacheIdOfCategoryAfterProductUpdate =
123+
$responseMissCategoryAfterProductUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
114124
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
115-
$this->assertCacheMissAndReturnResponse($categoryQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
125+
$this->assertCacheMissAndReturnResponse(
126+
$categoryQuery,
127+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdOfCategoryAfterProductUpdate]
128+
);
116129

117130
// cache-debug should be a MISS for product 1 after it is updated - cache invalidation
118131
$responseMissFirstProductAfterProductUpdate = $this->graphQlQueryWithResponseHeaders($product1Query);
119-
$cacheId = $responseMissFirstProductAfterProductUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
132+
$cacheIdOfFirstProductAfterProductUpdate =
133+
$responseMissFirstProductAfterProductUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
120134
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
121-
$this->assertCacheMissAndReturnResponse($product1Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
135+
$this->assertCacheMissAndReturnResponse(
136+
$product1Query,
137+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdOfFirstProductAfterProductUpdate]
138+
);
122139

123140
// Cache-debug header responses for product 2 and should be a HIT for product 2
124141
$responseHitSecondProduct = $this->graphQlQueryWithResponseHeaders($product2Query);
125-
$cacheId = $responseHitSecondProduct['headers'][CacheIdCalculator::CACHE_ID_HEADER];
142+
$cacheIdOfSecondProductOnHit =
143+
$responseHitSecondProduct['headers'][CacheIdCalculator::CACHE_ID_HEADER];
126144
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
127-
$this->assertCacheHitAndReturnResponse($product2Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
145+
$this->assertCacheHitAndReturnResponse(
146+
$product2Query,
147+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdOfSecondProductOnHit]
148+
);
128149
}
129150

130151
/**

dev/tests/api-functional/testsuite/Magento/GraphQl/PageCache/UrlRewrite/UrlResolverCacheTest.php

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class UrlResolverCacheTest extends GraphQLPageCacheAbstract
2020
{
2121
/**
22-
* Tests cache invalidation for product urlResolver
22+
* Tests cache works properly for product urlResolver
2323
*
2424
* @magentoConfigFixture default/system/full_page_cache/caching_application 2
2525
* @magentoApiDataFixture Magento/CatalogUrlRewrite/_files/product_with_category.php
@@ -32,13 +32,16 @@ public function testUrlResolverCachingForProducts()
3232
// Obtain the X-Magento-Cache-Id from the response which will be used as the cache key
3333
$response = $this->graphQlQueryWithResponseHeaders($urlResolverQuery);
3434
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
35-
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
35+
$cacheIdForProducts = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
3636
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
37-
$this->assertCacheMissAndReturnResponse($urlResolverQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
37+
$this->assertCacheMissAndReturnResponse(
38+
$urlResolverQuery,
39+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdForProducts]
40+
);
3841
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
3942
$cachedResponse = $this->assertCacheHitAndReturnResponse(
4043
$urlResolverQuery,
41-
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
44+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdForProducts]
4245
);
4346

4447
//cached data should be correct
@@ -60,13 +63,16 @@ public function testUrlResolverCachingForCategory()
6063

6164
$response = $this->graphQlQueryWithResponseHeaders($query);
6265
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
63-
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
66+
$cacheIdForCategory = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
6467
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
65-
$this->assertCacheMissAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
68+
$this->assertCacheMissAndReturnResponse(
69+
$query,
70+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdForCategory]
71+
);
6672
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
6773
$cachedResponse = $this->assertCacheHitAndReturnResponse(
6874
$query,
69-
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
75+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdForCategory]
7076
);
7177

7278
//verify cached data is correct
@@ -91,13 +97,16 @@ public function testUrlResolverCachingForCMSPage()
9197
$query = $this->getUrlResolverQuery($requestPath);
9298
$response = $this->graphQlQueryWithResponseHeaders($query);
9399
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
94-
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
100+
$cacheIdForCmsPage = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
95101
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
96-
$this->assertCacheMissAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
102+
$this->assertCacheMissAndReturnResponse(
103+
$query,
104+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdForCmsPage]
105+
);
97106
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
98107
$cachedResponse = $this->assertCacheHitAndReturnResponse(
99108
$query,
100-
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
109+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdForCmsPage]
101110
);
102111

103112
//verify cached data is correct
@@ -122,11 +131,17 @@ public function testCacheIsInvalidatedForUrlResolver()
122131
// Obtain the X-Magento-Cache-Id from the response which will be used as the cache key
123132
$response = $this->graphQlQueryWithResponseHeaders($urlResolverQuery);
124133
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
125-
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
134+
$cacheIdForUrlResolver = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
126135
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
127-
$this->assertCacheMissAndReturnResponse($urlResolverQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
136+
$this->assertCacheMissAndReturnResponse(
137+
$urlResolverQuery,
138+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdForUrlResolver]
139+
);
128140
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
129-
$this->assertCacheHitAndReturnResponse($urlResolverQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
141+
$this->assertCacheHitAndReturnResponse(
142+
$urlResolverQuery,
143+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdForUrlResolver]
144+
);
130145

131146
/** @var ProductRepositoryInterface $productRepository */
132147
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
@@ -135,7 +150,10 @@ public function testCacheIsInvalidatedForUrlResolver()
135150
$product->setUrlKey('p002-new.html')->save();
136151

137152
// Verify we obtain a cache MISS the third time after product url key is updated
138-
$this->assertCacheMissAndReturnResponse($urlResolverQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
153+
$this->assertCacheMissAndReturnResponse(
154+
$urlResolverQuery,
155+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheIdForUrlResolver]
156+
);
139157
}
140158

141159
/**

0 commit comments

Comments
 (0)