Skip to content

Let the root PSR-4 e2e test start its unchanged-cache run a second after the files were written - #7074

Merged
ondrejmirtes merged 1 commit into
2.3.xfrom
deflake-autoload-entries-root-e2e
Nov 15, 2026
Merged

ondrejmirtes merged 1 commit into
2.3.xfrom
deflake-autoload-entries-root-e2e

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

Class appears under a psr4 namespace mapped to the project root (e2e/result-cache-autoload-entries, added in 603c305a6) fails intermittently. It failed on push ca825b09e (run 43579878816) and on two unrelated PR runs (43591616653, 43648464066). That's 3 failures in about 87 E2E runs since 11-13, and later runs of the same commits' successors pass. The signature is always the same:

✗ Failed: Class appears under a psr4 namespace mapped to the project root
    to contain 'Result cache was not rewritten because it is unchanged.'
    … Result cache restored. 0 files will be reanalysed. … Result cache is saved.

Root cause. The code isn't wrong; the test's timing is. FileStatSignatureReader doesn't vouch for a file modified in the second the run started (the racy-git rule), so it leaves that file's signature out. write_class_consumer writes src/Consumer.php and src/Unrelated.php and runs PHPStan right away. On a fast runner that run sometimes starts in the same second. Then the next run is the first one that can record their signatures, so fileStatSignaturesDiffer() correctly rewrites the cache, and the assertion fails.

Fix. The test waits one second and runs once more before the run that checks the cache is left unchanged. That run still covers what the test is for: PHPStan's own files in the tmpDir under a PSR-4 root don't count as changed scanned files, because the extra run rewrites tmp/resultCache.php right before it. Only the test changes.

Verification (local, bashunit 0.52.0 as in CI):

  • Deterministic reproduction: run write_class_consumer's analyse under faketime pinned to the write second. Without the fix the test fails 3 of 3 times with the CI signature, and with the fix it passes 3 of 3.
  • The whole e2e/result-cache-autoload-entries file passes: 10 tests, 173 assertions.

Shipped code is unchanged, so the downgraded PHAR's PHP 7.4 compatibility is unaffected.

…ter the files were written

A run does not record the stat signature of a file modified in the second
it started, so when write_class_consumer's run started in the second its
files were written, the next run records the signatures and rewrites the
result cache, and 'Result cache was not rewritten because it is unchanged.'
was missing intermittently.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1976c-1bde-72f8-b96c-072279109d59
@ondrejmirtes
ondrejmirtes merged commit c2f6bd9 into 2.3.x Nov 15, 2026
575 of 576 checks passed
@ondrejmirtes
ondrejmirtes deleted the deflake-autoload-entries-root-e2e branch November 15, 2026 08:47
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