1 | #![warn (rust_2018_idioms)] |
2 | #![cfg (feature = "full" )] |
3 | #![cfg (unix)] |
4 | |
5 | mod support { |
6 | pub mod signal; |
7 | } |
8 | use support::signal::send_signal; |
9 | |
10 | use tokio::signal; |
11 | use tokio::sync::oneshot; |
12 | use tokio_test::assert_ok; |
13 | |
14 | #[tokio::test ] |
15 | async fn ctrl_c() { |
16 | let ctrl_c = signal::ctrl_c(); |
17 | |
18 | let (fire, wait) = oneshot::channel(); |
19 | |
20 | // NB: simulate a signal coming in by exercising our signal handler |
21 | // to avoid complications with sending SIGINT to the test process |
22 | tokio::spawn(async { |
23 | wait.await.expect("wait failed" ); |
24 | send_signal(libc::SIGINT); |
25 | }); |
26 | |
27 | let _ = fire.send(()); |
28 | |
29 | assert_ok!(ctrl_c.await); |
30 | } |
31 | |