diff --git a/Cargo.toml b/Cargo.toml index ab8baac95..09014021c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ name = "tokio-process" # - Update CHANGELOG.md. # - Create "X.Y.Z" git tag. version = "0.2.3" -authors = ["Alex Crichton "] +authors = ["Alex Crichton ", "Ivan Petkov "] license = "MIT/Apache-2.0" repository = "https://github.com/alexcrichton/tokio-process" homepage = "https://github.com/alexcrichton/tokio-process" @@ -27,11 +27,13 @@ tokio-io = "0.1" tokio-reactor = "0.1" [dev-dependencies] -env_logger = { version = "0.4", default-features = false } failure = "0.1" log = "0.4" -tokio = "0.1" -tokio-current-thread = "0.1" + +[dev-dependencies.tokio] +version = "0.1" +default-features = false +features = ["rt-full"] [target.'cfg(windows)'.dependencies] mio-named-pipes = "0.1" diff --git a/tests/smoke.rs b/tests/smoke.rs index e14a59429..a1dc7ec52 100644 --- a/tests/smoke.rs +++ b/tests/smoke.rs @@ -1,4 +1,3 @@ -extern crate tokio_current_thread; extern crate tokio_process; use tokio_process::CommandExt; @@ -15,7 +14,8 @@ fn simple() { let id = child.id(); assert!(id > 0); - let status = tokio_current_thread::block_on_all(&mut child).unwrap(); + let status = support::run_with_timeout(&mut child) + .expect("failed to run future"); assert_eq!(status.code(), Some(2)); assert_eq!(child.id(), id); diff --git a/tests/stdio.rs b/tests/stdio.rs index 045d127b3..1776f3ae3 100644 --- a/tests/stdio.rs +++ b/tests/stdio.rs @@ -1,21 +1,16 @@ extern crate futures; -extern crate tokio; -extern crate tokio_current_thread; -extern crate tokio_io; -extern crate tokio_process; #[macro_use] extern crate log; -extern crate env_logger; +extern crate tokio_io; +extern crate tokio_process; use std::io; use std::process::{Stdio, ExitStatus, Command}; -use std::time::Duration; use futures::future::Future; use futures::stream::{self, Stream}; use tokio_io::io::{read_until, write_all, read_to_end}; use tokio_process::{CommandExt, Child}; -use tokio::timer::Timeout; mod support; @@ -72,7 +67,6 @@ fn feed_cat(mut cat: Child, n: usize) -> Box Box Command { let mut me = env::current_exe().unwrap(); @@ -14,3 +17,26 @@ pub fn cmd(s: &str) -> Command { me.push(s); Command::new(me) } + +fn with_timeout(future: F) -> impl Future { + Timeout::new(future, Duration::from_secs(1)).map_err(|e| { + if e.is_timer() { + panic!("failed to register timer"); + } else if e.is_elapsed() { + panic!("timed out") + } else { + e.into_inner().expect("missing inner error") + } + }) +} + +pub fn run_with_timeout(future: F) -> Result +where + F: Future, +{ + // 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"); + rt.block_on(with_timeout(future)) +}