@@ -103,13 +103,12 @@ protected function setUp(): void
103103
104104 public function testRunDisabled ()
105105 {
106- $ this ->deploymentConfigMock ->expects ($ this ->once ())
106+ $ this ->deploymentConfigMock ->expects ($ this ->atLeastOnce ())
107107 ->method ('get ' )
108108 ->willReturnMap (
109109 [
110110 ['cron_consumers_runner/cron_run ' , true , false ],
111- ['cron_consumers_runner/max_messages ' , 10000 , 10000 ],
112- ['cron_consumers_runner/consumers ' , [], []],
111+ ['cron_consumers_runner/multiple_processes ' , [], []],
113112 ]
114113 );
115114
@@ -154,6 +153,7 @@ public function testRun(
154153 ['cron_consumers_runner/max_messages ' , 10000 , $ maxMessages ],
155154 ['cron_consumers_runner/consumers ' , [], $ allowedConsumers ],
156155 ['queue/only_spawn_when_message_available ' , null , 0 ],
156+ ['cron_consumers_runner/multiple_processes ' , [], []]
157157 ]
158158 );
159159
@@ -271,6 +271,125 @@ public function runDataProvider()
271271 ];
272272 }
273273
274+ /**
275+ * @param int $maxMessages
276+ * @param array $isLocked
277+ * @param string $php
278+ * @param array $returnMap
279+ * @param array $allowedConsumers
280+ * @param int $shellBackgroundExpects
281+ * @dataProvider runMultiProcessesDataProvider
282+ */
283+ public function testRunMultiProcesses (
284+ int $ maxMessages ,
285+ array $ isLocked ,
286+ string $ php ,
287+ array $ returnMap ,
288+ array $ allowedConsumers ,
289+ int $ shellBackgroundExpects
290+ ): void
291+ {
292+ $ consumerName = 'consumerName ' ;
293+
294+ $ this ->deploymentConfigMock
295+ ->method ('get ' )
296+ ->willReturnMap (
297+ [
298+ ['cron_consumers_runner/cron_run ' , true , true ],
299+ ['cron_consumers_runner/max_messages ' , 10000 , $ maxMessages ],
300+ ['cron_consumers_runner/consumers ' , [], $ allowedConsumers ],
301+ ['queue/only_spawn_when_message_available ' , null , 0 ],
302+ ['cron_consumers_runner/multiple_processes ' ,
303+ [],
304+ ['consumerName ' => 2 ]
305+ ]
306+ ]
307+ );
308+
309+ /** @var ConsumerConfigInterface|MockObject $firstCunsumer */
310+ $ consumer = $ this ->getMockBuilder (ConsumerConfigItemInterface::class)
311+ ->getMockForAbstractClass ();
312+ $ consumer ->method ('getName ' )->willReturn ($ consumerName );
313+
314+ $ this ->phpExecutableFinderMock ->expects ($ this ->once ())
315+ ->method ('find ' )
316+ ->willReturn ($ php );
317+
318+ $ this ->consumerConfigMock ->expects ($ this ->once ())
319+ ->method ('getConsumers ' )
320+ ->willReturn ([$ consumer ]);
321+
322+ $ this ->lockManagerMock ->expects (self ::exactly (2 ))
323+ ->method ('isLocked ' )
324+ ->withConsecutive (
325+ [md5 ($ consumerName . '- ' . 1 )], //phpcs:ignore
326+ [md5 ($ consumerName . '- ' . 2 )] //phpcs:ignore
327+ )
328+ ->willReturnOnConsecutiveCalls ($ isLocked [0 ], $ isLocked [1 ]);
329+
330+ $ this ->shellBackgroundMock ->expects (self ::exactly ($ shellBackgroundExpects ))
331+ ->method ('execute ' )
332+ ->willReturnMap ($ returnMap );
333+
334+ $ this ->consumersRunner ->run ();
335+ }
336+
337+ /**
338+ * @return array
339+ */
340+ public function runMultiProcessesDataProvider ()
341+ {
342+ return [
343+ [
344+ 'maxMessages ' => 20000 ,
345+ 'isLocked ' => [false , false ],
346+ 'php ' => '' ,
347+ 'returnMap ' => [
348+ [
349+ 'php ' . BP . '/bin/magento queue:consumers:start %s %s %s ' ,
350+ ['consumerName ' , '--multi-process=1 ' , '--max-messages=20000 ' ],
351+ 'value1 '
352+ ],
353+ [
354+ 'php ' . BP . '/bin/magento queue:consumers:start %s %s %s ' ,
355+ ['consumerName ' , '--multi-process=2 ' , '--max-messages=20000 ' ],
356+ 'value2 '
357+ ]
358+ ],
359+ 'allowedConsumers ' => [],
360+ 'shellBackgroundExpects ' => 2
361+ ],
362+ [
363+ 'maxMessages ' => 20000 ,
364+ 'isLocked ' => [true , false ],
365+ 'php ' => '' ,
366+ 'returnMap ' => [
367+ [
368+ 'php ' . BP . '/bin/magento queue:consumers:start %s %s %s ' ,
369+ ['consumerName ' , '--multi-process=2 ' , '--max-messages=20000 ' ],
370+ 'value2 '
371+ ]
372+ ],
373+ 'allowedConsumers ' => [],
374+ 'shellBackgroundExpects ' => 1
375+ ],
376+ [
377+ 'maxMessages ' => 20000 ,
378+ 'isLocked ' => [true , true ],
379+ 'php ' => '' ,
380+ 'returnMap ' => [
381+ [
382+ 'php ' . BP . '/bin/magento queue:consumers:start %s %s %s ' ,
383+ ['consumerName ' , '--multi-process=2 ' , '--max-messages=20000 ' ],
384+ 'value2 '
385+ ]
386+ ],
387+ 'allowedConsumers ' => [],
388+ 'shellBackgroundExpects ' => 0
389+ ],
390+ ];
391+ }
392+
274393 /**
275394 * @param boolean $onlySpawnWhenMessageAvailable
276395 * @param boolean $isMassagesAvailableInTheQueue
@@ -291,14 +410,15 @@ public function testRunBasedOnOnlySpawnWhenMessageAvailableConsumerConfiguration
291410 $ consumerName = 'consumerName ' ;
292411 $ connectionName = 'connectionName ' ;
293412 $ queueName = 'queueName ' ;
294- $ this ->deploymentConfigMock ->expects ($ this ->exactly (4 ))
413+ $ this ->deploymentConfigMock ->expects ($ this ->exactly (5 ))
295414 ->method ('get ' )
296415 ->willReturnMap (
297416 [
298417 ['cron_consumers_runner/cron_run ' , true , true ],
299418 ['cron_consumers_runner/max_messages ' , 10000 , 1000 ],
300419 ['cron_consumers_runner/consumers ' , [], []],
301420 ['queue/only_spawn_when_message_available ' , true , $ globalOnlySpawnWhenMessageAvailable ],
421+ ['cron_consumers_runner/multiple_processes ' , [], []]
302422 ]
303423 );
304424
@@ -321,9 +441,7 @@ public function testRunBasedOnOnlySpawnWhenMessageAvailableConsumerConfiguration
321441 ->method ('find ' )
322442 ->willReturn ('' );
323443
324- $ this ->lockManagerMock ->expects ($ this ->once ())
325- ->method ('isLocked ' )
326- ->willReturn (false );
444+ $ this ->lockManagerMock ->method ('isLocked ' )->willReturn (false );
327445
328446 $ this ->checkIsAvailableMessagesMock ->expects ($ this ->exactly ($ isMassagesAvailableInTheQueueCallCount ))
329447 ->method ('execute ' )
0 commit comments