diff --git a/src/Instrument/ClassLoading/CacheWarmer.php b/src/Instrument/ClassLoading/CacheWarmer.php index eff2d79f..fe1450ba 100644 --- a/src/Instrument/ClassLoading/CacheWarmer.php +++ b/src/Instrument/ClassLoading/CacheWarmer.php @@ -110,6 +110,9 @@ private function weaveApplication(): int // One walk of the application tree: the collected list is counted and then processed $enumerator = new Enumerator($options['appDir'], $options['includePaths'], $options['excludePaths']); $files = iterator_to_array($enumerator->enumerate(), false); + // In path order: the file system lists a directory in any order, which differs between machines. + // Sorted, every run weaves the files in the same order, and with fail-fast stops on the same file + usort($files, static fn(SplFileInfo $left, SplFileInfo $right): int => strcmp($left->getPathname(), $right->getPathname())); // No more workers than files; without a command line to start them, the files are woven here $workers = $this->workerCommandLine !== [] ? max(1, min($this->workers, count($files))) : 1; @@ -174,7 +177,8 @@ private function warmUpInWorkers(array $files, int $workers, WarmupReporter $rep // Loads every aspect once, which writes their advisor caches before the workers need them $container->getService(AdvisorIndex::class)->getAdvisors(); - // Largest files first: they take longest, and the small ones left for the end even out the workers + // Largest files first: they take longest, and the small ones left for the end even out the workers. + // The sort is stable: files of the same size stay in path order usort($files, static fn(SplFileInfo $left, SplFileInfo $right): int => $right->getSize() <=> $left->getSize()); $paths = array_map(self::pathOf(...), $files); diff --git a/tests/Instrument/ClassLoading/CacheWarmerTest.php b/tests/Instrument/ClassLoading/CacheWarmerTest.php index b5b4328d..57ca610d 100644 --- a/tests/Instrument/ClassLoading/CacheWarmerTest.php +++ b/tests/Instrument/ClassLoading/CacheWarmerTest.php @@ -424,7 +424,8 @@ public function testWarmUpReportsErrorsToErrorOutputAndReturnsTheirCount(): void public function testFailFastStopsAfterFirstError(): void { - // Two broken files: whichever comes first, the warmer stops before the second one + // Next to the valid Some.php from setUp(), two broken files. Files are woven in path order, whatever order + // the file system lists them in: AlsoBroken.php fails first, and the warmer stops before the other two file_put_contents($this->appDir . '/src/Broken.php', "appDir . '/src/AlsoBroken.php', "assertSame(1, $warmer->warmUp()); $display = $output->fetch(); $this->assertStringContainsString('[STOP]: Warmup was interrupted, stopping...', $display); + $this->assertStringContainsString('AlsoBroken.php: Cannot weave file', $display); + $this->assertDoesNotMatchRegularExpression('#[/\\\\]Broken\.php: Cannot weave#', $display); $this->assertStringContainsString('Total processed 1, 1 errors in ', $display); } }