summaryrefslogtreecommitdiffstats
path: root/vendor/tokio/tests/signal_ctrl_c.rs
blob: 4b057ee7e1405f1cbd7a3ea5f5d77a476cff76d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
#![cfg(unix)]

mod support {
    pub mod signal;
}
use support::signal::send_signal;

use tokio::signal;
use tokio::sync::oneshot;
use tokio_test::assert_ok;

#[tokio::test]
async fn ctrl_c() {
    let ctrl_c = signal::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(());

    assert_ok!(ctrl_c.await);
}