process: Run cargo fmt

This commit is contained in:
Ivan Petkov
2019-06-24 17:29:33 -07:00
parent 0ab25878bd
commit 27c15471c1
8 changed files with 151 additions and 155 deletions
+16 -12
View File
@@ -3,10 +3,10 @@
extern crate futures;
extern crate tokio_process;
use futures::{Future, IntoFuture, Stream, stream};
use futures::{stream, Future, IntoFuture, Stream};
use std::process::{Command, Stdio};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::thread;
use std::time::Duration;
use tokio_process::CommandExt;
@@ -17,15 +17,16 @@ fn run_test() {
thread::spawn(move || {
let _ = stream::iter_ok(0..2)
.map(|i| Command::new("echo")
.arg(format!("I am spawned process #{}", i))
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn_async()
.into_future()
.flatten()
)
.map(|i| {
Command::new("echo")
.arg(format!("I am spawned process #{}", i))
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn_async()
.into_future()
.flatten()
})
.buffered(2)
.collect()
.wait();
@@ -34,7 +35,10 @@ fn run_test() {
});
thread::sleep(Duration::from_millis(100));
assert!(finished.load(Ordering::SeqCst), "FINISHED flag not set, maybe we deadlocked?");
assert!(
finished.load(Ordering::SeqCst),
"FINISHED flag not set, maybe we deadlocked?"
);
}
#[test]
+1 -2
View File
@@ -14,8 +14,7 @@ fn simple() {
let id = child.id();
assert!(id > 0);
let status = support::run_with_timeout(&mut child)
.expect("failed to run future");
let status = support::run_with_timeout(&mut child).expect("failed to run future");
assert_eq!(status.code(), Some(2));
assert_eq!(child.id(), id);
+17 -16
View File
@@ -5,19 +5,18 @@ extern crate tokio_io;
extern crate tokio_process;
use std::io;
use std::process::{Stdio, ExitStatus, Command};
use std::process::{Command, ExitStatus, Stdio};
use futures::future::Future;
use futures::stream::{self, Stream};
use tokio_io::io::{read_until, write_all};
use tokio_process::{CommandExt, Child};
use tokio_process::{Child, CommandExt};
mod support;
fn cat() -> Command {
let mut cmd = support::cmd("cat");
cmd.stdin(Stdio::piped())
.stdout(Stdio::piped());
cmd.stdin(Stdio::piped()).stdout(Stdio::piped());
cmd
}
@@ -28,10 +27,12 @@ fn feed_cat(mut cat: Child, n: usize) -> Box<Future<Item = ExitStatus, Error = i
debug!("starting to feed");
// Produce n lines on the child's stdout.
let numbers = stream::iter_ok(0..n);
let write = numbers.fold(stdin, |stdin, i| {
debug!("sending line {} to child", i);
write_all(stdin, format!("line {}\n", i).into_bytes()).map(|p| p.0)
}).map(|_| ());
let write = numbers
.fold(stdin, |stdin, i| {
debug!("sending line {} to child", i);
write_all(stdin, format!("line {}\n", i).into_bytes()).map(|p| p.0)
})
.map(|_| ());
// Try to read `n + 1` lines, ensuring the last one is empty
// (i.e. EOF is reached after `n` lines.
@@ -41,15 +42,15 @@ fn feed_cat(mut cat: Child, n: usize) -> Box<Future<Item = ExitStatus, Error = i
let done = i >= n;
debug!("starting read from child");
read_until(reader, b'\n', Vec::new()).and_then(move |(reader, vec)| {
debug!("read line {} from child ({} bytes, done: {})",
i, vec.len(), done);
debug!(
"read line {} from child ({} bytes, done: {})",
i,
vec.len(),
done
);
match (done, vec.len()) {
(false, 0) => {
Err(io::Error::new(io::ErrorKind::BrokenPipe, "broken pipe"))
},
(true, n) if n != 0 => {
Err(io::Error::new(io::ErrorKind::Other, "extraneous data"))
},
(false, 0) => Err(io::Error::new(io::ErrorKind::BrokenPipe, "broken pipe")),
(true, n) if n != 0 => Err(io::Error::new(io::ErrorKind::Other, "extraneous data")),
_ => {
let s = std::str::from_utf8(&vec).unwrap();
let expected = format!("line {}\n", i);