Files
tokio/tokio-process/tests/issue_42.rs
T

58 lines
1.5 KiB
Rust
Raw Normal View History

#![cfg(unix)]
2019-08-07 10:38:45 -07:00
#![deny(warnings, rust_2018_idioms)]
2019-07-29 21:36:11 -04:00
use futures_util::future::FutureExt;
use futures_util::stream::FuturesOrdered;
use futures_util::stream::StreamExt;
2019-08-07 10:38:45 -07:00
use std::process::{Command, Stdio};
use std::sync::atomic::{AtomicBool, Ordering};
2019-06-24 17:19:16 -07:00
use std::sync::Arc;
use std::thread;
use std::time::Duration;
2019-08-07 10:38:45 -07:00
use tokio::runtime::current_thread;
use tokio_process::CommandExt;
2019-07-29 21:36:11 -04:00
mod support;
fn run_test() {
let finished = Arc::new(AtomicBool::new(false));
let finished_clone = finished.clone();
thread::spawn(move || {
2019-08-07 10:38:45 -07:00
let mut futures = FuturesOrdered::new();
2019-07-29 21:36:11 -04:00
for i in 0..2 {
futures.push(
2019-06-24 17:19:16 -07:00
Command::new("echo")
.arg(format!("I am spawned process #{}", i))
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn_async()
2019-07-29 21:36:11 -04:00
.unwrap()
.boxed(),
)
}
2019-08-07 10:38:45 -07:00
let mut rt = current_thread::Runtime::new().expect("failed to get runtime");
rt.block_on(support::with_timeout(futures.collect::<Vec<_>>()));
drop(rt);
finished_clone.store(true, Ordering::SeqCst);
});
thread::sleep(Duration::from_millis(100));
2019-06-24 17:19:16 -07:00
assert!(
finished.load(Ordering::SeqCst),
"FINISHED flag not set, maybe we deadlocked?"
);
}
#[test]
fn issue_42() {
let max = 10;
for i in 0..max {
println!("running {}/{}", i, max);
run_test()
}
}