mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-30 00:00:16 +02:00
process: Remove dependency on tokio-core
This commit is contained in:
+23
-23
@@ -1,5 +1,5 @@
|
||||
extern crate futures;
|
||||
extern crate tokio_core;
|
||||
extern crate tokio;
|
||||
extern crate tokio_io;
|
||||
extern crate tokio_process;
|
||||
#[macro_use]
|
||||
@@ -9,12 +9,14 @@ extern crate env_logger;
|
||||
use std::io;
|
||||
use std::process::{Stdio, ExitStatus, Command};
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use futures::future::Future;
|
||||
use futures::stream::{self, Stream};
|
||||
use tokio::executor::current_thread;
|
||||
use tokio_io::io::{read_until, write_all, read_to_end};
|
||||
use tokio_core::reactor::{Core, Timeout};
|
||||
use tokio_process::{CommandExt, Child};
|
||||
use tokio::timer::Deadline;
|
||||
|
||||
mod support;
|
||||
|
||||
@@ -84,34 +86,35 @@ fn feed_cat(mut cat: Child, n: usize) -> Box<Future<Item = ExitStatus, Error = i
|
||||
///
|
||||
/// - The child does produce EOF on stdout after the last line.
|
||||
fn feed_a_lot() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let child = cat().spawn_async_with_handle(lp.handle().new_tokio_handle()).unwrap();
|
||||
let status = lp.run(feed_cat(child, 10000)).unwrap();
|
||||
let child = cat().spawn_async().unwrap();
|
||||
let status = current_thread::block_on_all(feed_cat(child, 10000)).unwrap();
|
||||
assert_eq!(status.code(), Some(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drop_kills() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let mut child = cat().spawn_async_with_handle(lp.handle().new_tokio_handle()).unwrap();
|
||||
let mut child = cat().spawn_async().unwrap();
|
||||
let stdin = child.stdin().take().unwrap();
|
||||
let stdout = child.stdout().take().unwrap();
|
||||
drop(child);
|
||||
|
||||
drop(lp.run(write_all(stdin, b"1234")));
|
||||
let (_, output) = lp.run(read_to_end(stdout, Vec::new())).unwrap();
|
||||
// Ignore all write errors since we expect a broken pipe here
|
||||
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 = current_thread::block_on_all(future).unwrap();
|
||||
assert_eq!(output.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wait_with_output_captures() {
|
||||
let mut core = Core::new().unwrap();
|
||||
|
||||
let mut child = cat().spawn_async_with_handle(core.handle().new_tokio_handle()).unwrap();
|
||||
let mut child = cat().spawn_async().unwrap();
|
||||
let stdin = child.stdin().take().unwrap();
|
||||
let out = child.wait_with_output();
|
||||
|
||||
let ret = core.run(write_all(stdin, b"1234").map(|p| p.1).join(out)).unwrap();
|
||||
let ret = current_thread::block_on_all(write_all(stdin, b"1234").map(|p| p.1).join(out)).unwrap();
|
||||
let (written, output) = ret;
|
||||
|
||||
assert!(output.status.success());
|
||||
@@ -121,18 +124,15 @@ fn wait_with_output_captures() {
|
||||
|
||||
#[test]
|
||||
fn status_closes_any_pipes() {
|
||||
let mut core = Core::new().unwrap();
|
||||
|
||||
// Cat will open a pipe between the parent and child.
|
||||
// If `status_async` doesn't ensure the handles are closed,
|
||||
// we would end up blocking forever (and time out).
|
||||
let child = cat().status_async_with_handle(core.handle().new_tokio_handle()).unwrap();
|
||||
let timeout = Timeout::new(Duration::from_secs(1), &core.handle())
|
||||
.expect("timeout registration failed")
|
||||
.map(|()| panic!("time out exceeded! did we get stuck waiting on the child?"));
|
||||
let child = cat().status_async().expect("failed to spawn child");
|
||||
|
||||
match core.run(child.select(timeout)) {
|
||||
Ok((status, _)) => assert!(status.success()),
|
||||
Err(_) => panic!("failed to run futures"),
|
||||
}
|
||||
// NB: Deadline 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 = tokio::runtime::current_thread::Runtime::new().unwrap();
|
||||
rt.block_on(Deadline::new(child, Instant::now() + Duration::from_secs(1)))
|
||||
.expect("time out exceeded! did we get stuck waiting on the child?");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user