mirror of
https://github.com/pestphp/pest.git
synced 2026-04-21 22:47:27 +02:00
feat(time-based-sharding): updates exception name
This commit is contained in:
@ -34,7 +34,8 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
|
|||||||
* index: int,
|
* index: int,
|
||||||
* total: int,
|
* total: int,
|
||||||
* testsRan: int,
|
* testsRan: int,
|
||||||
* testsCount: int
|
* testsCount: int,
|
||||||
|
* estimatedTime: float|null
|
||||||
* }|null
|
* }|null
|
||||||
*/
|
*/
|
||||||
private static ?array $shard = null;
|
private static ?array $shard = null;
|
||||||
@ -122,11 +123,16 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
|
|||||||
$testsToRun = (array_chunk($tests, max(1, (int) ceil(count($tests) / $total))))[$index - 1] ?? [];
|
$testsToRun = (array_chunk($tests, max(1, (int) ceil(count($tests) / $total))))[$index - 1] ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$estimatedTime = self::$timeBalanced && $timings !== null
|
||||||
|
? array_sum(array_map(fn (string $test): float => $timings[$test] ?? 0.0, $testsToRun))
|
||||||
|
: null;
|
||||||
|
|
||||||
self::$shard = [
|
self::$shard = [
|
||||||
'index' => $index,
|
'index' => $index,
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
'testsRan' => count($testsToRun),
|
'testsRan' => count($testsToRun),
|
||||||
'testsCount' => count($tests),
|
'testsCount' => count($tests),
|
||||||
|
'estimatedTime' => $estimatedTime,
|
||||||
];
|
];
|
||||||
|
|
||||||
return [...$arguments, '--filter', $this->buildFilterArgument($testsToRun)];
|
return [...$arguments, '--filter', $this->buildFilterArgument($testsToRun)];
|
||||||
@ -174,7 +180,7 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
|
|||||||
'php',
|
'php',
|
||||||
...$this->removeParallelArguments($arguments),
|
...$this->removeParallelArguments($arguments),
|
||||||
'--list-tests',
|
'--list-tests',
|
||||||
]))->mustRun()->getOutput();
|
]))->setTimeout(120)->mustRun()->getOutput();
|
||||||
|
|
||||||
preg_match_all('/ - (?:P\\\\)?(Tests\\\\[^:]+)::/', $output, $matches);
|
preg_match_all('/ - (?:P\\\\)?(Tests\\\\[^:]+)::/', $output, $matches);
|
||||||
|
|
||||||
@ -226,8 +232,14 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
|
|||||||
'total' => $total,
|
'total' => $total,
|
||||||
'testsRan' => $testsRan,
|
'testsRan' => $testsRan,
|
||||||
'testsCount' => $testsCount,
|
'testsCount' => $testsCount,
|
||||||
|
'estimatedTime' => $estimatedTime,
|
||||||
] = self::$shard;
|
] = self::$shard;
|
||||||
|
|
||||||
|
$suffix = '';
|
||||||
|
if (self::$timeBalanced && is_float($estimatedTime)) {
|
||||||
|
$suffix = sprintf(' <fg=gray>(time-balanced, ~%.1fs)</>', $estimatedTime);
|
||||||
|
}
|
||||||
|
|
||||||
$this->output->writeln(sprintf(
|
$this->output->writeln(sprintf(
|
||||||
' <fg=gray>Shard:</> <fg=default>%d of %d</> — %d file%s ran, out of %d%s.',
|
' <fg=gray>Shard:</> <fg=default>%d of %d</> — %d file%s ran, out of %d%s.',
|
||||||
$index,
|
$index,
|
||||||
@ -235,7 +247,7 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
|
|||||||
$testsRan,
|
$testsRan,
|
||||||
$testsRan === 1 ? '' : 's',
|
$testsRan === 1 ? '' : 's',
|
||||||
$testsCount,
|
$testsCount,
|
||||||
self::$timeBalanced ? ' <fg=gray>(time-balanced)</>' : '',
|
$suffix,
|
||||||
));
|
));
|
||||||
|
|
||||||
return $exitCode;
|
return $exitCode;
|
||||||
@ -364,13 +376,13 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
|
|||||||
$contents = file_get_contents($path);
|
$contents = file_get_contents($path);
|
||||||
|
|
||||||
if ($contents === false) {
|
if ($contents === false) {
|
||||||
return null;
|
throw new InvalidOption('The [tests/.pest/shards.json] file could not be read. Delete it or run [--update-shards] to regenerate.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = json_decode($contents, true);
|
$data = json_decode($contents, true);
|
||||||
|
|
||||||
if (! is_array($data) || ! isset($data['timings']) || ! is_array($data['timings'])) {
|
if (! is_array($data) || ! isset($data['timings']) || ! is_array($data['timings'])) {
|
||||||
return null;
|
throw new InvalidOption('The [tests/.pest/shards.json] file is corrupted. Delete it or run [--update-shards] to regenerate.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var array<string, float> */
|
/** @var array<string, float> */
|
||||||
|
|||||||
Reference in New Issue
Block a user