Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Instrument/ClassLoading/CacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion tests/Instrument/ClassLoading/CacheWarmerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', "<?php // broken\n");
file_put_contents($this->appDir . '/src/AlsoBroken.php', "<?php // broken\n");

Expand All @@ -435,6 +436,8 @@ public function testFailFastStopsAfterFirstError(): void
$this->assertSame(1, $warmer->warmUp());
$display = $output->fetch();
$this->assertStringContainsString('[STOP]: Warmup was interrupted, stopping...', $display);
$this->assertStringContainsString('AlsoBroken.php: Cannot weave <broken> file', $display);
$this->assertDoesNotMatchRegularExpression('#[/\\\\]Broken\.php: Cannot weave#', $display);
$this->assertStringContainsString('Total processed 1, 1 errors in ', $display);
}
}
Loading