process: Fix drop_kills test when running on macOS with a single thread

This commit is contained in:
Ivan Petkov
2019-06-24 16:57:19 -07:00
parent 784d21ae31
commit 93680357dd
3 changed files with 23 additions and 7 deletions
+5 -4
View File
@@ -2,12 +2,13 @@ extern crate futures;
extern crate tokio;
use self::futures::Future;
use self::tokio::runtime::current_thread;
use self::tokio::timer::Timeout;
use std::env;
use std::process::Command;
use std::time::Duration;
pub use self::tokio::runtime::current_thread::Runtime as CurrentThreadRuntime;
pub fn cmd(s: &str) -> Command {
let mut me = env::current_exe().unwrap();
me.pop();
@@ -18,8 +19,8 @@ pub fn cmd(s: &str) -> Command {
Command::new(me)
}
fn with_timeout<F: Future>(future: F) -> impl Future<Item = F::Item, Error = F::Error> {
Timeout::new(future, Duration::from_secs(1)).map_err(|e| {
pub fn with_timeout<F: Future>(future: F) -> impl Future<Item = F::Item, Error = F::Error> {
Timeout::new(future, Duration::from_secs(3)).map_err(|e| {
if e.is_timer() {
panic!("failed to register timer");
} else if e.is_elapsed() {
@@ -37,6 +38,6 @@ where
// NB: Timeout requires a timer registration which is provided by
// tokio's `current_thread::Runtime`, but isn't available by just using
// tokio's default CurrentThread executor which powers `current_thread::block_on_all`.
let mut rt = current_thread::Runtime::new().expect("failed to get runtime");
let mut rt = CurrentThreadRuntime::new().expect("failed to get runtime");
rt.block_on(with_timeout(future))
}