nix-rust/nix

Run tests in processes rather than threads with `cargo nextest`

Closed this issue · 2 comments

Some tests modify process-wide stuff like signal handler, so we use these locks

nix/test/test.rs

Lines 63 to 80 in 70f8fe0

/// Any test that creates child processes or can be affected by child processes
/// must grab this mutex, regardless of what it does with those children.
///
/// It must hold the mutex until the child processes are waited upon.
pub static FORK_MTX: Mutex<()> = Mutex::new(());
/// Any test that changes the process's current working directory must grab
/// the RwLock exclusively. Any process that cares about the current
/// working directory must grab it shared.
pub static CWD_LOCK: RwLock<()> = RwLock::new(());
/// Any test that changes the process's supplementary groups must grab this
/// mutex
pub static GROUPS_MTX: Mutex<()> = Mutex::new(());
/// Any tests that loads or unloads kernel modules must grab this mutex
pub static KMOD_MTX: Mutex<()> = Mutex::new(());
/// Any test that calls ptsname(3) must grab this mutex.
pub static PTSNAME_MTX: Mutex<()> = Mutex::new(());
/// Any test that alters signal handling must grab this mutex.
pub static SIGNAL_MTX: Mutex<()> = Mutex::new(());

to sequentialize them, TIL that cargo nextest will run tests in processes rather than threads, perhaps this can help us get rid of these locks and potentially fixes some weird test failures.

cargo-nextest is cool, but I don't think that we should rely on it. Even if we use it during CI, we should also ensure that "cargo test" works too.

we should also ensure that "cargo test" works too.

Makes sense, closing the issue.