[12.x] Isolate compiled views per process during parallel testing#58390
Conversation
2712580 to
8fb80e8
Compare
|
@dxnter sorry for the silly question, but I'm wondering if this issue is resolved if |
Logically that makes sense, and a commenter on the issue brought that up. In their case, that didn't fix the failures.
Because of that, there's no way to pre-compile these templates. They don't exist on disk until the component renders for the first time, which is where the parallel testing issues come in. There are also a few other scenarios where views can't be pre-compiled:
Footnotes |
Yeah I believe I made that comment and changed my build script thinking caching views prior to parallel execution would help, but it didn't. - name: Pregenerate View Cache
run: php artisan view:cacheI thought because every single Livewire component render method was just calling public function placeholder(): string
{
return '<div class="flex justify-center p-6"><flux:icon.loading /></div>';
}Haven't dug as far as you to be sure. I did adapt our CI to export view caches during failures to see if I can help track it further, but knowing I'm Livewire/Flux - it may be something in that realm. |
|
@dxnter Nice solution! This resolves my issue 🙏 One possible concern is that cached views are not cleared after the tests finish, and view:clear does not remove subdirectories. I am not sure whether this has any practical implications, though. |
Fixes #58378
Overview
Addressing race conditions that can occur when running tests in parallel. I originally approached this issue with updates to the
CompilerEngineandBladeCompilerin #58381, but I closed that since it was starting to involve too many changes.Problem
When running parallel tests, multiple processes compile and read Blade views from the same directory simultaneously. This causes several types of failures:
FileNotFoundExceptionwhen a compiled view is deleted by another process before it can be readParseErrorby reading a partially-written compiled view file (file_put_contents()is not atomic)RootTagMissingFromViewExceptionwhen inline component templates are truncatedNone of these are deterministic and can be difficult to reproduce, but become increasingly common as the number of parallel processes increases.
Solution
Following a similar pattern that's used for database isolation (
TestDatabases), this PR introduces aTestViewstrait that isolates compiled views per test process. Each parallel process now uses its own subdirectory.This completely eliminates race conditions since processes no longer share compiled view files.