Skip to content

[13.x] Make the parallel compiled view callbacks tolerate a concurrent run - #61786

Merged
taylorotwell merged 2 commits into
laravel:13.xfrom
joshdaugherty:fix/parallel-compiled-view-race
Sep 29, 2026
Merged

taylorotwell merged 2 commits into
laravel:13.xfrom
joshdaugherty:fix/parallel-compiled-view-race

Conversation

@joshdaugherty

Copy link
Copy Markdown

Fixes #61785.

TestViews gives each parallel worker a compiled view directory named after ParallelTesting::token(), the worker index. Two parallel runs of the same project at the same time therefore use the same directories, and both process callbacks that manage them fail when the other run acts between their check and their action:

  • setUpProcess: File::ensureDirectoryExists() checks isDirectory() and then calls mkdir() without suppression, so the run that loses fails with mkdir(): File exists.
  • tearDownProcess: File::deleteDirectory() checks isDirectory() and then constructs a FilesystemIterator, which throws UnexpectedValueException when the directory is already gone.

This changes only those two callbacks:

  • The set-up callback creates the directory with makeDirectory(..., force: true), which does not fail when the directory already exists.
  • The tear-down callback treats a directory that disappeared as already deleted.

It does not change what token() returns or where the compiled views go, so a single parallel run behaves exactly as before.

Tests

Two tests are added to TestViewsTest. Each replaces the files binding with a Filesystem whose isDirectory() answers as it would have just before the other run acted, while the real directory is in the other run's state. The race therefore happens every time, not by chance:

  • The directory already exists, but isDirectory() says it does not. Set-up must not raise a warning.
  • The directory is already gone, but isDirectory() says it exists. Tear-down must not throw.

Against the current 13.x implementation, both tests fail: the first with ErrorException: mkdir(): File exists, and the second with UnexpectedValueException from FilesystemIterator. With this change they pass, and tests/Testing passes (414 tests). Run on PHP 8.4, Windows 11.

@taylorotwell
taylorotwell merged commit 6070a6d into laravel:13.x Sep 29, 2026
48 checks passed
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.

Concurrent parallel test runs fail on the shared compiled view directory

2 participants