Skip to content

Commit a9d376d

Browse files
author
Matthew O'Loughlin
committed
GH-26255: Add test coverage for multi-request purge tag splitting.
1 parent fc2ce73 commit a9d376d

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

app/code/Magento/CacheInvalidate/Model/PurgeCache.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
/**
1111
* Class PurgeCache
12-
* @package Magento\CacheInvalidate\Model
1312
*/
1413
class PurgeCache
1514
{
@@ -54,7 +53,7 @@ public function __construct(
5453
\Magento\PageCache\Model\Cache\Server $cacheServer,
5554
\Magento\CacheInvalidate\Model\SocketFactory $socketAdapterFactory,
5655
InvalidateLogger $logger,
57-
$maxHeaderSize = 7680
56+
int $maxHeaderSize = 7680
5857
) {
5958
$this->cacheServer = $cacheServer;
6059
$this->socketAdapterFactory = $socketAdapterFactory;

app/code/Magento/CacheInvalidate/Test/Unit/Model/PurgeCacheTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protected function setUp()
4242
'cacheServer' => $this->cacheServer,
4343
'socketAdapterFactory' => $socketFactoryMock,
4444
'logger' => $this->loggerMock,
45+
'maxHeaderSize' => 256
4546
]
4647
);
4748
}
@@ -85,6 +86,49 @@ public function testSendPurgeRequest($hosts)
8586
$this->assertTrue($this->model->sendPurgeRequest(['tags']));
8687
}
8788

89+
public function testSendMultiPurgeRequest()
90+
{
91+
$tags = [
92+
'(^|,)cat_p_95(,|$)', '(^|,)cat_p_96(,|$)', '(^|,)cat_p_97(,|$)', '(^|,)cat_p_98(,|$)',
93+
'(^|,)cat_p_99(,|$)', '(^|,)cat_p_100(,|$)', '(^|,)cat_p_10038(,|$)', '(^|,)cat_p_142985(,|$)',
94+
'(^|,)cat_p_199(,|$)', '(^|,)cat_p_300(,|$)', '(^|,)cat_p_12038(,|$)', '(^|,)cat_p_152985(,|$)',
95+
'(^|,)cat_p_299(,|$)', '(^|,)cat_p_400(,|$)', '(^|,)cat_p_13038(,|$)', '(^|,)cat_p_162985(,|$)',
96+
];
97+
98+
$tagsSplitA = array_slice($tags, 0, 12);
99+
$tagsSplitB = array_slice($tags, 12, 4);
100+
101+
$uri = UriFactory::factory('')->setHost('localhost')
102+
->setPort(80)
103+
->setScheme('http');
104+
105+
$this->cacheServer->expects($this->once())
106+
->method('getUris')
107+
->willReturn([$uri]);
108+
109+
$this->socketAdapterMock->expects($this->exactly(2))
110+
->method('connect')
111+
->with($uri->getHost(), $uri->getPort());
112+
113+
$this->socketAdapterMock->expects($this->exactly(2))
114+
->method('write')
115+
->withConsecutive(
116+
[
117+
'PURGE', $uri, '1.1',
118+
['X-Magento-Tags-Pattern' => implode('|', $tagsSplitA), 'Host' => $uri->getHost()]
119+
],
120+
[
121+
'PURGE', $uri, '1.1',
122+
['X-Magento-Tags-Pattern' => implode('|', $tagsSplitB), 'Host' => $uri->getHost()]
123+
]
124+
);
125+
126+
$this->socketAdapterMock->expects($this->exactly(2))
127+
->method('close');
128+
129+
$this->assertTrue($this->model->sendPurgeRequest($tags));
130+
}
131+
88132
/**
89133
* @return array
90134
*/

0 commit comments

Comments
 (0)