use crate::child::spawn::fault;
use crate::error::ChildFate;
use crate::identity::refusing_the_next_terminate;
use crate::log_capture::warns_since;
use crate::test_child::Console;
#[derive(Clone, Copy)]
enum Backend {
Std,
Raw,
}
fn teardown_with_an_exit_under_way(backend: Backend, force: fn(bool)) -> (ChildFate, Vec<String>) {
crate::log_capture::install();
let mark = crate::log_capture::mark();
let (stdin, writer) = crate::test_child::held_writer_stdin();
let mut cmd = crate::test_child::tokio_command(Console::Hidden);
if matches!(backend, Backend::Raw) {
cmd.executable(crate::test_child::BLOCKER_ARGV[0]);
}
cmd.args(crate::test_child::BLOCKER_ARGV.iter().copied());
cmd.stdin(stdin).expect("set stdin pipe");
cmd.stdout(crate::stdio::Stdio::null()).expect("set stdout");
let _warn = crate::tokio::child::fault::warn_slow_teardowns_after(std::time::Duration::ZERO);
let _end = crate::wait::block_probe::on_blocking(move || drop(writer));
let kernel =
std::sync::Arc::new(refusing_the_next_terminate().on_creation_token(Ok(crate::identity::Key::from_raw(1))));
force(true);
let spawned = crate::child::spawn::spawn_uncommitted(
cmd.as_sync_mut(),
crate::tokio::child::async_policy(),
std::sync::Arc::clone(&kernel),
);
force(false);
let (_, fate) = crate::child::spawn::failure::expect_may_have_started_with(crate::error::Error::from(
spawned.expect_err("the forced failure fails the spawn"),
));
assert!(kernel.all_rows_taken(), "the teardown sent its kill");
(fate, warns_since(mark, "still waiting"))
}
fn assert_warns_once_and_waits_on((fate, warns): (ChildFate, Vec<String>)) {
assert_eq!(warns.len(), 1, "one warn, and the wait goes on: {warns:?}");
assert_eq!(fate, ChildFate::Reaped, "the wait goes on past the threshold");
}
#[skuld::test]
async fn a_std_teardown_after_a_failed_attach_warns_once_past_its_threshold() {
assert_warns_once_and_waits_on(teardown_with_an_exit_under_way(
Backend::Std,
fault::set_force_attach_failure,
));
}
#[skuld::test]
async fn a_raw_teardown_after_a_failed_attach_warns_once_past_its_threshold() {
assert_warns_once_and_waits_on(teardown_with_an_exit_under_way(
Backend::Raw,
fault::set_force_attach_failure,
));
}