Skip to content

Commit

Permalink
Merge branch '2.3-develop' of github.com:magento/magento2ce into MAGE…
Browse files Browse the repository at this point in the history
…TWO-93184
  • Loading branch information
slopukhov committed Jul 17, 2018
2 parents 267ae5b + 34da3bd commit bd21cc0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
4 changes: 3 additions & 1 deletion app/code/Magento/MessageQueue/Model/Cron/ConsumersRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ private function canBeRun($consumerName, array $allowedConsumers = [])
*/
private function getPidFilePath($consumerName)
{
return $consumerName . static::PID_FILE_EXT;
$sanitizedHostname = preg_replace('/[^a-z0-9]/i', '', gethostname());

return $consumerName . '-' . $sanitizedHostname . static::PID_FILE_EXT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class ConsumersRunnerTest extends \PHPUnit\Framework\TestCase
*/
protected function setUp()
{
require_once __DIR__ . '/../../_files/consumers_runner_functions_mocks.php';

$this->phpExecutableFinderMock = $this->getMockBuilder(phpExecutableFinder::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -116,7 +118,7 @@ public function testRun(
$isRunExpects
) {
$consumerName = 'consumerName';
$pidFilePath = 'consumerName.pid';
$pidFilePath = 'consumerName-myHostName.pid';

$this->deploymentConfigMock->expects($this->exactly(3))
->method('get')
Expand Down Expand Up @@ -164,7 +166,7 @@ public function runDataProvider()
'isRun' => false,
'php' => '',
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=20000'],
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=20000'],
'allowedConsumers' => [],
'shellBackgroundExpects' => 1,
'isRunExpects' => 1,
Expand All @@ -174,7 +176,7 @@ public function runDataProvider()
'isRun' => false,
'php' => '',
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
'allowedConsumers' => [],
'shellBackgroundExpects' => 1,
'isRunExpects' => 1,
Expand All @@ -184,7 +186,7 @@ public function runDataProvider()
'isRun' => false,
'php' => '',
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
'allowedConsumers' => ['someConsumer'],
'shellBackgroundExpects' => 0,
'isRunExpects' => 0,
Expand All @@ -194,7 +196,7 @@ public function runDataProvider()
'isRun' => true,
'php' => '',
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
'allowedConsumers' => ['someConsumer'],
'shellBackgroundExpects' => 0,
'isRunExpects' => 0,
Expand All @@ -204,7 +206,7 @@ public function runDataProvider()
'isRun' => true,
'php' => '',
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
'allowedConsumers' => [],
'shellBackgroundExpects' => 0,
'isRunExpects' => 1,
Expand All @@ -214,7 +216,7 @@ public function runDataProvider()
'isRun' => true,
'php' => '',
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
'allowedConsumers' => ['consumerName'],
'shellBackgroundExpects' => 0,
'isRunExpects' => 1,
Expand All @@ -224,7 +226,7 @@ public function runDataProvider()
'isRun' => false,
'php' => '',
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
'allowedConsumers' => ['consumerName'],
'shellBackgroundExpects' => 1,
'isRunExpects' => 1,
Expand All @@ -234,7 +236,7 @@ public function runDataProvider()
'isRun' => false,
'php' => '/bin/php',
'command' => '/bin/php '. BP . '/bin/magento queue:consumers:start %s %s',
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid'],
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid'],
'allowedConsumers' => ['consumerName'],
'shellBackgroundExpects' => 1,
'isRunExpects' => 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MessageQueue\Model\Cron;

/**
* @return string
*/
function gethostname()
{
return 'myHost@Name';
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function testCheckThatPidFilesWasCreated()
public function testSpecificConsumerAndRerun()
{
$specificConsumer = 'quoteItemCleaner';
$pidFilePath = $specificConsumer . ConsumersRunner::PID_FILE_EXT;
$pidFilePath = $this->getPidFileName($specificConsumer);
$config = $this->config;
$config['cron_consumers_runner'] = ['consumers' => [$specificConsumer], 'max_messages' => 0];

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

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

if ($pid && $this->pid->isRun($pidFilePath)) {
Expand All @@ -258,4 +258,15 @@ protected function tearDown()
$this->writeConfig($this->config);
$this->appConfig->reinit();
}

/**
* @param string $consumerName The consumers name
* @return string The name to file with PID
*/
private function getPidFileName($consumerName)
{
$sanitizedHostname = preg_replace('/[^a-z0-9]/i', '', gethostname());

return $consumerName . '-' . $sanitizedHostname . ConsumersRunner::PID_FILE_EXT;
}
}

0 comments on commit bd21cc0

Please sign in to comment.