-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MC-39718: Process Manager always exits successfully if the amount of …
…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
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/code/Magento/Indexer/Test/Unit/Model/ProcessManagerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
], | ||
]; | ||
} | ||
} |