Files
tokio/tokio-net/tests/signal_simple.rs
T
Ivan Petkov 08b07afbd9 signal: remove new() constructors in favor of free functions (#1472)
* Also removed any `*_with_handle` related methods in favor of always
using the default reactor
2019-08-18 14:22:09 -07:00

38 lines
918 B
Rust

#![cfg(unix)]
#![cfg(feature = "signal")]
#![warn(rust_2018_idioms)]
#![feature(async_await)]
pub mod signal_support;
use crate::signal_support::*;
#[tokio::test]
async fn simple() {
let signal = signal(SignalKind::user_defined1()).expect("failed to create signal");
send_signal(libc::SIGUSR1);
let _ = with_timeout(signal.into_future()).await;
}
#[tokio::test]
#[cfg(unix)]
async fn ctrl_c() {
use tokio::sync::oneshot;
use tokio_net::signal::ctrl_c;
let ctrl_c = ctrl_c().expect("failed to init ctrl_c");
let (fire, wait) = oneshot::channel();
// NB: simulate a signal coming in by exercising our signal handler
// to avoid complications with sending SIGINT to the test process
tokio::spawn(async {
wait.await.expect("wait failed");
send_signal(libc::SIGINT);
});
let _ = fire.send(());
let _ = with_timeout(ctrl_c.into_future()).await;
}