Skip to content

Commit bd21cc0

Browse files
committed
Merge branch '2.3-develop' of github.com:magento/magento2ce into MAGETWO-93184
2 parents 267ae5b + 34da3bd commit bd21cc0

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

app/code/Magento/MessageQueue/Model/Cron/ConsumersRunner.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ private function canBeRun($consumerName, array $allowedConsumers = [])
139139
*/
140140
private function getPidFilePath($consumerName)
141141
{
142-
return $consumerName . static::PID_FILE_EXT;
142+
$sanitizedHostname = preg_replace('/[^a-z0-9]/i', '', gethostname());
143+
144+
return $consumerName . '-' . $sanitizedHostname . static::PID_FILE_EXT;
143145
}
144146
}

app/code/Magento/MessageQueue/Test/Unit/Model/Cron/ConsumersRunnerTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class ConsumersRunnerTest extends \PHPUnit\Framework\TestCase
5151
*/
5252
protected function setUp()
5353
{
54+
require_once __DIR__ . '/../../_files/consumers_runner_functions_mocks.php';
55+
5456
$this->phpExecutableFinderMock = $this->getMockBuilder(phpExecutableFinder::class)
5557
->disableOriginalConstructor()
5658
->getMock();
@@ -116,7 +118,7 @@ public function testRun(
116118
$isRunExpects
117119
) {
118120
$consumerName = 'consumerName';
119-
$pidFilePath = 'consumerName.pid';
121+
$pidFilePath = 'consumerName-myHostName.pid';
120122

121123
$this->deploymentConfigMock->expects($this->exactly(3))
122124
->method('get')
@@ -164,7 +166,7 @@ public function runDataProvider()
164166
'isRun' => false,
165167
'php' => '',
166168
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
167-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=20000'],
169+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=20000'],
168170
'allowedConsumers' => [],
169171
'shellBackgroundExpects' => 1,
170172
'isRunExpects' => 1,
@@ -174,7 +176,7 @@ public function runDataProvider()
174176
'isRun' => false,
175177
'php' => '',
176178
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
177-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
179+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
178180
'allowedConsumers' => [],
179181
'shellBackgroundExpects' => 1,
180182
'isRunExpects' => 1,
@@ -184,7 +186,7 @@ public function runDataProvider()
184186
'isRun' => false,
185187
'php' => '',
186188
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
187-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
189+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
188190
'allowedConsumers' => ['someConsumer'],
189191
'shellBackgroundExpects' => 0,
190192
'isRunExpects' => 0,
@@ -194,7 +196,7 @@ public function runDataProvider()
194196
'isRun' => true,
195197
'php' => '',
196198
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
197-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
199+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
198200
'allowedConsumers' => ['someConsumer'],
199201
'shellBackgroundExpects' => 0,
200202
'isRunExpects' => 0,
@@ -204,7 +206,7 @@ public function runDataProvider()
204206
'isRun' => true,
205207
'php' => '',
206208
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
207-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
209+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
208210
'allowedConsumers' => [],
209211
'shellBackgroundExpects' => 0,
210212
'isRunExpects' => 1,
@@ -214,7 +216,7 @@ public function runDataProvider()
214216
'isRun' => true,
215217
'php' => '',
216218
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
217-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
219+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
218220
'allowedConsumers' => ['consumerName'],
219221
'shellBackgroundExpects' => 0,
220222
'isRunExpects' => 1,
@@ -224,7 +226,7 @@ public function runDataProvider()
224226
'isRun' => false,
225227
'php' => '',
226228
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
227-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
229+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
228230
'allowedConsumers' => ['consumerName'],
229231
'shellBackgroundExpects' => 1,
230232
'isRunExpects' => 1,
@@ -234,7 +236,7 @@ public function runDataProvider()
234236
'isRun' => false,
235237
'php' => '/bin/php',
236238
'command' => '/bin/php '. BP . '/bin/magento queue:consumers:start %s %s',
237-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid'],
239+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid'],
238240
'allowedConsumers' => ['consumerName'],
239241
'shellBackgroundExpects' => 1,
240242
'isRunExpects' => 1,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MessageQueue\Model\Cron;
9+
10+
/**
11+
* @return string
12+
*/
13+
function gethostname()
14+
{
15+
return 'myHost@Name';
16+
}

dev/tests/integration/testsuite/Magento/MessageQueue/Model/Cron/ConsumersRunnerTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function testCheckThatPidFilesWasCreated()
130130
public function testSpecificConsumerAndRerun()
131131
{
132132
$specificConsumer = 'quoteItemCleaner';
133-
$pidFilePath = $specificConsumer . ConsumersRunner::PID_FILE_EXT;
133+
$pidFilePath = $this->getPidFileName($specificConsumer);
134134
$config = $this->config;
135135
$config['cron_consumers_runner'] = ['consumers' => [$specificConsumer], 'max_messages' => 0];
136136

@@ -228,7 +228,7 @@ private function writeConfig(array $config)
228228
private function getPidFileFullPath($consumerName)
229229
{
230230
$directoryList = $this->objectManager->get(DirectoryList::class);
231-
return $directoryList->getPath(DirectoryList::VAR_DIR) . '/' . $consumerName . ConsumersRunner::PID_FILE_EXT;
231+
return $directoryList->getPath(DirectoryList::VAR_DIR) . '/' . $this->getPidFileName($consumerName);
232232
}
233233

234234
/**
@@ -239,7 +239,7 @@ protected function tearDown()
239239
foreach ($this->consumerConfig->getConsumers() as $consumer) {
240240
$consumerName = $consumer->getName();
241241
$pidFileFullPath = $this->getPidFileFullPath($consumerName);
242-
$pidFilePath = $consumerName . ConsumersRunner::PID_FILE_EXT;
242+
$pidFilePath = $this->getPidFileName($consumerName);
243243
$pid = $this->pid->getPid($pidFilePath);
244244

245245
if ($pid && $this->pid->isRun($pidFilePath)) {
@@ -258,4 +258,15 @@ protected function tearDown()
258258
$this->writeConfig($this->config);
259259
$this->appConfig->reinit();
260260
}
261+
262+
/**
263+
* @param string $consumerName The consumers name
264+
* @return string The name to file with PID
265+
*/
266+
private function getPidFileName($consumerName)
267+
{
268+
$sanitizedHostname = preg_replace('/[^a-z0-9]/i', '', gethostname());
269+
270+
return $consumerName . '-' . $sanitizedHostname . ConsumersRunner::PID_FILE_EXT;
271+
}
261272
}

0 commit comments

Comments
 (0)