use super::{support::*, *};
pub(super) const MODULE: &str = module_path!();
#[tokio::test]
#[ignore = "driven in a child process by the_parked_gauge_returns_to_baseline_for_every_ending"]
#[expect(
clippy::print_stdout,
reason = "the parent reads the child's stdout as the proof that it ran"
)]
async fn child_normal_exit() -> TestResult {
let snapshotter = install_recorder()?;
let _sentinel = parked_sentinel().await?;
await_gauge(&snapshotter, 1.0).await?;
let mut paired = parked_pair(AfterRelease::Reply).await?;
await_gauge(&snapshotter, 3.0).await?;
println!("scenario={} parked=3", Ending::NormalExit.label());
answer_live_body(&mut paired).await?;
ensure(
gauge_reads(&snapshotter, 2.0),
format!(
"two messages are still parked while a reply is pending, gauge reads {}",
parked_gauge(&snapshotter)
),
)?;
println!("scenario={} drained_one=2", Ending::NormalExit.label());
answer_parked_pair(&mut paired).await?;
await_gauge(&snapshotter, 1.0).await?;
println!("scenario={} drained_both=1", Ending::NormalExit.label());
SinkExt::<Bytes>::close(&mut paired.client).await?;
let joined = bounded_for(STEP_WAIT, "the connection ending", paired.connection).await?;
joined??;
ensure(
gauge_reads(&snapshotter, 1.0),
format!(
"a returned connection must leave only the sentinel parked, gauge reads {}",
parked_gauge(&snapshotter)
),
)?;
Ok(())
}
#[tokio::test]
#[ignore = "driven in a child process by the_parked_gauge_returns_to_baseline_for_every_ending"]
#[expect(
clippy::print_stdout,
reason = "the parent reads the child's stdout as the proof that it ran"
)]
async fn child_task_abort() -> TestResult {
let snapshotter = install_recorder()?;
let _sentinel = parked_sentinel().await?;
await_gauge(&snapshotter, 1.0).await?;
let paired = parked_pair(AfterRelease::Reply).await?;
await_gauge(&snapshotter, 3.0).await?;
println!("scenario={} parked=3", Ending::TaskAbort.label());
paired.connection.abort();
let joined = bounded_for(STEP_WAIT, "the aborted task ending", paired.connection).await?;
ensure(
joined.is_err_and(|error| error.is_cancelled()),
"the connection task must end because it was cancelled",
)?;
ensure(
gauge_reads(&snapshotter, 1.0),
format!(
"a cancelled connection must release what it parked, gauge reads {}",
parked_gauge(&snapshotter)
),
)?;
println!("scenario={} aborted=1", Ending::TaskAbort.label());
Ok(())
}
#[tokio::test]
#[ignore = "driven in a child process by the_parked_gauge_returns_to_baseline_for_every_ending"]
#[expect(
clippy::print_stdout,
reason = "the parent reads the child's stdout as the proof that it ran"
)]
async fn child_handler_panic() -> TestResult {
let snapshotter = install_recorder()?;
let _sentinel = parked_sentinel().await?;
await_gauge(&snapshotter, 1.0).await?;
let paired = parked_pair(AfterRelease::Panic).await?;
await_gauge(&snapshotter, 3.0).await?;
println!("scenario={} parked=3", Ending::HandlerPanic.label());
paired.release.notify_one();
let joined = bounded_for(STEP_WAIT, "the panicking handler ending", paired.connection).await?;
ensure(
joined.is_err_and(|error| error.is_panic()),
"the handler panic must end the connection task",
)?;
ensure(
gauge_reads(&snapshotter, 1.0),
format!(
"an unwinding connection must release what it parked, gauge reads {}",
parked_gauge(&snapshotter)
),
)?;
println!("scenario={} panicked=1", Ending::HandlerPanic.label());
Ok(())
}