Skip to content

Commit f6dfe82

Browse files
committed
ACP2E-3538: indexer_update_all_views cron error with MAGE_INDEXER_THREADS_COUNT
1 parent 6cfb9b6 commit f6dfe82

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

app/code/Magento/Indexer/Model/ProcessManager.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2018 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -78,7 +78,7 @@ public function __construct(
7878
*/
7979
public function execute($userFunctions)
8080
{
81-
if ($this->threadsCount > 1 && $this->isCanBeParalleled() && !$this->isSetupMode() && PHP_SAPI == 'cli') {
81+
if ($this->isMultiThreadsExecute()) {
8282
$this->multiThreadsExecute($userFunctions);
8383
} else {
8484
$this->simpleThreadExecute($userFunctions);
@@ -196,4 +196,14 @@ private function executeParentProcess(int &$threadNumber)
196196
$threadNumber--;
197197
}
198198
}
199+
200+
/**
201+
* Check if the current process is multithreaded
202+
*
203+
* @return bool
204+
*/
205+
public function isMultiThreadsExecute(): bool
206+
{
207+
return $this->threadsCount > 1 && $this->isCanBeParalleled() && !$this->isSetupMode() && PHP_SAPI == 'cli';
208+
}
199209
}

app/code/Magento/Indexer/Test/Unit/Model/ProcessManagerTest.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -206,4 +206,37 @@ function () {
206206
],
207207
];
208208
}
209+
210+
/**
211+
* @dataProvider testIsMultiThreadsExecuteDataProvider
212+
* @param $threadsCount
213+
* @param $expectedResult
214+
* @return void
215+
* @throws \PHPUnit\Framework\MockObject\Exception
216+
*/
217+
public function testIsMultiThreadsExecute($threadsCount, $expectedResult): void
218+
{
219+
$connectionMock = $this->createMock(ResourceConnection::class);
220+
$registryMock = $this->createMock(Registry::class);
221+
$loggerMock = $this->createMock(LoggerInterface::class);
222+
$amqpConfigPoolMock = $this->createMock(AmqpConfigPool::class);
223+
$processManager = new ProcessManager(
224+
$connectionMock,
225+
$registryMock,
226+
$threadsCount,
227+
$loggerMock,
228+
$amqpConfigPoolMock
229+
);
230+
$this->assertEquals($expectedResult, $processManager->isMultiThreadsExecute());
231+
}
232+
233+
public static function testIsMultiThreadsExecuteDataProvider(): array
234+
{
235+
return [
236+
'threadsCount is null' => [null, false],
237+
'threadsCount is 0' => [0, false],
238+
'threadsCount is 1' => [1, false],
239+
'threadsCount is 2' => [2, true],
240+
];
241+
}
209242
}

0 commit comments

Comments
 (0)