use std::time::Duration;
use super::{StopTarget, TreeCall};
use crate::os_process::fake::FakeProcess;
use crate::test_child::over_fake::child_over;
#[skuld::test]
fn a_root_target_stands_for_the_root_and_a_tree_target_for_the_tree() {
let child = child_over(&FakeProcess::new([]));
let root = StopTarget::from(&child);
let tree = StopTarget::tree(&child, TreeCall::SignalOnly);
for target in [&root, &tree] {
assert_eq!(target.pid(), child.pid());
assert_eq!(target.id(), child.id());
}
assert!(!root.covers_tree());
assert!(tree.covers_tree());
}
#[skuld::test]
fn a_refused_send_replaces_the_record_of_an_earlier_one() {
use super::{RootRecord, TreeRecord};
let refusal = || crate::error::Error::Unsupported {
op: "the test".into(),
platform: "test",
detail: "refused by the test".into(),
source: None,
};
let child = child_over(&FakeProcess::new([]));
let root = StopTarget::from(&child);
root.note_root_went_out("SIGTEST");
assert!(matches!(
&*root.root_record.lock().unwrap(),
Some(RootRecord::Sent("SIGTEST"))
));
root.note_refused(&refusal());
assert!(
matches!(root.into_root_record(), Some(RootRecord::Refused(report)) if report.contains("refused by the test"))
);
let tree = StopTarget::tree(&child, TreeCall::SignalOnly);
tree.note_tree(TreeRecord::Sent {
earlier: None,
walk: None,
});
tree.note_refused(&refusal());
assert!(
matches!(tree.into_tree_record(), Some(TreeRecord::NotSent(report)) if report.contains("refused by the test"))
);
}
#[skuld::test]
fn wait_exit_waits_for_the_root_and_reaps_nothing_for_both_kinds_of_target() {
let (child, stdin) = crate::test_child::held_uncontained_blocker(true);
let root = StopTarget::from(&child);
let tree = StopTarget::tree(&child, TreeCall::SignalOnly);
assert!(!root.wait_exit(Duration::ZERO).expect("a look"));
assert!(!tree.wait_exit(Duration::ZERO).expect("a look"));
child.kill().expect("kill");
assert!(root.wait_exit(Duration::from_secs(3600)).expect("the root exits"));
assert!(tree.wait_exit(Duration::from_secs(3600)).expect("the root exited"));
drop(stdin);
crate::test_child::assert_killed(
"the blocker",
child.wait().expect("the status is still there to collect"),
);
}
#[cfg(windows)]
#[skuld::test]
fn leads_group_on_our_console_is_the_recorded_facts() {
use crate::containment::windows::ConsoleFacts;
let mut child = child_over(&FakeProcess::new([]));
for (group, own_console_flags, caller_had_console, leads) in [
(true, false, true, true),
(false, false, true, false),
(true, true, true, false),
(true, false, false, false),
] {
child.console = ConsoleFacts {
group,
own_console_flags,
caller_had_console,
elevated: false,
};
assert_eq!(
StopTarget::from(&child).leads_group_on_our_console(),
leads,
"{:?}",
child.console
);
}
}