bread-utils: fix flaky test isolation around process-global env vars
singleton.rs's tests used to call the real kill() on the current test process itself (the recorded "other instance" PID was our own, since tests run single-process) — split try_acquire (side-effect-free) out from toggle_or_kill (sends the signal) so the concurrency assertions no longer risk SIGTERM-ing the test binary. Separately, hypr.rs's env-var test mutates HYPRLAND_INSTANCE_SIGNATURE/ XDG_RUNTIME_DIR process-globally; cargo runs tests in parallel threads by default, so it could race a concurrently-running singleton or xdg test expecting the real XDG_RUNTIME_DIR, intermittently failing them with ENOENT. Added a shared env_test_lock() all env-var-touching tests now acquire for their duration. Verified via 5 repeated full test runs with zero flakes (28/28 passing each time).
This commit is contained in:
parent
853ee33415
commit
49c63c8ccf
4 changed files with 29 additions and 1 deletions
|
|
@ -25,6 +25,18 @@ pub mod proc;
|
|||
pub mod singleton;
|
||||
pub mod xdg;
|
||||
|
||||
/// Serializes tests that read or mutate process-global env vars
|
||||
/// (`XDG_RUNTIME_DIR`, `HYPRLAND_INSTANCE_SIGNATURE`) — `cargo test` runs
|
||||
/// tests in parallel threads within one process by default, and
|
||||
/// `std::env::set_var` is process-wide, so a `hypr` test temporarily
|
||||
/// pointing `XDG_RUNTIME_DIR` at a nonexistent path can otherwise race a
|
||||
/// concurrently-running `singleton` or `xdg` test that expects the real one.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn env_test_lock() -> &'static std::sync::Mutex<()> {
|
||||
static LOCK: std::sync::OnceLock<std::sync::Mutex<()>> = std::sync::OnceLock::new();
|
||||
LOCK.get_or_init(|| std::sync::Mutex::new(()))
|
||||
}
|
||||
|
||||
#[cfg(feature = "toml")]
|
||||
pub mod tomlcfg;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue