From 491ddcb33502d9c6e1ff5d9aa2cfbd8b13c77b8c Mon Sep 17 00:00:00 2001 From: Finomnis Date: Sun, 22 Oct 2023 18:28:07 +0200 Subject: [PATCH] Increase coverage (#68) --- tests/integration_test_2.rs | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/integration_test_2.rs b/tests/integration_test_2.rs index 28eff68..601f000 100644 --- a/tests/integration_test_2.rs +++ b/tests/integration_test_2.rs @@ -161,3 +161,41 @@ async fn request_local_shutdown() { .await .unwrap(); } + +#[cfg(unix)] +#[tokio::test] +#[traced_test] +async fn shutdown_through_signal_2() { + use nix::sys::signal::{self, Signal}; + use nix::unistd::Pid; + use tokio_graceful_shutdown::FutureExt; + + let subsystem = |subsys: SubsystemHandle| async move { + subsys.on_shutdown_requested().await; + sleep(Duration::from_millis(200)).await; + BoxedResult::Ok(()) + }; + + tokio::join!( + async { + sleep(Duration::from_millis(100)).await; + + // Send SIGINT to ourselves. + signal::kill(Pid::this(), Signal::SIGTERM).unwrap(); + }, + async { + let result = Toplevel::new(move |s| async move { + s.start(SubsystemBuilder::new("subsys", subsystem)); + assert!(sleep(Duration::from_millis(1000)) + .cancel_on_shutdown(&s) + .await + .is_err()); + assert!(s.is_shutdown_requested()); + }) + .catch_signals() + .handle_shutdown_requests(Duration::from_millis(400)) + .await; + assert!(result.is_ok()); + }, + ); +}