Run Nx integration tests sequentially to prevent shared-sandbox race condition#380
Merged
rhoerr merged 1 commit intoMay 27, 2026
Conversation
When Nx runs multiple affected projects in parallel (default --parallel=3), each project's PHPUnit bootstrap runs concurrently inside the same Warden php-fpm container, sharing the same filesystem. This causes two classes of race condition: 1. Both bootstraps call deployTestModules.php simultaneously, each removing and re-copying to app/code/Magento/TestModule*/ at the same time. 2. Both bootstraps call setup:install, which creates a sandbox directory under dev/tests/integration/tmp/ keyed by a SHA-256 hash of the install config. Since both targets share the same phpunit.xml.dist and install-config-mysql.php, they produce an identical sandbox path. The second process to arrive fails with "mkdir(): File exists", which the PHPUnit error handler converts to a fatal exception that crashes the bootstrap before any tests run. Setting --parallel=1 makes Nx execute test targets sequentially, eliminating the shared-state conflicts. The tradeoff is longer wall-clock time when multiple packages are affected, but the tests were failing entirely without this change so reliability wins over speed.
4 tasks
rhoerr
approved these changes
May 27, 2026
Contributor
rhoerr
left a comment
There was a problem hiding this comment.
Thank you. Seems plausible and safe. Merging to try it on mage-os/mageos-magento2#213 .
thebraziliandeveloper
added a commit
to thebraziliandeveloper/mageos-magento2
that referenced
this pull request
May 27, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When Nx runs multiple affected projects in parallel (default
--parallel=3), each project's PHPUnit bootstrap runs concurrently inside the same Wardenphp-fpmcontainer, sharing the same bind-mounted filesystem. This produces two classes of race condition that crash the integration test bootstrap before any tests execute:1.
deployTestModules.phpconflictsBoth bootstraps call
deployTestModules.phpsimultaneously. Each process removes and re-copies toapp/code/Magento/TestModule*/at the same time — one process deletes directories the other just created, or twomkdir()calls collide on the same path, triggering a"File exists"PHP warning that the integration test error handler converts into a fatalPHPUnit\Framework\Exception.2. Shared sandbox directory conflict
Both bootstraps call
setup:installviaMagento\TestFramework\Application::install(), which creates a sandbox directory under:Because both targets share the same
phpunit.xml.distandinstall-config-mysql.php, they compute an identical sandbox path. The second process to callmkdir()on that path fails with"File exists", again converted to a fatal bootstrap exception.Fix
Add
--parallel=1to thenx affectedcommand so test targets execute sequentially:Trade-off
Sequential execution increases wall-clock time when multiple packages are affected simultaneously. However:
A longer-term fix would give each test target a distinct install config (different DB name), producing unique sandbox paths and eliminating the shared-state problem while restoring parallelism.
Related
Follows #379 (cache key fix, already merged).
🤖 Generated with Claude Code