← 输入框|github.com|刷新
Skip to content

Make ResultCacheManagerCollectedDataTest independent of the second boundary - #6898

Merged
ondrejmirtes merged 1 commit into
2.3.xfrom
fix-collected-data-cache-test-timing
Nov 1, 2026
Merged

ondrejmirtes merged 1 commit into
2.3.xfrom
fix-collected-data-cache-test-timing

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

ResultCacheManagerCollectedDataTest fails intermittently on 2.3.x. On 92a35f5 it failed in both Tests (PHPUnit 11.x (8.2, ubuntu-latest)) and Compile PHAR (Run with Turbo Extension (ubuntu-latest, 8.2, nts, make tests)), in testPartialSaveEqualsFreshSaveOfMergedData. The only difference was the fileStat entries in dependencyGraph: the partial save had a/c signed and the fresh save had none.

Baseline and first bad commit

  • Last all-green baseline: 524520f. Every workflow passed except Benchmark, which also fails on 9c8ed05.
  • 9c8ed05 added the test. Its Tests run passed by luck of timing. 92a35f5 only touches an unrelated fixture and fails on the same timing. Locally, at an unchanged 92a35f5, the test failed in 1 of 30 runs (once also in testWarmSaveCopiesEveryEntryByteForByte).

Root cause (test-only)

  • saveFullAnalysis() restored with one ResultCacheManager and processed/saved with another, so the "fresh" save never had the signatures restore() recorded and always wrote N. In production, the same manager restores and saves.
  • FileStatSignatureReader leaves out signatures of files modified in the second the read began. So the partial and warm saves record signatures only when a second boundary has passed since the files were written.

The fix restores and saves with the same manager and waits until the files are in the past before saving, the same way DirectoryWalkerTest and OptimizedDirectorySourceLocatorFactoryTest do. No src/ change.

Verification

  • A temporary probe that forces a second boundary between the saves fails 3/3 on the old test, fails with either part of the fix alone, and passes 5/5 with both parts.
  • 40/40 unforced runs passed. tests/PHPStan/Analyser/ResultCache and tests/PHPStan/File pass. make cs passes, and PHPStan reports no errors on the file.
  • The change is test-only, so the downgraded PHAR is unaffected.

…undary

saveFullAnalysis() restored the cache with one ResultCacheManager and saved it
with another, so the "fresh" save never had the stat signatures the restore
recorded and always wrote none. The partial and warm saves record them as soon
as the files are older than the second the save begins, so the comparisons
failed whenever a second boundary fell between the saves.

Restore and save with the same manager, and wait until the files are in the
past before saving, like DirectoryWalkerTest and
OptimizedDirectorySourceLocatorFactoryTest do, so every save signs every file.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1976c-1bde-72f8-b96c-072279109d59
@ondrejmirtes
ondrejmirtes merged commit 0932294 into 2.3.x Nov 1, 2026
724 checks passed
@ondrejmirtes
ondrejmirtes deleted the fix-collected-data-cache-test-timing branch November 1, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant