diff --git a/Cargo.toml b/Cargo.toml index 6dd830a60..09014021c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ codecov = { repository = "alexcrichton/tokio-process" } [dependencies] futures = "0.1.11" -mio = "=0.6.16" # TODO: investigate further and unpin this +mio = "0.6.5" tokio-io = "0.1" tokio-reactor = "0.1" diff --git a/tests/stdio.rs b/tests/stdio.rs index 1776f3ae3..abb00d416 100644 --- a/tests/stdio.rs +++ b/tests/stdio.rs @@ -85,6 +85,18 @@ fn feed_a_lot() { assert_eq!(status.code(), Some(0)); } +// FIXME: delete this test once we have a resolution for #51 +// This test's setup is flaky, and setting up a consistent test is nearly +// impossible: right now we invoke `cat` and immediately kill it, expecting +// that it didn't write anything, but if there's something wrong with the +// command itself (e.g. redirection issues, it doesn't actually print anything +// out, etc.) this test can falsely pass. Attempting a solution which writes +// some data, *then* kill the child, write more data, and assert that only the +// first write is echoed back seems like a good approach, however, due to the +// ordering of context switches or how the kernel buffers data we can get +// inconsistent results. We can keep this test around for now, but as soon as +// we have a solution for #51, we may have a better avenue for testing this +// functionality. #[test] fn drop_kills() { let mut child = cat().spawn_async().unwrap(); @@ -96,9 +108,12 @@ fn drop_kills() { let writer = write_all(stdin, b"1234").then(|_| Ok(())); let reader = read_to_end(stdout, Vec::new()); - let future = writer.join(reader).map(|(_, (_, out))| out); + let (_, output) = support::CurrentThreadRuntime::new() + .expect("failed to get rt") + .spawn(writer) + .block_on(support::with_timeout(reader)) + .expect("failed to get output"); - let output = support::run_with_timeout(future).unwrap(); assert_eq!(output.len(), 0); } diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 38435c8cd..0e9ce6845 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -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(future: F) -> impl Future { - Timeout::new(future, Duration::from_secs(1)).map_err(|e| { +pub fn with_timeout(future: F) -> impl Future { + 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)) }