diff --git a/oxa/oxa-work/src/lib.rs b/oxa/oxa-work/src/lib.rs index c4cf9f48..90023885 100644 --- a/oxa/oxa-work/src/lib.rs +++ b/oxa/oxa-work/src/lib.rs @@ -39,6 +39,10 @@ pub use worker::{WorkerInterruption, WorkerOutcome, WorkerResult, WorkerTokens}; #[path = "../tests/support/private_dir.rs"] mod test_dir; +#[cfg(test)] +#[path = "../tests/support/lock_process.rs"] +mod lock_process; + pub type Result = std::result::Result; // Lead facts consume public observations and never open runner task-state files. diff --git a/oxa/oxa-work/src/queue/native.rs b/oxa/oxa-work/src/queue/native.rs index 59a7ed23..3253c724 100644 --- a/oxa/oxa-work/src/queue/native.rs +++ b/oxa/oxa-work/src/queue/native.rs @@ -222,6 +222,9 @@ mod tests { #[test] fn only_the_exact_durable_whole_task_after_lock_release_settles_the_original_claim() { + if crate::lock_process::in_parent() { + return; + } let (_directory, claims, binding, prepared, policy) = setup(); let owner = NativeQueueOwner { claims: &claims, @@ -271,6 +274,9 @@ mod tests { #[test] fn native_queue_dispatches_one_canonical_attempt_and_settles_before_the_event() { + if crate::lock_process::in_parent() { + return; + } let (directory, claims, binding, prepared, policy) = setup(); let owner = NativeQueueOwner { claims: &claims, diff --git a/oxa/oxa-work/src/shadow.rs b/oxa/oxa-work/src/shadow.rs index 0aaca562..9c72fd1a 100644 --- a/oxa/oxa-work/src/shadow.rs +++ b/oxa/oxa-work/src/shadow.rs @@ -172,6 +172,9 @@ mod tests { #[test] fn admission_replay_rejects_and_open_log_preserves_interrupted_tail_bytes() { + if crate::lock_process::in_parent() { + return; + } let full = snapshot_bytes(); for fragment in [full.as_slice(), &full[..full.len() / 2]] { let dir = path("interrupted-admission"); @@ -202,6 +205,9 @@ mod tests { #[test] fn admission_replay_refuses_multiple_objects_on_one_complete_line() { + if crate::lock_process::in_parent() { + return; + } let journal = path("corrupt-admission"); let snapshot = snapshot_bytes(); let line = [&snapshot[..], &snapshot[..], b"\n"].concat(); diff --git a/oxa/oxa-work/tests/support/lock_process.rs b/oxa/oxa-work/tests/support/lock_process.rs new file mode 100644 index 00000000..e8078c7c --- /dev/null +++ b/oxa/oxa-work/tests/support/lock_process.rs @@ -0,0 +1,33 @@ +//! Isolate drop-and-reopen lock assertions from unrelated libtest forks. + +/// Return after running this exact test in a fresh process, or continue in that child. +pub fn in_parent() -> bool { + const CHILD: &str = "OXA_WORK_LOCK_TEST_CHILD"; + let thread = std::thread::current(); + let name = thread.name().expect("named libtest thread"); + if std::env::var(CHILD).as_deref() == Ok(name) { + return false; + } + + // CLOEXEC closes descriptors at exec, not at fork. A parallel test's + // pre_exec child can retain an unrelated locked file description after its + // last intended owner drops it. Keep the real drop/reacquire assertions, + // but create their locks only after exec, with no other tests in this process. + let mut command = std::process::Command::new(std::env::current_exe().unwrap()); + command + .env_clear() + .env(CHILD, name) + .args(["--exact", name, "--nocapture", "--test-threads=1"]); + if let Some(directory) = std::env::var_os("TMPDIR") { + command.env("TMPDIR", directory); + } + let output = command.output().expect("start isolated lock test"); + let stdout = String::from_utf8_lossy(&output.stdout); + assert!( + output.status.success() && stdout.contains("1 passed; 0 failed;"), + "isolated {name}: {}\n{stdout}\n{}", + output.status, + String::from_utf8_lossy(&output.stderr) + ); + true +}