Skip to content

fix(test): hold the CLI env lock in every CLI parsing test - #3579

Merged
inureyes merged 2 commits into
mainfrom
fix/cli-tests-env-lock
Nov 30, 2026
Merged

inureyes merged 2 commits into
mainfrom
fix/cli-tests-env-lock

Conversation

@inureyes

Copy link
Copy Markdown
Member

clap reads MLXCEL_* env defaults at parse time, and the ScopedEnv tests in src/main_tests.rs set those variables process-wide while holding CLI_ENV_LOCK. 48 tests parsed the CLI without the lock, so under the default parallel runner they could observe another test's value. During the auto-impl run for #3567 to #3569, settings_cli_mlxcel_serve_defaults_off_and_explicit_flag_enables failed once on GB10 with 0 is not in 1.. because serve_responses_background_ephemeral_ttl_zero_is_refused (added in #2915) had MLXCEL_RESPONSES_BACKGROUND_EPHEMERAL_TTL_SECS=0 set at the same moment.

Changes

  • Every CLI parsing test takes a shared cli_env_lock() helper. The helper recovers from a poisoned lock, so one failing test no longer fails every other lock holder. The 11 existing lock sites use it too.
  • New scan test every_cli_parsing_test_holds_the_env_lock reads main_tests.rs and fails when a #[test] that parses the CLI, directly or through a helper in the file, does not take the lock.

Validation

  • Revert check: removing the lock from one test makes the scan test fail and name that test.
  • cargo test --profile test-fast --features cuda --bin mlxcel: 10 of 10 consecutive default-parallel runs passed (365 passed).
  • cargo clippy --features cuda --bin mlxcel --tests -- -D warnings, cargo fmt --check and the four scripts/ci contract checks pass.

@inureyes inureyes added type:test Test related changes priority:low Low priority area:cli Command-line interface / CLI flags status:review Under review labels Nov 30, 2026
inureyes added a commit that referenced this pull request Nov 30, 2026
clap reads MLXCEL_* env defaults at parse time, and the ScopedEnv tests in src/main_tests.rs set those variables process-wide while holding CLI_ENV_LOCK. 48 tests parsed the CLI without the lock, so under the default parallel test runner they could see another test's value. On GB10, settings_cli_mlxcel_serve_defaults_off_and_explicit_flag_enables failed once because serve_responses_background_ephemeral_ttl_zero_is_refused (#2915) had MLXCEL_RESPONSES_BACKGROUND_EPHEMERAL_TTL_SECS=0 set.

Every CLI parsing test now takes a shared cli_env_lock() helper, which also recovers from a poisoned lock so one failing test no longer fails the other lock holders. The 11 existing lock sites use the same helper. A new scan test, every_cli_parsing_test_holds_the_env_lock, fails when a test that parses the CLI (directly or through a helper in the file) does not take the lock.

Validation: removing the lock from one test makes the scan test fail and name it; cargo test --bin mlxcel passed 10 of 10 consecutive default-parallel runs (365 passed); clippy with -D warnings and fmt are clean.
@inureyes
inureyes force-pushed the fix/cli-tests-env-lock branch from 496e253 to 42a3eef Compare November 30, 2026 02:27
@inureyes
inureyes marked this pull request as ready for review November 30, 2026 02:27
@inureyes
inureyes merged commit 52fa5c7 into main Nov 30, 2026
13 of 15 checks passed
@inureyes
inureyes deleted the fix/cli-tests-env-lock branch November 30, 2026 02:28
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 30, 2026
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Command-line interface / CLI flags priority:low Low priority status:done Completed type:test Test related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant