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
|
|
@ -138,6 +138,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn first_acquire_succeeds_and_releases_on_drop() {
|
||||
// Guards against `hypr`'s env-var test concurrently pointing
|
||||
// XDG_RUNTIME_DIR at a nonexistent path mid-test — see `env_test_lock`.
|
||||
let _lock = crate::env_test_lock().lock().unwrap_or_else(|e| e.into_inner());
|
||||
let app = unique_app("first");
|
||||
match try_acquire(&app).unwrap() {
|
||||
Acquire::Acquired(_guard) => {}
|
||||
|
|
@ -150,6 +153,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn second_acquire_while_first_is_held_reports_held_by_other_with_our_pid() {
|
||||
let _lock = crate::env_test_lock().lock().unwrap_or_else(|e| e.into_inner());
|
||||
let app = unique_app("second");
|
||||
let guard = match try_acquire(&app).unwrap() {
|
||||
Acquire::Acquired(g) => g,
|
||||
|
|
@ -170,6 +174,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn lock_is_released_after_guard_drop_so_a_later_instance_can_acquire() {
|
||||
let _lock = crate::env_test_lock().lock().unwrap_or_else(|e| e.into_inner());
|
||||
let app = unique_app("release");
|
||||
let guard = match try_acquire(&app).unwrap() {
|
||||
Acquire::Acquired(g) => g,
|
||||
|
|
@ -185,6 +190,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn toggle_or_kill_starts_when_nothing_else_is_running() {
|
||||
let _lock = crate::env_test_lock().lock().unwrap_or_else(|e| e.into_inner());
|
||||
let app = unique_app("toggle-start");
|
||||
match toggle_or_kill(&app).unwrap() {
|
||||
Toggle::Started(_guard) => {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue