Skip to content

Commit 6f76b0b

Browse files
committed
MQE-2495: config parallel by number of groups
1 parent 7979782 commit 6f76b0b

File tree

7 files changed

+310
-49
lines changed

7 files changed

+310
-49
lines changed

dev/tests/verification/Tests/SuiteGenerationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\FunctionalTestingFramework\Suite\SuiteGenerator;
1111
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
1212
use Magento\FunctionalTestingFramework\Util\Manifest\DefaultTestManifest;
13-
use Magento\FunctionalTestingFramework\Util\Manifest\ParallelTestManifest;
13+
use Magento\FunctionalTestingFramework\Util\Manifest\ParallelByTimeTestManifest;
1414
use Magento\FunctionalTestingFramework\Util\Manifest\TestManifestFactory;
1515
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
1616
use Symfony\Component\Yaml\Yaml;
@@ -121,7 +121,7 @@ public function testSuiteGenerationParallel()
121121
$expectedContents = SuiteTestReferences::$data[$groupName];
122122

123123
//createParallelManifest
124-
/** @var ParallelTestManifest $parallelManifest */
124+
/** @var ParallelByTimeTestManifest $parallelManifest */
125125
$parallelManifest = TestManifestFactory::makeManifest("parallel", ["functionalSuite1" => []]);
126126

