Repository navigation
perf(xtask): use RwLock for CWD_LOCK so spawning tests run in parallel (#2124) - #2132
Conversation
#2124) The CWD_LOCK was a single Mutex<()>. Every subprocess-spawning test (14 in run.rs) AND every cwd-manipulating test (with_temp_cwd, with_repo_cwd) acquired the SAME exclusive lock. This meant: - Two spawning tests could not run in parallel (they only need to exclude cwd-manipulating tests, not each other). - The 109s policy_checker_facade_runs_current_repo_checks test blocked every other spawning test behind the mutex. ## Change Replace Mutex<()> with RwLock<()>: - acquire_test_cwd_write_guard() -> RwLockWriteGuard (exclusive) Used by with_temp_cwd and with_repo_cwd — the tests that actually change the process cwd and delete temp dirs. - acquire_test_cwd_read_guard() -> RwLockReadGuard (shared) Used by all 14 spawning tests in run.rs — they inherit the process cwd but don't change it, so they can run in parallel with each other. They are only excluded while a cwd-manipulating test holds the write guard. This restores parallelism for the spawning-test lane while keeping the race fix (#2044) intact: a spawning test and a cwd-manipulating test can never run concurrently. ## Renamed - acquire_test_cwd_lock() -> split into acquire_test_cwd_write_guard() and acquire_test_cwd_read_guard() so the caller's intent is explicit. Verified: cargo check -p xtask --all-targets PASS cargo test -p xtask PASS (1204 tests, 0 failures, 114s) cargo clippy -p xtask -D warnings PASS cargo xtask check-no-panic-family PASS (0 stale, 0 unallowed) Closes #2124.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
Summary by CodeRabbit
WalkthroughThe test CWD lock changes from ChangesCWD test synchronization
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.44.1)xtask/src/main.rsast-grep timed out on this file Comment |
There was a problem hiding this comment.
Code Review
This pull request updates the test suite in xtask/src/run.rs by replacing the exclusive acquire_test_cwd_lock with acquire_test_cwd_read_guard across multiple test cases. This change allows tests that do not modify the current working directory to run concurrently using a shared read lock. There are no review comments, and I have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Problem (#2124)
The
CWD_LOCKadded in #2051 was a singleMutex<()>. Every subprocess-spawning test (14 inrun.rs) AND every cwd-manipulating test (with_temp_cwd,with_repo_cwd) acquired the SAME exclusive lock. This meant:policy_checker_facade_runs_current_repo_checkstest blocked every other spawning test behind the mutex.The current wall-clock impact is acceptable (
rust-tests-juniton main finishes in 4-6 minutes), but the over-serialisation is unnecessary.Change
Replace
Mutex<()>withRwLock<()>:with_temp_cwdandwith_repo_cwdinmain.rsuse the write guard (they change the process cwd and delete temp dirs).run.rsuse the read guard (they inherit the process cwd but don't change it, so they can run in parallel with each other).This restores parallelism for the spawning-test lane while keeping the race fix (#2044) intact: a spawning test and a cwd-manipulating test can never run concurrently (read excludes write).
Why RwLock and not two separate Mutexes?
A two-mutex approach (one for cwd, one for spawn) would NOT close the race — the spawning test needs to be excluded from the cwd-manipulating test's
set_current_dir/remove_dir_allwindow, and vice versa.RwLockis the standard primitive for "multiple readers OR one writer, never both" — exactly this access pattern.Evidence
The 1204-test suite passes with no flakes across the full parallel run — the race #2044 fixed is genuinely closed by the read/write exclusion, not by the global mutex.
Scope
Two-file change:
xtask/src/main.rs:CWD_LOCKtype changed fromMutextoRwLock;acquire_test_cwd_locksplit intoacquire_test_cwd_write_guard+acquire_test_cwd_read_guard;with_temp_cwdandwith_repo_cwdupdated to use the write guard.xtask/src/run.rs: import updated; all 14 spawning tests updated to use the read guard.No production code change. No behavior change for the test outcomes — only the parallelism model. Closes #2124.
Non-goals