From e161afd0c726c508e5f92089c9a598ff6b5ff3a1 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Mon, 16 Nov 2026 08:41:51 +0000 Subject: [PATCH] Wait on the clock that timestamps writes in ResultCacheManagerCollectedDataTest 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 --- .../ResultCacheManagerCollectedDataTest.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/PHPStan/Analyser/ResultCache/ResultCacheManagerCollectedDataTest.php b/tests/PHPStan/Analyser/ResultCache/ResultCacheManagerCollectedDataTest.php index 291e9ded834..8a998a35f24 100644 --- a/tests/PHPStan/Analyser/ResultCache/ResultCacheManagerCollectedDataTest.php +++ b/tests/PHPStan/Analyser/ResultCache/ResultCacheManagerCollectedDataTest.php @@ -51,7 +51,6 @@ use function strpos; use function substr; use function sys_get_temp_dir; -use function time; use function uniqid; use function unlink; use function usleep; @@ -379,6 +378,10 @@ public function testNoFilesChangedDuringTheAnalysis(): void /** * A save keeps the stat signature only of a file not modified in the second the save began, * so without waiting, saves on both sides of a second boundary differ in their signatures. + * + * Waits on the clock that timestamps writes, not on time(): right after a second boundary a + * write can still be timestamped with the second before, so a file written as soon as time() + * moves on could keep the signature it had. */ private function waitUntilTheFilesAreInThePast(): void { @@ -390,9 +393,20 @@ private function waitUntilTheFilesAreInThePast(): void $latest = max($latest, $stat['mtime'], $stat['ctime']); } - while (time() <= $latest) { + // outside src/, like the cache file, so it is not a scanned file + $probe = $this->directory . '/clock-probe'; + while (true) { + file_put_contents($probe, ''); + clearstatcache(); + $stat = stat($probe); + $this->assertIsArray($stat); + if ($stat['mtime'] > $latest) { + break; + } + usleep(50_000); } + unlink($probe); } /**