Skip to content

Commit ce722d9

Browse files
committed
MC-19250: The stuck deployment on the Cloud because of consumers
1 parent 1b10981 commit ce722d9

File tree

3 files changed

+113
-4
lines changed

3 files changed

+113
-4
lines changed

app/code/Magento/MessageQueue/Setup/ConfigOptionsList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function getOptions()
4646
SelectConfigOption::FRONTEND_WIZARD_SELECT,
4747
$this->selectOptions,
4848
self::CONFIG_PATH_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES,
49-
'Should consumers wait for message from the queue? 1 - Yes, 0 - No',
49+
'Should consumers wait for a message from the queue? 1 - Yes, 0 - No',
5050
self::DEFULT_CONSUMERS_WAIT_FOR_MESSAGES
5151
),
5252
];

dev/tests/integration/testsuite/Magento/Framework/MessageQueue/UseCase/QueueTestCaseAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class QueueTestCaseAbstract extends \PHPUnit\Framework\TestCase
4545
/**
4646
* @var PublisherConsumerController
4747
*/
48-
private $publisherConsumerController;
48+
protected $publisherConsumerController;
4949

5050
protected function setUp()
5151
{

dev/tests/integration/testsuite/Magento/Framework/MessageQueue/UseCase/WaitAndNotWaitMessagesTest.php

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
namespace Magento\Framework\MessageQueue\UseCase;
77

88
use Magento\Framework\App\DeploymentConfig\FileReader;
9+
use Magento\TestModuleAsyncAmqp\Model\AsyncTestData;
10+
use Magento\Framework\App\DeploymentConfig\Writer;
911
use Magento\Framework\Config\File\ConfigFilePool;
12+
use Magento\Framework\Filesystem;
1013

1114
class WaitAndNotWaitMessagesTest extends QueueTestCaseAbstract
1215
{
@@ -15,25 +18,113 @@ class WaitAndNotWaitMessagesTest extends QueueTestCaseAbstract
1518
*/
1619
private $reader;
1720

21+
/**
22+
* @var Filesystem
23+
*/
24+
private $filesystem;
25+
26+
/**
27+
* @var ConfigFilePool
28+
*/
29+
private $configFilePool;
30+
1831
/**
1932
* @var array
2033
*/
2134
private $config;
2235

36+
/**
37+
* @var \Magento\TestModuleAsyncAmqp\Model\AsyncTestData
38+
*/
39+
protected $msgObject;
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
protected $consumers = ['mixed.sync.and.async.queue.consumer'];
45+
46+
/**
47+
* @var string[]
48+
*/
49+
protected $messages = ['message1', 'message2', 'message3'];
50+
51+
/**
52+
* @var int|null
53+
*/
54+
protected $maxMessages = 4;
55+
2356
/**
2457
* @inheritdoc
2558
*/
2659
protected function setUp()
2760
{
2861
parent::setUp();
62+
$this->msgObject = $this->objectManager->create(AsyncTestData::class);
2963
$this->reader = $this->objectManager->get(FileReader::class);
30-
64+
$this->filesystem = $this->objectManager->get(Filesystem::class);
3165
$this->config = $this->loadConfig();
3266
}
3367

34-
public function testDefaultConfiguration()
68+
/**
69+
* Check if consumers wait for messages from the queue
70+
*/
71+
public function testWaitForMessages()
3572
{
3673
$this->assertArraySubset(['queue' => ['consumers_wait_for_messages' => 1]], $this->config);
74+
75+
foreach ($this->messages as $msg) {
76+
$this->publishMessage($msg);
77+
}
78+
79+
$this->waitForAsynchronousResult(count($this->messages), $this->logFilePath);
80+
81+
foreach ($this->messages as $item) {
82+
$this->assertContains($item, file_get_contents($this->logFilePath));
83+
}
84+
85+
$this->publishMessage('message4');
86+
$this->waitForAsynchronousResult(count($this->messages) + 1, $this->logFilePath);
87+
$this->assertContains('message4', file_get_contents($this->logFilePath));
88+
}
89+
90+
/**
91+
* Check if consumers do not wait for messages from the queue and die
92+
*/
93+
public function testNotWaitForMessages(): void
94+
{
95+
$this->publisherConsumerController->stopConsumers();
96+
97+
$config = $this->config;
98+
$config['queue']['consumers_wait_for_messages'] = 0;
99+
$this->writeConfig($config);
100+
101+
$this->assertArraySubset(['queue' => ['consumers_wait_for_messages' => 0]], $this->loadConfig());
102+
foreach ($this->messages as $msg) {
103+
$this->publishMessage($msg);
104+
}
105+
106+
$this->publisherConsumerController->startConsumers();
107+
$this->waitForAsynchronousResult(count($this->messages), $this->logFilePath);
108+
109+
foreach ($this->messages as $item) {
110+
$this->assertContains($item, file_get_contents($this->logFilePath));
111+
}
112+
113+
// Checks that consumers do not wait 4th message and die
114+
$this->assertArraySubset(
115+
['mixed.sync.and.async.queue.consumer' => []],
116+
$this->publisherConsumerController->getConsumersProcessIds()
117+
);
118+
}
119+
120+
/**
121+
* @param string $msg
122+
*/
123+
private function publishMessage(string $msg): void
124+
{
125+
$this->msgObject->setValue($msg);
126+
$this->msgObject->setTextFilePath($this->logFilePath);
127+
$this->publisher->publish('multi.topic.queue.topic.c', $this->msgObject);
37128
}
38129

39130
/**
@@ -43,4 +134,22 @@ private function loadConfig(): array
43134
{
44135
return $this->reader->load(ConfigFilePool::APP_ENV);
45136
}
137+
138+
/**
139+
* @param array $config
140+
*/
141+
private function writeConfig(array $config): void
142+
{
143+
$writer = $this->objectManager->get(Writer::class);
144+
$writer->saveConfig([ConfigFilePool::APP_ENV => $config], true);
145+
}
146+
147+
/**
148+
* @inheritdoc
149+
*/
150+
protected function tearDown()
151+
{
152+
parent::tearDown();
153+
$this->writeConfig($this->config);
154+
}
46155
}

0 commit comments

Comments
 (0)