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
+1 -1
View File
@@ -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"
+17 -2
View File
@@ -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);
}
+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))
}