wait for spawned child processes
MODIFY
ipc/tests/common/mod.rs
ipc/tests/common/mod.rs
@@ -15,3 +15,17 @@ pub fn fork<F: FnOnce()>(child_func: F) -> libc::pid_t {
}
}
}
+
+pub fn wait(pid: libc::pid_t) -> bool {
+ // libc::waitpid is unsafe function
+ unsafe {
+ let mut status: i32 = 0;
+ let options: i32 = 0;
+ return match libc::waitpid(pid, &mut status as *mut i32, options) {
+ -1 => {
+ panic!("error occured libc::waitpid problem")
+ }
+ _pid => true,
+ };
+ }
+}

MODIFY
ipc/tests/test_ipc.rs
ipc/tests/test_ipc.rs
@@ -60,6 +60,8 @@ fn ipc_fork_and_client_exchange() -> Result<(), failure::Error> {
let recv = rx.receive()?;
assert_eq!(recv, "dog");
+ assert!(common::wait(child_pid));
+
Ok(())
}
@@ -130,7 +132,10 @@ fn ipc_fork_and_try_read_with_timeout() -> Result<(), failure::Error> {
Err(IpcError::ReceiveMessageTimeouted { .. }) => {
Err(format_err!("Unexpected IpcError::ReceiveMessageTimeouted"))
}
- Err(_) => Ok(()),
+ Err(_) => {
+ assert!(common::wait(child_pid));
+ Ok(())
+ }
Ok(_) => Err(format_err!("Unexpected result")),
}
}

wait for spawned child processes