process: Add status_async2 as a closer analog to spawn_async

This commit is contained in:
Ivan Petkov
2019-06-24 16:56:50 -07:00
parent 56d3914675
commit b9c6eb309c
2 changed files with 77 additions and 0 deletions
+19
View File
@@ -119,6 +119,7 @@ fn wait_with_output_captures() {
assert_eq!(output.stderr.len(), 0);
}
#[allow(deprecated)]
#[test]
fn status_closes_any_pipes() {
let mut core = Core::new().unwrap();
@@ -136,3 +137,21 @@ fn status_closes_any_pipes() {
Err(_) => panic!("failed to run futures"),
}
}
#[test]
fn status2_closes_any_pipes() {
let mut core = Core::new().unwrap();
// Cat will open a pipe between the parent and child.
// If `status_async2` doesn't ensure the handles are closed,
// we would end up blocking forever (and time out).
let child = cat().status_async2(&core.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?"));
match core.run(child.select(timeout)) {
Ok((status, _)) => assert!(status.success()),
Err(_) => panic!("failed to run futures"),
}
}