mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
signal: Refactor Signal tests
* Added timeouts to all tests that were missing them - any issue we have will likely result in deadlocks/starvation so its best if all tests quickly timeout rather than require getting killed or have the CI timeout itself * Added a `support` module and put a bunch of helpers there to DRY the tests
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#![cfg(unix)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
pub mod support;
|
||||
use support::*;
|
||||
|
||||
const TEST_SIGNAL: libc::c_int = libc::SIGUSR1;
|
||||
|
||||
#[test]
|
||||
fn dropping_loops_does_not_cause_starvation() {
|
||||
let (mut rt, signal) = {
|
||||
let mut first_rt = CurrentThreadRuntime::new()
|
||||
.expect("failed to init first runtime");
|
||||
|
||||
let first_signal = run_with_timeout(&mut first_rt, Signal::new(TEST_SIGNAL))
|
||||
.expect("failed to register first signal");
|
||||
|
||||
let mut second_rt = CurrentThreadRuntime::new()
|
||||
.expect("failed to init second runtime");
|
||||
|
||||
let second_signal = run_with_timeout(&mut second_rt, Signal::new(TEST_SIGNAL))
|
||||
.expect("failed to register second signal");
|
||||
|
||||
drop(first_rt);
|
||||
drop(first_signal);
|
||||
|
||||
(second_rt, second_signal)
|
||||
};
|
||||
|
||||
send_signal(TEST_SIGNAL);
|
||||
|
||||
let signal_future = signal.into_future()
|
||||
.map_err(|(e, _)| e);
|
||||
|
||||
run_with_timeout(&mut rt, signal_future)
|
||||
.expect("failed to get signal");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user