Skip to content

Commit 7cbb1fc

Browse files
committed
wip
1 parent cb5f6e1 commit 7cbb1fc

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Plugins/Shard.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
5050
*/
5151
private static bool $timeBalanced = false;
5252

53+
/**
54+
* Whether the shards.json file is outdated.
55+
*/
56+
private static bool $shardsOutdated = false;
57+
5358
/**
5459
* Collected timings from workers or subscribers.
5560
*
@@ -110,15 +115,18 @@ public function handleArguments(array $arguments): array
110115

111116
$timings = $this->loadShardsFile();
112117
if ($timings !== null) {
113-
$missingTests = array_diff($tests, array_keys($timings));
118+
$knownTests = array_values(array_filter($tests, fn (string $test): bool => isset($timings[$test])));
119+
$newTests = array_values(array_diff($tests, $knownTests));
114120

115-
if ($missingTests !== []) {
116-
throw new InvalidOption('The [tests/.pest/shards.json] file is out of date. Run [--update-shards] to update it.');
121+
$partitions = $this->partitionByTime($knownTests, $timings, $total);
122+
123+
foreach ($newTests as $i => $test) {
124+
$partitions[$i % $total][] = $test;
117125
}
118126

119-
$partitions = $this->partitionByTime($tests, $timings, $total);
120127
$testsToRun = $partitions[$index - 1] ?? [];
121128
self::$timeBalanced = true;
129+
self::$shardsOutdated = $newTests !== [];
122130
} else {
123131
$testsToRun = (array_chunk($tests, max(1, (int) ceil(count($tests) / $total))))[$index - 1] ?? [];
124132
}
@@ -250,6 +258,10 @@ public function addOutput(int $exitCode): int
250258
$suffix,
251259
));
252260

261+
if (self::$shardsOutdated) {
262+
$this->output->writeln(' <fg=yellow;options=bold>WARN</> <fg=default>The [tests/.pest/shards.json] file is out of date. Run [--update-shards] to update it.</>');
263+
}
264+
253265
return $exitCode;
254266
}
255267

tests/Arch.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'exec',
2020
'md5',
2121
'unserialize',
22+
'uniqid',
2223
'extract',
2324
'assert',
2425
]);

0 commit comments

Comments
 (0)