Repository navigation
Wait on the clock that timestamps writes in ResultCacheManagerCollectedDataTest - #7089
Merged
Merged
Conversation
…edDataTest Right after a second boundary a write can still be timestamped with the second before, so waitUntilTheFilesAreInThePast() returning as soon as time() moved on let testFileChangedAndChangedBackDuringTheAnalysisIsAnalysedAgain write the file back with the signature it was hashed with. Amp-Thread-ID: https://ampcode.com/threads/T-01a1976c-1bde-72f8-b96c-072279109d59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ResultCacheManagerCollectedDataTest::testFileChangedAndChangedBackDuringTheAnalysisIsAnalysedAgainfails intermittently at line 354. The getFilesChangedDuringAnalysis() result comes back as[]instead of the changed file. It failed on 2.3.x HEAD02480d849in Compile PHAR'sRun with Turbo Extension (windows-latest, 8.2, nts, make tests)(job 132884291961), and every other check on that commit passed. It also failed once in a local full-suite run, and about 1 in 10 local runs of the single test.Root cause (test only).
waitUntilTheFilesAreInThePast()waits untiltime()passes the files' latest mtime. But writes are timestamped with the kernel's coarse clock, which right after a second boundary can still read the previous second for a few milliseconds. In this sandbox, a write made as soon astime()ticked over was stamped with the earlier second 40 of 40 times. When the helper's 50 ms poll wakes inside that window, the test writes the file back in what should be a later second. The file gets back its old size, mtime, ctime, inode and device, and so the very stat signaturerestore()hashed it with. The manager is then right to see nothing changed.Fix. The helper now waits on the clock that timestamps writes. It rewrites a probe file next to
src/(outside the scanned directory, like the cache file) until its mtime passes the files' latest timestamp. The now-unusedtimeimport is removed.Verification
tests/PHPStan/Analyser/ResultCachepasses (34 tests). phpcs and PHPStan report no errors on the file.A related note for the maintainer, not changed here:
ResultCacheManager::hashAnalysedFiles()andFileStatSignatures::begin()also take "now" fromtime(). A file written in the first milliseconds of a second can be stamped with the second before, so it is not treated as racy even though it was written after the run began. The window is a few milliseconds and needs a same-size rewrite, but if it matters, a reference timestamp taken from the file system (as git does from its index file) would close it.Shipped code is unchanged, so the downgraded PHAR's PHP 7.4 compatibility is unaffected.