Skip to content

Commit 684e793

Browse files
committed
MQE-2495: config parallel by number of groups
1 parent f5065a0 commit 684e793

File tree

1 file changed

+50
-20
lines changed

1 file changed

+50
-20
lines changed

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ protected function configure()
5656
'i',
5757
InputOption::VALUE_REQUIRED,
5858
'Used in combination with a parallel configuration, determines desired group size (in minutes)',
59-
self::PARALLEL_DEFAULT_TIME
6059
)->addOption(
6160
'groups',
6261
'g',
@@ -97,7 +96,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
9796
$config = $input->getOption('config');
9897
$json = $input->getOption('tests'); // for backward compatibility
9998
$force = $input->getOption('force');
100-
$time = $input->getOption('time') * 60 * 1000; // convert from minutes to milliseconds
99+
$time = $input->getOption('time');
100+
//$time = $input->getOption('time') * 60 * 1000; // convert from minutes to milliseconds
101101
$groups = $input->getOption('groups');
102102
$debug = $input->getOption('debug') ?? MftfApplicationConfig::LEVEL_DEVELOPER; // for backward compatibility
103103
$remove = $input->getOption('remove');
@@ -132,25 +132,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
132132
throw new TestFrameworkException("JSON could not be parsed: " . json_last_error_msg());
133133
}
134134

135-
$configNumber = null;
136135
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;
136+
list($config, $configNumber) = $this->parseConfigureParalleOptions($time, $groups);
154137
}
155138

156139
// Remove previous GENERATED_DIR if --remove option is used
@@ -279,4 +262,51 @@ private function parseTestsConfigJson($json, array $testConfiguration)
279262
$jsonTestConfiguration['suites'] = $testConfigArray['suites'] ?? null;
280263
return $jsonTestConfiguration;
281264
}
265+
266+
/**
267+
* Parse console command options --time and/or --groups and return config type and config number in an array
268+
*
269+
* @param mixed $time
270+
* @param mixed $groups
271+
* @return array
272+
* @throws FastFailException
273+
*/
274+
private function parseConfigureParalleOptions($time, $groups)
275+
{
276+
$config = null;
277+
$configNumber = null;
278+
if ($time !== null && $groups !== null) {
279+
throw new FastFailException(
280+
"'time' and 'groups' options are mutually exclusive. "
281+
. "Only one can be specified for 'config parallel'"
282+
);
283+
} elseif ($time === null && $groups === null) {
284+
$config = 'parallelByTime';
285+
$configNumber = self::PARALLEL_DEFAULT_TIME * 60 * 1000; // convert from minutes to milliseconds
286+
} elseif ($time) {
287+
if (is_numeric($time)) {
288+
$time = $time * 60 * 1000; // convert from minutes to milliseconds
289+
if (is_int($time) && $time > 0) {
290+
$config = 'parallelByTime';
291+
$configNumber = $time;
292+
}
293+
}
294+
} else {
295+
if (is_numeric($groups)) {
296+
$groups = $groups * 1;
297+
if (is_int($groups) && $groups > 0) {
298+
$config = 'parallelByGroup';
299+
$configNumber = $groups;
300+
}
301+
}
302+
}
303+
304+
if ($config && $configNumber) {
305+
return [$config, $configNumber];
306+
} elseif ($time) {
307+
throw new FastFailException("'time' option must be an integer and greater than 0");
308+
} else {
309+
throw new FastFailException("'groups' option must be an integer and greater than 0");
310+
}
311+
}
282312
}

0 commit comments

Comments
 (0)