@@ -103,13 +103,12 @@ protected function setUp(): void
103
103
104
104
public function testRunDisabled ()
105
105
{
106
- $ this ->deploymentConfigMock ->expects ($ this ->once ())
106
+ $ this ->deploymentConfigMock ->expects ($ this ->atLeastOnce ())
107
107
->method ('get ' )
108
108
->willReturnMap (
109
109
[
110
110
['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 ' , [], []],
113
112
]
114
113
);
115
114
@@ -154,6 +153,7 @@ public function testRun(
154
153
['cron_consumers_runner/max_messages ' , 10000 , $ maxMessages ],
155
154
['cron_consumers_runner/consumers ' , [], $ allowedConsumers ],
156
155
['queue/only_spawn_when_message_available ' , null , 0 ],
156
+ ['cron_consumers_runner/multiple_processes ' , [], []]
157
157
]
158
158
);
159
159
@@ -271,6 +271,125 @@ public function runDataProvider()
271
271
];
272
272
}
273
273
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
+
274
393
/**
275
394
* @param boolean $onlySpawnWhenMessageAvailable
276
395
* @param boolean $isMassagesAvailableInTheQueue
@@ -291,14 +410,15 @@ public function testRunBasedOnOnlySpawnWhenMessageAvailableConsumerConfiguration
291
410
$ consumerName = 'consumerName ' ;
292
411
$ connectionName = 'connectionName ' ;
293
412
$ queueName = 'queueName ' ;
294
- $ this ->deploymentConfigMock ->expects ($ this ->exactly (4 ))
413
+ $ this ->deploymentConfigMock ->expects ($ this ->exactly (5 ))
295
414
->method ('get ' )
296
415
->willReturnMap (
297
416
[
298
417
['cron_consumers_runner/cron_run ' , true , true ],
299
418
['cron_consumers_runner/max_messages ' , 10000 , 1000 ],
300
419
['cron_consumers_runner/consumers ' , [], []],
301
420
['queue/only_spawn_when_message_available ' , true , $ globalOnlySpawnWhenMessageAvailable ],
421
+ ['cron_consumers_runner/multiple_processes ' , [], []]
302
422
]
303
423
);
304
424
@@ -321,9 +441,7 @@ public function testRunBasedOnOnlySpawnWhenMessageAvailableConsumerConfiguration
321
441
->method ('find ' )
322
442
->willReturn ('' );
323
443
324
- $ this ->lockManagerMock ->expects ($ this ->once ())
325
- ->method ('isLocked ' )
326
- ->willReturn (false );
444
+ $ this ->lockManagerMock ->method ('isLocked ' )->willReturn (false );
327
445
328
446
$ this ->checkIsAvailableMessagesMock ->expects ($ this ->exactly ($ isMassagesAvailableInTheQueueCallCount ))
329
447
->method ('execute ' )
0 commit comments