Skip to content

test: serialise process-environment tests behind a shared guard - #100

Merged
ekhodzitsky merged 1 commit into
masterfrom
fix/env-test-isolation
Sep 26, 2026
Merged

ekhodzitsky merged 1 commit into
masterfrom
fix/env-test-isolation

Conversation

@ekhodzitsky

Copy link
Copy Markdown
Owner

Problem

Unit tests that set POLYVOICE_* overrides raced under the default multi-threaded cargo test harness. The missing-cohort case observed the cohort path set by the concurrent env-override case (about one filtered run in four locally). The comments assumed nextest process isolation, and the CI local-pipeline job hid the race with --test-threads=1.

Change

  • New crate-level test-only module src/test_env.rs: one global mutex plus an RAII guard whose set/remove record the prior value of every variable they touch and restore it on drop, so a caller's shell environment survives the run.
  • Every env-mutating unit test (VBx knob overlays in clusterer_factory and vbx_tests, PLDA-dir and AS-norm cohort overrides in builder_tests) now goes through the guard. The offline-failure and registry-only cases clear the override under the lock so an inherited variable cannot flip their outcome.
  • CI: the pipeline-local,vbx lib run drops --test-threads=1 so the parallel harness exercises the fix.

Verification

  • Before: 7/30 filtered parallel runs of the load_as_norm_cohort* tests failed.
  • After: 40/40 filtered and 10/10 full parallel runs of the pipeline-local,vbx lib suite green (876 tests); cli-native lib suite green (922 tests).
  • cargo nextest run on the env tests: 8/8.
  • cargo clippy -D warnings clean on cli, cli-native, pipeline-local,vbx, clusterer,vbx, and no-default feature sets. --all-features is not buildable on the local host (no OpenBLAS) and is left to CI.

Unit tests that set POLYVOICE_* overrides raced under the default
multi-threaded cargo test harness: the missing-cohort case observed the
cohort set by the concurrent env-override case (about one run in four on
the filtered suite). The comments assumed nextest process isolation, and
the CI local-pipeline job papered over it with --test-threads=1.

Add a crate-level test-only guard: one global mutex plus RAII undo that
records the prior value of every variable it touches and restores it on
drop, so a caller's shell environment survives the run. Route every
env-mutating unit test and the env-reading tests they race with through
it; the offline-failure cases clear the override under the lock so an
inherited variable cannot flip them. Drop the single-thread workaround
from CI so the parallel harness exercises the fix.

Verified: 40/40 filtered and 10/10 full parallel runs of the
pipeline-local+vbx lib suite, the cli-native lib suite, nextest on the
env tests, clippy -D warnings on the touched feature sets.
@ekhodzitsky
ekhodzitsky merged commit da3470e into master Sep 26, 2026
49 checks passed
@ekhodzitsky
ekhodzitsky deleted the fix/env-test-isolation branch September 26, 2026 15:59
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