fix(tests): serialize all env-touching tests on the crate-wide mutex - #12
Merged
Merged
Conversation
`cargo test --lib` failed reliably on a 14-core machine: 20 of 352 tests failed, all cascading from a single race. Three modules opted out of the crate-wide lock in [lib.rs](src/lib.rs#L21). `client` and `secrets` each declared their own module-private `ENV_MUTEX`, so their guards serialized only against tests in the same module. The 17 `client` tests that set `HOME` therefore ran concurrently with the `config`, `run` and `sandbox` tests that the crate-wide mutex serializes; `config::tests::agent_filesystem_paths_resolved` read another test's `HOME`, panicked while holding the crate-wide mutex, and poisoned it for the 19 further tests that `unwrap()` that lock. Four `exec` tests took no lock at all. They compare `build_env()`'s snapshot of the environment against a second `std::env::var` read of the same variable, and `ESSENTIAL_VARS` covers `HOME`, `LANG`, `LC_ALL` and `TZ` — all mutated by `run` tests, so the value could change between the two reads. With every env-touching test on one mutex, 40 consecutive parallel runs pass, so the Nix package no longer needs `dontUseCargoParallelTests`. Claude-Session: https://claude.ai/code/session_01E3R8fS7y8zYjoEzjorYTBJ
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.
cargo test --libfailed reliably on a 14-core machine: 20 of 352 tests failed, all cascading from a single race. Three modules opted out of the crate-wide lock in lib.rs.clientandsecretseach declared their own module-privateENV_MUTEX, so their guards serialized only against tests in the same module. The 17clienttests that setHOMEtherefore ran concurrently with theconfig,runandsandboxtests that the crate-wide mutex serializes;config::tests::agent_filesystem_paths_resolvedread another test'sHOME, panicked while holding the crate-wide mutex, and poisoned it for the 19 further tests thatunwrap()that lock.Four
exectests took no lock at all. They comparebuild_env()'s snapshot of the environment against a secondstd::env::varread of the same variable, andESSENTIAL_VARScoversHOME,LANG,LC_ALLandTZ— all mutated byruntests, so the value could change between the two reads.With every env-touching test on one mutex, 40 consecutive parallel runs pass, so the Nix package no longer needs
dontUseCargoParallelTests.Claude-Session: https://claude.ai/code/session_01E3R8fS7y8zYjoEzjorYTBJ