use crate::test_child::{
assert_no_child_of_this_thread, has_not_exited, held_uncontained_blocker, is_unreaped_child, wait_until_zombie,
Console,
};
#[skuld::test]
fn a_waited_root_stays_a_zombie_until_its_handle_drops() {
let (child, writer) = held_uncontained_blocker(true);
let pid = child.pid();
drop(writer);
child.wait().expect("wait");
assert!(is_unreaped_child(pid), "the wait consumed the root's exit record");
drop(child);
assert!(!is_unreaped_child(pid), "the drop left the root a zombie");
}
#[cfg(target_os = "linux")]
#[skuld::test]
fn a_disarmed_drop_of_an_exited_child_the_wait_never_saw_reaps_it() {
let (child, writer) = held_uncontained_blocker(false);
let pid = child.pid();
drop(writer);
wait_until_zombie(pid);
assert!(is_unreaped_child(pid), "the test's own wait consumed the exit record");
drop(child);
assert!(
!is_unreaped_child(pid),
"the disarmed drop left the exited root a zombie"
);
}
#[cfg(target_os = "macos")]
#[skuld::test]
fn a_disarmed_drop_of_an_exited_child_the_wait_never_saw_leaves_it_to_the_application() {
let (child, writer) = held_uncontained_blocker(false);
let pid = child.pid();
drop(writer);
wait_until_zombie(pid);
assert!(is_unreaped_child(pid), "the test's own wait consumed the exit record");
drop(child);
assert!(is_unreaped_child(pid), "the drop consumed by number what no wait saw");
crate::test_child::reaped_elsewhere::reap_behind(pid);
}
#[skuld::test]
fn a_disarmed_drop_of_a_running_child_leaves_it_running() {
let (child, writer) = held_uncontained_blocker(false);
let pid = child.pid();
drop(child);
assert!(is_unreaped_child(pid), "the root is still ours");
assert!(has_not_exited(pid), "the root was killed or waited for");
drop(writer);
crate::test_child::reaped_elsewhere::reap_behind(pid);
}
#[skuld::test]
fn status_with_kill_on_drop_false_leaves_no_zombie() {
assert_no_child_of_this_thread("the test starts with no child");
let mut cmd = crate::test_child::command(Console::Hidden);
cmd.args(["true"]);
cmd.kill_on_drop(false);
let status = cmd.status().expect("status");
assert!(status.success(), "{status:?}");
assert_no_child_of_this_thread("status left its child a zombie");
}