Skip to content

Run the test suite in parallel - #225

Merged
simonhamp merged 2 commits into
mainfrom
fix/parallel-tests
Nov 26, 2026
Merged

simonhamp merged 2 commits into
mainfrom
fix/parallel-tests

Conversation

@simonhamp

@simonhamp simonhamp commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

pest --parallel failed 200 to 300 tests a run, a different set each time. Serially everything passes.

Every worker shared storage/. TestCase::tearDown deletes storage/framework/async after each test, so it kept deleting the async spool while a test in another worker was still using it. finishRefreshes() skips a task whose payload has gone, so held refreshes quietly never ran and the test failed on what the screen showed ("Did not see [1 new commit]" and the like). Other tests lost their draft images under storage/app/draft-images, or failed in tearDown itself with FilesystemIterator ... Failed to open directory. When that happened, parent::tearDown() never ran, the test's transaction was left open, and every later test in that worker failed with "cannot start a transaction within a transaction" or "no such table: pending_writes".

What changed in tests/TestCase.php:

  • Under a parallel run, each worker sets LARAVEL_STORAGE_PATH to storage/framework/testing/parallel/{token} before the app boots, so the config built from storage_path() (disks, logs, compiled views) follows it. The directory is emptied and its skeleton created when the worker starts. That folder is already gitignored. A serial run has no TEST_TOKEN and still uses storage/.
  • tearDown calls parent::tearDown() in a finally, so one failed cleanup can't take down the rest of the worker.

The storage change alone is enough to make the parallel run pass. With only the finally change the transaction errors went away but about 160 tests still failed on the shared spool, so those assertion failures were real races and not just fallout from the open transaction.

CI now runs php artisan test --compact --parallel, one worker per CPU on the runner.

Results on this branch: --parallel passed three runs in a row (2434 passed, 12 skipped each, about 11s on 14 processes), and the serial run still passes (2434 passed, 12 skipped, about 85s). Before the change, a parallel run on main had 270 failures.

For review: tests that call app()->useStoragePath() themselves (NataNullers, LogRowCache, LogPageFrames, ImageCache) still win over the per-worker path, because useStoragePath() takes precedence over LARAVEL_STORAGE_PATH. The worker path is read from $_SERVER/getenv() and set up with a plain Filesystem, since it runs before the first app exists.

Screenshots

  • No visible change

🤖 Generated with Claude Code

simonhamp and others added 2 commits November 26, 2026 23:29
Under pest --parallel every worker shared storage/. TestCase::tearDown
deletes storage/framework/async after each test, so it kept deleting the
async spool while a test in another worker was still using it. Held
refreshes then found no payload and quietly never ran, and other tests
lost their draft images or failed in tearDown itself. When tearDown threw
before parent::tearDown(), the open transaction was never rolled back and
every later test in that worker failed with "cannot start a transaction
within a transaction".

Each worker now sets LARAVEL_STORAGE_PATH to
storage/framework/testing/parallel/{token} before the app boots, so the
config built from storage_path() follows it. The directory is emptied
when the worker starts. A serial run still uses storage/.

tearDown also calls parent::tearDown() in a finally block, so one failed
cleanup can't take down the rest of the worker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each worker now has its own storage directory, so the suite passes
in parallel. Locally it takes about 10 seconds instead of 85.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp simonhamp changed the title Give each parallel test worker its own storage directory Run the test suite in parallel Nov 26, 2026
@simonhamp
simonhamp marked this pull request as ready for review November 26, 2026 23:36
@simonhamp
simonhamp merged commit 8256149 into main Nov 26, 2026
5 checks passed
@simonhamp
simonhamp deleted the fix/parallel-tests branch November 26, 2026 23:37
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.

1 participant