127127
// Generate the Suite

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
1616
use Magento\FunctionalTestingFramework\Util\GenerationErrorHandler;
1717
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
18-
use Magento\FunctionalTestingFramework\Util\Manifest\ParallelTestManifest;
18+
use Magento\FunctionalTestingFramework\Util\Manifest\ParallelByTimeTestManifest;
1919
use Magento\FunctionalTestingFramework\Util\Manifest\TestManifestFactory;
2020
use Magento\FunctionalTestingFramework\Util\TestGenerator;
2121
use Symfony\Component\Console\Input\InputArgument;
@@ -29,6 +29,8 @@
2929
*/
3030
class GenerateTestsCommand extends BaseGenerateCommand
3131
{
32+
const PARALLEL_DEFAULT_TIME = 10;
33+
3234
/**
3335
* Configures the current command.
3436
*
@@ -43,13 +45,23 @@ protected function configure()
4345
'name',
4446
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
4547
'name(s) of specific tests to generate'
46-
)->addOption("config", 'c', InputOption::VALUE_REQUIRED, 'default, singleRun, or parallel', 'default')
47-
->addOption(
48+
)->addOption(
49+
"config",
50+
'c',
51+
InputOption::VALUE_REQUIRED,
52+
'default, singleRun, or parallel',
53+
'default'
54+
)->addOption(
4855
'time',
4956
'i',
5057
InputOption::VALUE_REQUIRED,
5158
'Used in combination with a parallel configuration, determines desired group size (in minutes)',
52-
10
59+
self::PARALLEL_DEFAULT_TIME
60+
)->addOption(
61+
'groups',
62+
'g',
63+
InputOption::VALUE_REQUIRED,
64+
'Used in combination with a parallel configuration, determines desired number of groups'
5365
)->addOption(
5466
'tests',
5567
't',
@@ -86,6 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8698
$json = $input->getOption('tests'); // for backward compatibility
8799
$force = $input->getOption('force');
88100
$time = $input->getOption('time') * 60 * 1000; // convert from minutes to milliseconds
101+
$groups = $input->getOption('groups');
89102
$debug = $input->getOption('debug') ?? MftfApplicationConfig::LEVEL_DEVELOPER; // for backward compatibility
90103
$remove = $input->getOption('remove');
91104
$verbose = $output->isVerbose();
@@ -119,9 +132,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
119132
throw new TestFrameworkException("JSON could not be parsed: " . json_last_error_msg());
120133
}
121134

122-
if ($config === 'parallel' && $time <= 0) {
123-
// stop execution if the user has given us an invalid argument for time argument during parallel generation
124-
throw new TestFrameworkException("time option cannot be less than or equal to 0");
135+
$configNumber = null;
136+
if ($config === 'parallel') {
137+
$config = 'parallelByTime';
138+
if ($groups) {
139+
$groups = $groups * 1;
140+
$config = 'parallelByGroup';
141+
if ($time !== self::PARALLEL_DEFAULT_TIME * 60 * 1000) {
142+
throw new TestFrameworkException(
143+
"'time' and 'groups' options are mutually exclusive, only one can be used at a time"
144+
);
145+
}
146+
if (!is_int($groups) || $groups <= 0) {
147+
throw new TestFrameworkException("'groups' option must be an integer and greater than 0");
148+
}
149+
} elseif ($time <= 0) {
150+
throw new TestFrameworkException("'time' option cannot be less than or equal to 0");
151+
}
152+
153+
$configNumber = $groups ?? $time;
125154
}
126155

127156
// Remove previous GENERATED_DIR if --remove option is used
@@ -153,9 +182,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
153182
} catch (\Exception $e) {
154183
}
155184

156-
if ($config == 'parallel') {
157-
/** @var ParallelTestManifest $testManifest */
158-
$testManifest->createTestGroups($time);
185+
if (strpos($config, 'parallel') !== false) {
186+
$testManifest->createTestGroups($configNumber);
159187
}
160188

161189
SuiteGenerator::getInstance()->generateAllSuites($testManifest);

src/Magento/FunctionalTestingFramework/Util/Manifest/ParallelTestManifest.php renamed to src/Magento/FunctionalTestingFramework/Util/Manifest/BaseParallelTestManifest.php

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,53 @@
66

77
namespace Magento\FunctionalTestingFramework\Util\Manifest;
88

9-
use Codeception\Suite;
109
use Magento\Framework\Exception\RuntimeException;
11-
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
12-
use Magento\FunctionalTestingFramework\Suite\Objects\SuiteObject;
13-
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
1410
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
1511
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
1612
use Magento\FunctionalTestingFramework\Util\Sorter\ParallelGroupSorter;
17-
use RecursiveArrayIterator;
18-
use RecursiveIteratorIterator;
1913

20-
class ParallelTestManifest extends BaseTestManifest
14+
abstract class BaseParallelTestManifest extends BaseTestManifest
2115
{
22-
const PARALLEL_CONFIG = 'parallel';
23-
2416
/**
2517
* An associate array of test name to size of test.
2618
*
2719
* @var string[]
2820
*/
29-
private $testNameToSize = [];
21+
protected $testNameToSize = [];
3022

3123
/**
3224
* Class variable to store resulting group config.
3325
*
3426
* @var array
3527
*/
36-
private $testGroups;
28+
protected $testGroups;
3729

3830
/**
3931
* An instance of the group sorter which will take suites and tests organizing them to be run together.
4032
*
4133
* @var ParallelGroupSorter
4234
*/
43-
private $parallelGroupSorter;
35+
protected $parallelGroupSorter;
4436

4537
/**
4638
* Path to the directory that will contain all test group files
4739
*
4840
* @var string
4941
*/
50-
private $dirPath;
42+
protected $dirPath;
5143

5244
/**
53-
* TestManifest constructor.
45+
* BaseParallelTestManifest constructor.
5446
*
5547
* @param array $suiteConfiguration
48+
* @param string $runConfig
5649
* @param string $testPath
5750
*/
58-
public function __construct($suiteConfiguration, $testPath)
51+
public function __construct($suiteConfiguration, $runConfig, $testPath)
5952
{
6053
$this->dirPath = dirname($testPath) . DIRECTORY_SEPARATOR . 'groups';
6154
$this->parallelGroupSorter = new ParallelGroupSorter();
62-
parent::__construct($testPath, self::PARALLEL_CONFIG, $suiteConfiguration);
55+
parent::__construct($testPath, $runConfig, $suiteConfiguration);
6356
}
6457

6558
/**
@@ -74,22 +67,12 @@ public function addTest($testObject)
7467
}
7568

7669
/**
77-
* Function which generates test groups based on arg passed. The function builds groups using the args as an upper
78-
* limit.
70+
* Function which generates test groups based on arg passed.
7971
*
80-
* @param integer $time
72+
* @param integer $number
8173
* @return void
8274
*/
83-
public function createTestGroups($time)
84-
{
85-
$this->testGroups = $this->parallelGroupSorter->getTestsGroupedBySize(
86-
$this->getSuiteConfig(),
87-
$this->testNameToSize,
88-
$time
89-
);
90-
91-
$this->suiteConfiguration = $this->parallelGroupSorter->getResultingSuiteConfig();
92-
}
75+
abstract public function createTestGroups($number);
9376

9477
/**
9578
* Function which generates the actual manifest once the relevant tests have been added to the array.
@@ -126,7 +109,7 @@ public function getSorter()
126109
* @param array $suites
127110
* @return void
128111
*/
129-
private function generateGroupFile($testGroup, $nodeNumber, $suites)
112+
protected function generateGroupFile($testGroup, $nodeNumber, $suites)
130113
{
131114
foreach ($testGroup as $entryName => $testValue) {
132115
$fileResource = fopen($this->dirPath . DIRECTORY_SEPARATOR . "group{$nodeNumber}.txt", 'a');
@@ -149,7 +132,7 @@ private function generateGroupFile($testGroup, $nodeNumber, $suites)
149132
* @param array $multiDimensionalSuites
150133
* @return array
151134
*/
152-
private function getFlattenedSuiteConfiguration($multiDimensionalSuites)
135+
protected function getFlattenedSuiteConfiguration($multiDimensionalSuites)
153136
{
154137
$suites = [];
155138
foreach ($multiDimensionalSuites as $suiteName => $suiteContent) {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\FunctionalTestingFramework\Util\Manifest;
8+
9+
use Magento\Framework\Exception\RuntimeException;
10+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
11+
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
12+
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
13+
use Magento\FunctionalTestingFramework\Util\Sorter\ParallelGroupSorter;
14+
15+
class ParallelByGroupTestManifest extends BaseParallelTestManifest
16+
{
17+
const PARALLEL_CONFIG = 'parallelByGroup';
18+
19+
/**
20+
* ParallelByGroupTestManifest constructor.
21+
*
22+
* @param array $suiteConfiguration
23+
* @param string $testPath
24+
*/
25+
public function __construct($suiteConfiguration, $testPath)
26+
{
27+
parent::__construct($suiteConfiguration, self::PARALLEL_CONFIG, $testPath);
28+
}
29+
30+
/**
31+
* Function which generates test groups based on arg passed.
32+
*
33+
* @param integer $totalGroups
34+
* @return void
35+
* @throws TestFrameworkException
36+
*/
37+
public function createTestGroups($totalGroups)
38+
{
39+
$this->testGroups = $this->parallelGroupSorter->getTestsGroupedByFixedGroupCount(
40+
$this->getSuiteConfig(),
41+
$this->testNameToSize,
42+
$totalGroups
43+
);
44+
45+
$this->suiteConfiguration = $this->parallelGroupSorter->getResultingSuiteConfig();
46+
}
47+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\FunctionalTestingFramework\Util\Manifest;
8+
9+
use Codeception\Suite;
10+
use Magento\Framework\Exception\RuntimeException;
11+
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
12+
use Magento\FunctionalTestingFramework\Suite\Objects\SuiteObject;
13+
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
14+
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
15+
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
16+
use Magento\FunctionalTestingFramework\Util\Sorter\ParallelGroupSorter;
17+
use RecursiveArrayIterator;
18+
use RecursiveIteratorIterator;
19+
20+
class ParallelByTimeTestManifest extends BaseParallelTestManifest
21+
{
22+
const PARALLEL_CONFIG = 'parallelByTime';
23+
24+
/**
25+
* GroupBasedParallelTestManifest constructor.
26+
*
27+
* @param array $suiteConfiguration
28+
* @param string $testPath
29+
*/
30+
public function __construct($suiteConfiguration, $testPath)
31+
{
32+
parent::__construct($suiteConfiguration, self::PARALLEL_CONFIG, $testPath);
33+
}
34+
35+
/**
36+
* Function which generates test groups based on arg passed. The function builds groups using the args as an upper
37+
* limit.
38+
*
39+
* @param integer $time
40+
* @return void
41+
*/
42+
public function createTestGroups($time)
43+
{
44+
$this->testGroups = $this->parallelGroupSorter->getTestsGroupedBySize(
45+
$this->getSuiteConfig(),
46+
$this->testNameToSize,
47+
$time
48+
);
49+
50+
$this->suiteConfiguration = $this->parallelGroupSorter->getResultingSuiteConfig();
51+
}
52+
}

src/Magento/FunctionalTestingFramework/Util/Manifest/TestManifestFactory.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ public static function makeManifest($runConfig, $suiteConfiguration, $testPath =
4141
case 'singleRun':
4242
return new SingleRunTestManifest($suiteConfiguration, $testDirFullPath);
4343

44-
case 'parallel':
45-
return new ParallelTestManifest($suiteConfiguration, $testDirFullPath);
44+
case 'parallelByTime':
45+
return new ParallelByTimeTestManifest($suiteConfiguration, $testDirFullPath);
46+
47+
case 'parallelByGroup':
48+
return new ParallelByGroupTestManifest($suiteConfiguration, $testDirFullPath);
4649

4750
default:
4851
return new DefaultTestManifest($suiteConfiguration, $testDirFullPath);

0 commit comments

Comments
 (0)