Skip to content

Commit ffab628

Browse files
authored
ENGCOM-8163: honor queue_consumer.xml maxMessages #28995
2 parents fa95e33 + c68d6d4 commit ffab628

File tree

2 files changed

+65
-14
lines changed

2 files changed

+65
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function run()
131131
];
132132

133133
if ($maxMessages) {
134-
$arguments[] = '--max-messages=' . $maxMessages;
134+
$arguments[] = '--max-messages=' . min($consumer->getMaxMessages() ?? $maxMessages, $maxMessages);
135135
}
136136

137137
$command = $php . ' ' . BP . '/bin/magento queue:consumers:start %s %s'

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

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,36 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\MessageQueue\Model\Cron;
79

10+
use Magento\Framework\App\Config\ReinitableConfigInterface;
811
use Magento\Framework\App\DeploymentConfig;
9-
use Magento\Framework\App\ResourceConnection;
10-
use Magento\Framework\Lock\Backend\Database;
11-
use Magento\Framework\MessageQueue\Consumer\ConfigInterface as ConsumerConfigInterface;
12-
use Magento\Framework\Lock\LockManagerInterface;
1312
use Magento\Framework\App\DeploymentConfig\FileReader;
1413
use Magento\Framework\App\DeploymentConfig\Writer;
14+
use Magento\Framework\App\Filesystem\DirectoryList;
15+
use Magento\Framework\App\ResourceConnection;
1516
use Magento\Framework\Config\File\ConfigFilePool;
16-
use Magento\Framework\ShellInterface;
1717
use Magento\Framework\Filesystem;
18-
use Magento\Framework\App\Filesystem\DirectoryList;
19-
use Magento\Framework\App\Config\ReinitableConfigInterface;
18+
use Magento\Framework\Lock\Backend\Database;
19+
use Magento\Framework\Lock\LockManagerInterface;
20+
use Magento\Framework\MessageQueue\Consumer\ConfigInterface as ConsumerConfigInterface;
21+
use Magento\Framework\ObjectManagerInterface;
22+
use Magento\Framework\ShellInterface;
23+
use Magento\TestFramework\Helper\Bootstrap;
24+
use PHPUnit\Framework\MockObject\MockObject;
25+
use PHPUnit\Framework\TestCase;
2026

2127
/**
2228
* Tests the different cases of consumers running by ConsumersRunner
2329
*
24-
* {@inheritdoc}
2530
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2631
*/
27-
class ConsumersRunnerTest extends \PHPUnit\Framework\TestCase
32+
class ConsumersRunnerTest extends TestCase
2833
{
2934
/**
30-
* @var \Magento\Framework\ObjectManagerInterface
35+
* @var ObjectManagerInterface
3136
*/
3237
private $objectManager;
3338

@@ -69,7 +74,7 @@ class ConsumersRunnerTest extends \PHPUnit\Framework\TestCase
6974
private $appConfig;
7075

7176
/**
72-
* @var ShellInterface|\PHPUnit\Framework\MockObject\MockObject
77+
* @var ShellInterface|MockObject
7378
*/
7479
private $shellMock;
7580

@@ -83,7 +88,7 @@ class ConsumersRunnerTest extends \PHPUnit\Framework\TestCase
8388
*/
8489
protected function setUp(): void
8590
{
86-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
91+
$this->objectManager = Bootstrap::getObjectManager();
8792
$this->shellMock = $this->getMockBuilder(ShellInterface::class)
8893
->getMockForAbstractClass();
8994
$resourceConnection = $this->objectManager->create(ResourceConnection::class);
@@ -106,7 +111,7 @@ protected function setUp(): void
106111
->willReturnCallback(
107112
function ($command, $arguments) {
108113
$command = vsprintf($command, $arguments);
109-
$params = \Magento\TestFramework\Helper\Bootstrap::getInstance()->getAppInitParams();
114+
$params = Bootstrap::getInstance()->getAppInitParams();
110115
$params['MAGE_DIRS']['base']['path'] = BP;
111116
$params = 'INTEGRATION_TEST_PARAMS="' . urldecode(http_build_query($params)) . '"';
112117
$command = str_replace('bin/magento', 'dev/tests/integration/bin/magento', $command);
@@ -117,6 +122,52 @@ function ($command, $arguments) {
117122
);
118123
}
119124

125+
/**
126+
* @param string $specificConsumer
127+
* @param int $maxMessage
128+
* @param string $command
129+
* @param array $expectedArguments
130+
*
131+
* @return void
132+
* @dataProvider runDataProvider
133+
*/
134+
public function testArgumentMaxMessages(
135+
string $specificConsumer,
136+
int $maxMessage,
137+
string $command,
138+
array $expectedArguments
139+
) {
140+
$config = $this->config;
141+
$config['cron_consumers_runner'] = ['consumers' => [$specificConsumer], 'max_messages' => $maxMessage];
142+
$this->writeConfig($config);
143+
$this->shellMock->expects($this->any())
144+
->method('execute')
145+
->with($command, $expectedArguments);
146+
147+
$this->consumersRunner->run();
148+
}
149+
150+
/**
151+
* @return array
152+
*/
153+
public function runDataProvider()
154+
{
155+
return [
156+
[
157+
'specificConsumer' => 'exportProcessor',
158+
'max_messages' => 10,
159+
'command' => PHP_BINARY . ' ' . BP . '/bin/magento queue:consumers:start %s %s %s',
160+
'expectedArguments' => ['exportProcessor', '--single-thread', '--max-messages=10'],
161+
],
162+
[
163+
'specificConsumer' => 'exportProcessor',
164+
'max_messages' => 5000,
165+
'command' => PHP_BINARY . ' ' . BP . '/bin/magento queue:consumers:start %s %s %s',
166+
'expectedArguments' => ['exportProcessor', '--single-thread', '--max-messages=100'],
167+
],
168+
];
169+
}
170+
120171
/**
121172
* Tests running of specific consumer and his re-running when it is working
122173
*

0 commit comments

Comments
 (0)