Skip to content

Commit ab0257a

Browse files
committed
B2B-2530: Unskip GraphQL cache tests skipped due to DEVOPS-4924
- Fixed the caching order and other naming on tests
1 parent 28de998 commit ab0257a

File tree

5 files changed

+49
-41
lines changed

5 files changed

+49
-41
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testCacheInvalidationForProducts()
3939
}
4040
}
4141
QUERY;
42-
// Cache-debug should be a MISS when product is queried for first time
42+
// Cache should be a MISS when product is queried for first time
4343
// Obtain the X-Magento-Cache-Id from the response which will be used as the cache key
4444
$response = $this->graphQlQueryWithResponseHeaders($query);
4545
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
@@ -59,7 +59,7 @@ public function testCacheInvalidationForProducts()
5959
$responseAfterUpdate = $this->graphQlQueryWithResponseHeaders($query);
6060
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $responseAfterUpdate['headers']);
6161
$cacheId = $responseAfterUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
62-
// Cache invalidation happens and cache-debug header value is a MISS after product update
62+
// Cache invalidation happens and cache header value is a MISS after product update
6363
$this->assertCacheMissAndReturnResponse($query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
6464
}
6565

@@ -95,30 +95,32 @@ public function testCacheInvalidationForCategoriesWithProduct()
9595
$cacheId = $responseFirstProduct['headers'][CacheIdCalculator::CACHE_ID_HEADER];
9696
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
9797
$this->assertCacheMissAndReturnResponse($product1Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
98-
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
99-
$this->assertCacheHitAndReturnResponse($product1Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
98+
99+
// Cache-debug header should be a MISS for product 2 during first load
100+
$responseMissSecondProduct = $this->graphQlQueryWithResponseHeaders($product2Query);
101+
$cacheId = $responseMissSecondProduct['headers'][CacheIdCalculator::CACHE_ID_HEADER];
102+
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
103+
$this->assertCacheMissAndReturnResponse($product2Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
100104

101105
$firstProduct->setPrice(20);
102106
$productRepository->save($firstProduct);
103107

104108
// cache-debug header value should be MISS after updating product1 and reloading the Category
105-
$responseMissCategoryAfterUpdate = $this->graphQlQueryWithResponseHeaders($categoryQuery);
106-
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $responseMissCategoryAfterUpdate['headers']);
107-
$cacheId = $responseMissCategoryAfterUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
109+
$responseMissCategoryAfterProductUpdate = $this->graphQlQueryWithResponseHeaders($categoryQuery);
110+
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $responseMissCategoryAfterProductUpdate['headers']);
111+
$cacheId = $responseMissCategoryAfterProductUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
108112
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
109113
$this->assertCacheMissAndReturnResponse($categoryQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
110114

111115
// cache-debug should be a MISS for product 1 after it is updated - cache invalidation
112-
$responseMissFirstProductAfterUpdate = $this->graphQlQueryWithResponseHeaders($product1Query);
113-
$cacheId = $responseMissFirstProductAfterUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
116+
$responseMissFirstProductAfterProductUpdate = $this->graphQlQueryWithResponseHeaders($product1Query);
117+
$cacheId = $responseMissFirstProductAfterProductUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
114118
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
115119
$this->assertCacheMissAndReturnResponse($product1Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
116120

117-
// Cache-debug header responses for product 2
121+
// Cache-debug header responses for product 2 and should be a HIT for product 2
118122
$responseHitSecondProduct = $this->graphQlQueryWithResponseHeaders($product2Query);
119123
$cacheId = $responseHitSecondProduct['headers'][CacheIdCalculator::CACHE_ID_HEADER];
120-
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
121-
$this->assertCacheMissAndReturnResponse($product2Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
122124
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
123125
$this->assertCacheHitAndReturnResponse($product2Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
124126
}
@@ -156,7 +158,6 @@ private function getCategoryQuery(): string
156158
$categoryId = 4;
157159
$pageSize = 10;
158160
$currentPage = 1;
159-
160161
$categoryQueryString = <<<QUERY
161162
query {
162163
category(id: $categoryId) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,16 @@ public function testCacheIsInvalidatedOnBlockUpdate()
6969
$cacheId = $fixtureBlock['headers'][CacheIdCalculator::CACHE_ID_HEADER];
7070
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
7171
$this->assertCacheMissAndReturnResponse($fixtureBlockQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
72-
// Verify we obtain a cache HIT the second time we search the cache using this X-Magento-Cache-Id
73-
$this->assertCacheHitAndReturnResponse($fixtureBlockQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
7472

7573
$enabledBlock = $this->graphQlQueryWithResponseHeaders($enabledBlockQuery);
7674
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $enabledBlock['headers']);
7775
$cacheId = $enabledBlock['headers'][CacheIdCalculator::CACHE_ID_HEADER];
7876
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
7977
$this->assertCacheMissAndReturnResponse($enabledBlockQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
78+
79+
//cache should be a HIT on second request
80+
// Verify we obtain a cache HIT the second time we search the cache using this X-Magento-Cache-Id
81+
$this->assertCacheHitAndReturnResponse($fixtureBlockQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
8082
// Verify we obtain a cache HIT the second time we search the cache using this X-Magento-Cache-Id
8183
$this->assertCacheHitAndReturnResponse($enabledBlockQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
8284

@@ -97,7 +99,7 @@ public function testCacheIsInvalidatedOnBlockUpdate()
9799
// Verify we obtain a cache HIT the second time we search the cache using this X-Magento-Cache-Id
98100
$this->assertCacheHitAndReturnResponse($enabledBlockQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
99101

100-
//updated block data should be correct
102+
//updated block data should be correct on fixture block
101103
$this->assertNotEmpty($fixtureBlockAfterUpdate['body']);
102104
$blocks = $fixtureBlockAfterUpdate['body']['cmsBlocks']['items'];
103105
$this->assertArrayNotHasKey('errors', $fixtureBlockAfterUpdate['body']);

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,15 @@ public function testCacheIsInvalidatedOnPageUpdate()
8888
$cacheId = $page100Response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
8989
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
9090
$this->assertCacheMissAndReturnResponse($page100Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
91-
//cache-debug should be a HIT on second request
92-
$this->assertCacheHitAndReturnResponse($page100Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
9391

9492
$pageBlankResponse = $this->graphQlQueryWithResponseHeaders($pageBlankQuery);
9593
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $pageBlankResponse['headers']);
9694
$cacheId = $pageBlankResponse['headers'][CacheIdCalculator::CACHE_ID_HEADER];
9795
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
9896
$this->assertCacheMissAndReturnResponse($pageBlankQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
97+
98+
//cache-debug should be a HIT on second request
99+
$this->assertCacheHitAndReturnResponse($page100Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
99100
//cache-debug should be a HIT on second request
100101
$this->assertCacheHitAndReturnResponse($pageBlankQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
101102

@@ -105,21 +106,21 @@ public function testCacheIsInvalidatedOnPageUpdate()
105106
$pageRepository->save($pageBlank);
106107

107108
//cache-debug should be a MISS after updating the page
108-
$pageBlankResponseAfterUpdate = $this->graphQlQueryWithResponseHeaders($pageBlankQuery);
109-
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $pageBlankResponseAfterUpdate['headers']);
110-
$cacheId = $pageBlankResponseAfterUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
109+
$pageBlankResponseMissAfterUpdate = $this->graphQlQueryWithResponseHeaders($pageBlankQuery);
110+
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $pageBlankResponseMissAfterUpdate['headers']);
111+
$cacheId = $pageBlankResponseMissAfterUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
111112
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
112113
$this->assertCacheMissAndReturnResponse($pageBlankQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
113114

114-
$page100ResponseAfterUpdate = $this->graphQlQueryWithResponseHeaders($page100Query);
115-
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $page100Response['headers']);
116-
$cacheId = $page100ResponseAfterUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
115+
$page100ResponseHitAfterUpdate = $this->graphQlQueryWithResponseHeaders($page100Query);
116+
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $page100ResponseHitAfterUpdate['headers']);
117+
$cacheId = $page100ResponseHitAfterUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
117118
$this->assertCacheHitAndReturnResponse($page100Query, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
118119

119120
//updated page data should be correct
120-
$this->assertNotEmpty($pageBlankResponseAfterUpdate['body']);
121-
$pageData = $pageBlankResponseAfterUpdate['body']['cmsPage'];
122-
$this->assertArrayNotHasKey('errors', $pageBlankResponseAfterUpdate['body']);
121+
$this->assertNotEmpty($pageBlankResponseMissAfterUpdate['body']);
122+
$pageData = $pageBlankResponseMissAfterUpdate['body']['cmsPage'];
123+
$this->assertArrayNotHasKey('errors', $pageBlankResponseMissAfterUpdate['body']);
123124
$this->assertEquals('Cms Page Design Blank', $pageData['title']);
124125
$this->assertEquals($newPageContent, $pageData['content']);
125126
}

dev/tests/api-functional/testsuite/Magento/GraphQl/PageCache/Quote/Guest/CartCacheTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ public function testCartIsNotCached()
3333
$responseMiss = $this->graphQlQueryWithResponseHeaders($getCartQuery);
3434
$this->assertArrayHasKey('cart', $responseMiss['body']);
3535
$this->assertArrayHasKey('items', $responseMiss['body']['cart']);
36-
37-
// Obtain the X-Magento-Cache-Id from the response which will be used as the cache key
38-
$response = $this->graphQlQueryWithResponseHeaders($getCartQuery);
39-
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
40-
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
36+
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $responseMiss['headers']);
37+
$cacheId = $responseMiss['headers'][CacheIdCalculator::CACHE_ID_HEADER];
4138
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
4239
$this->assertCacheMissAndReturnResponse($getCartQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
40+
41+
// Cache debug header value is still a MISS for any subsequent request
42+
// Obtain the X-Magento-Cache-Id from the response which will be used as the cache key
43+
$responseMissNext = $this->graphQlQueryWithResponseHeaders($getCartQuery);
44+
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $responseMissNext['headers']);
45+
$cacheId = $responseMissNext['headers'][CacheIdCalculator::CACHE_ID_HEADER];
4346
// Verify we obtain a cache MISS the second time we search the cache using this X-Magento-Cache-Id
4447
$this->assertCacheMissAndReturnResponse($getCartQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
4548
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@ public function testUrlResolverCachingForProducts()
3333
$response = $this->graphQlQueryWithResponseHeaders($urlResolverQuery);
3434
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
3535
$cacheId = $response['headers'][CacheIdCalculator::CACHE_ID_HEADER];
36-
3736
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
3837
$this->assertCacheMissAndReturnResponse($urlResolverQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
39-
4038
// Verify we obtain a cache HIT the second time around for this X-Magento-Cache-Id
41-
$this->assertCacheHitAndReturnResponse($urlResolverQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
39+
$cachedResponse = $this->assertCacheHitAndReturnResponse(
40+
$urlResolverQuery,
41+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
42+
);
4243

4344
//cached data should be correct
44-
$this->assertNotEmpty($response['body']);
45-
$this->assertArrayNotHasKey('errors', $response['body']);
46-
$this->assertEquals('PRODUCT', $response['body']['urlResolver']['type']);
45+
$this->assertNotEmpty($cachedResponse['body']);
46+
$this->assertArrayNotHasKey('errors', $cachedResponse['body']);
47+
$this->assertEquals('PRODUCT', $cachedResponse['body']['urlResolver']['type']);
4748
}
4849

4950
/**
@@ -134,9 +135,9 @@ public function testCacheIsInvalidatedForUrlResolver()
134135

135136
//cache-debug should be a MISS after updating the url key and accessing the same requestPath or urlKey
136137
$urlResolverQuery = $this->getUrlResolverQuery($urlKey);
137-
$responseAfterUpdate = $this->graphQlQueryWithResponseHeaders($urlResolverQuery);
138-
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $response['headers']);
139-
$cacheId = $responseAfterUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
138+
$responseMissAfterUrlUpdate = $this->graphQlQueryWithResponseHeaders($urlResolverQuery);
139+
$this->assertArrayHasKey(CacheIdCalculator::CACHE_ID_HEADER, $responseMissAfterUrlUpdate['headers']);
140+
$cacheId = $responseMissAfterUrlUpdate['headers'][CacheIdCalculator::CACHE_ID_HEADER];
140141
// Verify we obtain a cache MISS the first time we search the cache using this X-Magento-Cache-Id
141142
$this->assertCacheMissAndReturnResponse($urlResolverQuery, [CacheIdCalculator::CACHE_ID_HEADER => $cacheId]);
142143
}

0 commit comments

Comments
 (0)