Skip to content

Commit

Permalink
MC-39718: Process Manager always exits successfully if the amount of …
Browse files Browse the repository at this point in the history
…functions(i.e. indexer dimensions) is lower than the MAGE_INDEXER_THREADS_COUNT env variable
  • Loading branch information
Viktor Kopin committed Dec 21, 2020
1 parent 38d712e commit 7896526
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/code/Magento/Indexer/Model/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ private function multiThreadsExecute($userFunctions)
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock,Magento2.Functions.DiscouragedFunction
while (pcntl_waitpid(0, $status) != -1) {
//Waiting for the completion of child processes
if ($status > 0) {
$this->failInChildProcess = true;
}
}

if ($this->failInChildProcess) {
Expand Down
69 changes: 69 additions & 0 deletions app/code/Magento/Indexer/Test/Unit/Model/ProcessManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Indexer\Test\Unit\Model;

use Magento\Framework\App\ResourceConnection;
use Magento\Indexer\Model\ProcessManager;
use PHPUnit\Framework\TestCase;

/**
* Class covers process manager execution test logic
*/
class ProcessManagerTest extends TestCase
{
/**
* @dataProvider closureFunctionsProvider
* @param array $userFunctions
* @param int $threadsCount
* @return void
*/
public function testFailureInChildProcessHandleMultiThread(array $userFunctions, int $threadsCount): void
{
$connectionMock = $this->createMock(ResourceConnection::class);
$processManager = new ProcessManager(
$connectionMock,
null,
$threadsCount
);

try {
$processManager->execute($userFunctions);
$this->fail('Exception was not handled');
} catch (\RuntimeException $exception) {
$this->assertEquals('Fail in child process', $exception->getMessage());
}
}

/**
* Closure functions data provider for multi thread execution
*
* @return array
* @SuppressWarnings(PHPMD.ExitExpression)
*/
public function closureFunctionsProvider(): array
{
return [
'more_threads_than_functions' => [
'user_functions' => [
// @codingStandardsIgnoreStart
function () {
exit(1);
},
function () {
exit(0);
},
function () {
exit(0);
},
// @codingStandardsIgnoreEnd
],
'threads_count' => 4,
],
];
}
}

0 comments on commit 7896526

Please sign in to comment.