use super::{
assert_acked, assert_break_sent_to, assert_in_our_console, assert_refused_by_the_direct_send_for_no_group,
connect_reporter, kill_release_reap, report_done, spawn_member, Handler,
};
use crate::stop::proxy::protocol::ProxyAnswer;
use crate::stop::proxy::proxy_tests::Fixture;
use crate::{Containment, StopTarget};
pub(crate) const REPORTER_TEST: &str = "test_child::ctrl_break::nested::fixture_nested_terminate_reporter";
pub(crate) const ADDR_ENV: &str = "COSCA_FIXTURE_NESTED_TERMINATE_ADDR";
#[skuld::test]
fn fixture_nested_terminate_reporter() {
let Some(mut report) = connect_reporter(ADDR_ENV) else {
return;
};
let _warns = crate::log_capture::warn_watch();
let (child, mut sock, _) = spawn_member(Handler::Ack, None, crate::ContainMode::Strongest, |_| {});
let pid = child.pid();
assert_eq!(
child.containment(),
Containment::Delegated,
"this process is contained, so its own spawn is nested"
);
assert!(StopTarget::from(&child).leads_group_on_our_console());
assert_in_our_console(pid, "the nested member");
assert!(
matches!(child.terminate_tree(), Err(crate::error::Error::Unsupported { .. })),
"a nested member still owns no tree teardown"
);
child.terminate().expect("terminate a nested console-group child");
assert_break_sent_to(pid);
assert_acked(&mut sock, "the nested member");
kill_release_reap(&child, sock, false);
report_done(&mut report);
}
pub(crate) const NO_GROUP_REPORTER_TEST: &str = "test_child::ctrl_break::nested::fixture_nested_without_group_reporter";
pub(crate) const NO_GROUP_ADDR_ENV: &str = "COSCA_FIXTURE_NESTED_NO_GROUP_ADDR";
#[skuld::test]
fn fixture_nested_without_group_reporter() {
let Some(mut report) = connect_reporter(NO_GROUP_ADDR_ENV) else {
return;
};
let _warns = crate::log_capture::warn_watch();
let fixture = Fixture::answering(ProxyAnswer::Sent.code());
let (child, sock, _) = spawn_member(Handler::Ack, None, crate::ContainMode::Strongest, |cmd| {
_ = cmd.new_process_group(false);
cmd.ctrl_proxy(fixture.setting());
});
assert_eq!(
child.containment(),
Containment::Delegated,
"this process is contained, so its own spawn is nested"
);
assert!(!StopTarget::from(&child).leads_group_on_our_console());
let err = child
.terminate()
.expect_err("a nested member that leads no group is refused by the direct send");
assert_refused_by_the_direct_send_for_no_group(&err);
assert!(fixture.ran().is_none(), "the proxy was started");
kill_release_reap(&child, sock, false);
report_done(&mut report);
}