mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
fix(tia): memoize the merged baseline so replay stays linear (#1974)
Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com> Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com>
This commit is contained in:
@@ -62,6 +62,11 @@ final class Graph
|
||||
|
||||
private string $fallbackBranch = 'main';
|
||||
|
||||
/**
|
||||
* @var array<string, array{0: array{sha: ?string, tree: array<string, string>, complete?: bool, results: array<string, array{status: int, message: string, time: float, assertions?: int, file?: string}>}, 1: array{sha: ?string, tree: array<string, string>, complete?: bool, results: array<string, array{status: int, message: string, time: float, assertions?: int, file?: string}>}, 2: array{sha: ?string, tree: array<string, string>, complete?: bool, results: array<string, array{status: int, message: string, time: float, assertions?: int, file?: string}>}}>
|
||||
*/
|
||||
private array $mergedBaselines = [];
|
||||
|
||||
private readonly string $projectRoot;
|
||||
|
||||
/** @var array<string, true>|null */
|
||||
@@ -976,15 +981,26 @@ final class Graph
|
||||
return $own;
|
||||
}
|
||||
|
||||
$key = $branch."\0".$fallbackBranch;
|
||||
$memo = $this->mergedBaselines[$key] ?? null;
|
||||
|
||||
if ($memo !== null && $memo[0] === $own && $memo[1] === $fallback) {
|
||||
return $memo[2];
|
||||
}
|
||||
|
||||
$under = ($own['complete'] ?? false) === true
|
||||
? $this->withoutFilesCoveredBy($fallback['results'], $own['results'])
|
||||
: $fallback['results'];
|
||||
|
||||
return [
|
||||
$merged = [
|
||||
'sha' => $own['sha'] ?? $fallback['sha'],
|
||||
'tree' => $own['tree'] !== [] ? $own['tree'] : $fallback['tree'],
|
||||
'results' => array_replace($under, $own['results']),
|
||||
];
|
||||
|
||||
$this->mergedBaselines[$key] = [$own, $fallback, $merged];
|
||||
|
||||
return $merged;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1984,6 +1984,7 @@
|
||||
✓ markKnownTestFiles() → it does not clobber edges of an already-known test file
|
||||
✓ markKnownTestFiles() → it ignores paths outside the project root
|
||||
✓ clearResults() → it drops the results of the fallback branch too
|
||||
✓ branch baseline over the fallback → it reads results written after an earlier read
|
||||
|
||||
PASS Tests\Unit\Plugins\Tia\IsEnabledForRun
|
||||
✓ does not throw when an integer --random-order-seed is passed as a separate argv element
|
||||
@@ -2346,4 +2347,4 @@
|
||||
✓ pass with dataset with ('my-datas-set-value')
|
||||
✓ within describe → pass with dataset with ('my-datas-set-value')
|
||||
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1665 passed (3701 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1666 passed (3706 assertions)
|
||||
@@ -326,3 +326,23 @@ describe('clearResults()', function (): void {
|
||||
->and($graph->getResult('main', 'Tests\FooTest::it passes'))->toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('branch baseline over the fallback', function (): void {
|
||||
it('reads results written after an earlier read', function (): void {
|
||||
$graph = new Graph(sys_get_temp_dir());
|
||||
$graph->setResult('main', 'Tests\FooTest::it passes', 0, '', 0.1, 1, 'tests/Feature/FooTest.php');
|
||||
$graph->setResult('main', 'Tests\BarTest::it passes', 0, '', 0.2, 1, 'tests/Feature/BarTest.php');
|
||||
$graph->setResult('feature', 'Tests\FooTest::it passes', 0, '', 0.3, 1, 'tests/Feature/FooTest.php');
|
||||
$graph->markBaselineComplete('feature');
|
||||
|
||||
expect($graph->getTime('feature', 'Tests\FooTest::it passes', 'main'))->toBe(0.3)
|
||||
->and($graph->getTime('feature', 'Tests\BarTest::it passes', 'main'))->toBe(0.2);
|
||||
|
||||
$graph->setResult('feature', 'Tests\FooTest::it passes', 7, 'boom', 0.4, 1, 'tests/Feature/FooTest.php');
|
||||
$graph->setResult('main', 'Tests\BarTest::it passes', 0, '', 0.5, 1, 'tests/Feature/BarTest.php');
|
||||
|
||||
expect($graph->getTime('feature', 'Tests\FooTest::it passes', 'main'))->toBe(0.4)
|
||||
->and($graph->getResult('feature', 'Tests\FooTest::it passes', 'main')?->isFailure())->toBeTrue()
|
||||
->and($graph->getTime('feature', 'Tests\BarTest::it passes', 'main'))->toBe(0.5);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,7 +21,7 @@ test('parallel', function () use ($run): void {
|
||||
$output = implode("\n", array_slice(explode("\n", (string) $output), -10));
|
||||
$profileOutput = $run('tests/Fixtures/Suites/SuccessOnly.php', '--profile');
|
||||
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1636 passed (3623 assertions)';
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1637 passed (3628 assertions)';
|
||||
|
||||
expect($output)
|
||||
->toContain("Tests: {$expected}")
|
||||
|
||||
Reference in New Issue
Block a user