Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase coverage #68

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/integration_test_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
},
);
}