Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions oxa/oxa-work/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = std::result::Result<T, String>;

// Lead facts consume public observations and never open runner task-state files.
Expand Down
6 changes: 6 additions & 0 deletions oxa/oxa-work/src/queue/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions oxa/oxa-work/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down
33 changes: 33 additions & 0 deletions oxa/oxa-work/tests/support/lock_process.rs
Original file line number Diff line number Diff line change
@@ -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
}
Loading