Add parallel execution for data generator

[MAILPOET-3226]
This commit is contained in:
Rostislav Wolny
2021-05-06 15:32:43 +02:00
committed by Veljko V
parent ab00ff7869
commit 81fc441d4f
4 changed files with 74 additions and 29 deletions

View File

@@ -908,7 +908,27 @@ class RoboFile extends \Robo\Tasks {
->downloadReleaseZip('woocommerce.zip', __DIR__ . '/tests/plugins/', $tag);
}
public function generateData($generatorName = null) {
public function generateData($generatorName = null, $threads = 1) {
require_once __DIR__ . '/tests/DataGenerator/_bootstrap.php';
$generator = new \MailPoet\Test\DataGenerator\DataGenerator(new \Codeception\Lib\Console\Output([]));
$generator->runBefore($generatorName);
if ((int)$threads === 1) {
$this->generateUnitOfData($generatorName);
} else {
$parallelTask = $this->taskParallelExec();
for ($i = 1; $i <= $threads; $i++) {
$parallelTask = $parallelTask->process("./do generate:unit-of-data $generatorName");
}
$parallelTask->run();
}
$generator->runAfter($generatorName);
}
/**
* This is intended only for usage as a child process in parallel execution
* @param string|null $generatorName
*/
public function generateUnitOfData($generatorName = null) {
require_once __DIR__ . '/tests/DataGenerator/_bootstrap.php';
$generator = new \MailPoet\Test\DataGenerator\DataGenerator(new \Codeception\Lib\Console\Output([]));
$generator->run($generatorName);