-
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 e45a944
Showing
2 changed files
with
187 additions
and
1 deletion.
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
183 changes: 183 additions & 0 deletions
183
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,183 @@ | ||
<?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 functionsWithErrorProvider | ||
* @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 functionsWithErrorProvider(): array | ||
{ | ||
return [ | ||
'more_threads_than_functions' => [ | ||
'user_functions' => [ | ||
// @codingStandardsIgnoreStart | ||
function () { | ||
exit(1); | ||
}, | ||
function () { | ||
exit(0); | ||
}, | ||
function () { | ||
exit(0); | ||
}, | ||
// @codingStandardsIgnoreEnd | ||
], | ||
'threads_count' => 4, | ||
], | ||
'less_threads_than_functions' => [ | ||
'user_functions' => [ | ||
// @codingStandardsIgnoreStart | ||
function () { | ||
exit(1); | ||
}, | ||
function () { | ||
exit(0); | ||
}, | ||
function () { | ||
exit(0); | ||
}, | ||
// @codingStandardsIgnoreEnd | ||
], | ||
'threads_count' => 2, | ||
], | ||
'equal_threads_and_functions' => [ | ||
'user_functions' => [ | ||
// @codingStandardsIgnoreStart | ||
function () { | ||
exit(1); | ||
}, | ||
function () { | ||
exit(0); | ||
}, | ||
function () { | ||
exit(0); | ||
}, | ||
// @codingStandardsIgnoreEnd | ||
], | ||
'threads_count' => 3, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider successFunctionsProvider | ||
* @param array $userFunctions | ||
* @param int $threadsCount | ||
* @return void | ||
*/ | ||
public function testSuccessChildProcessHandleMultiThread(array $userFunctions, int $threadsCount): void | ||
{ | ||
$connectionMock = $this->createMock(ResourceConnection::class); | ||
$processManager = new ProcessManager( | ||
$connectionMock, | ||
null, | ||
$threadsCount | ||
); | ||
|
||
try { | ||
$processManager->execute($userFunctions); | ||
} catch (\RuntimeException $exception) { | ||
$this->fail('Exception was not handled'); | ||
} | ||
} | ||
|
||
/** | ||
* Closure functions data provider for multi thread execution | ||
* | ||
* @return array | ||
* @SuppressWarnings(PHPMD.ExitExpression) | ||
*/ | ||
public function successFunctionsProvider(): array | ||
{ | ||
return [ | ||
'more_threads_than_functions' => [ | ||
'user_functions' => [ | ||
// @codingStandardsIgnoreStart | ||
function () { | ||
exit(0); | ||
}, | ||
function () { | ||
exit(0); | ||
}, | ||
function () { | ||
exit(0); | ||
}, | ||
// @codingStandardsIgnoreEnd | ||
], | ||
'threads_count' => 4, | ||
], | ||
'less_threads_than_functions' => [ | ||
'user_functions' => [ | ||
// @codingStandardsIgnoreStart | ||
function () { | ||
exit(0); | ||
}, | ||
function () { | ||
exit(0); | ||
}, | ||
function () { | ||
exit(0); | ||
}, | ||
// @codingStandardsIgnoreEnd | ||
], | ||
'threads_count' => 2, | ||
], | ||
'equal_threads_and_functions' => [ | ||
'user_functions' => [ | ||
// @codingStandardsIgnoreStart | ||
function () { | ||
exit(0); | ||
}, | ||
function () { | ||
exit(0); | ||
}, | ||
function () { | ||
exit(0); | ||
}, | ||
// @codingStandardsIgnoreEnd | ||
], | ||
'threads_count' => 3, | ||
], | ||
]; | ||
} | ||
} |