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,7 +25,15 @@ fn home_or_root() -> PathBuf {
|
|||
/// `$XDG_CONFIG_HOME` (only if it's set to an absolute path) or `~/.config`,
|
||||
/// joined with `app`.
|
||||
pub fn config_dir(app: &str) -> PathBuf {
|
||||
base_config_dir().join(app)
|
||||
config_home().join(app)
|
||||
}
|
||||
|
||||
/// The bare `$XDG_CONFIG_HOME` (or `~/.config`) directory, with no app name
|
||||
/// joined on — for callers that build up multiple sub-paths themselves
|
||||
/// (e.g. `bos-settings`, which joins a different bread* app's name per
|
||||
/// config file it edits).
|
||||
pub fn config_home() -> PathBuf {
|
||||
base_config_dir()
|
||||
}
|
||||
|
||||
/// `$XDG_DATA_HOME` (only if absolute) or `~/.local/share`, joined with `app`.
|
||||
|
|
@ -88,6 +96,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn runtime_dir_falls_back_to_tmp() {
|
||||
let _lock = crate::env_test_lock().lock().unwrap_or_else(|e| e.into_inner());
|
||||
// We don't unset XDG_RUNTIME_DIR here (test isolation), just confirm
|
||||
// the function returns *something* absolute either way.
|
||||
assert!(runtime_dir().is_absolute());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue