Skip to content

Commit eddd4a7

Browse files
authored
Fix test hangs on macos. (#1170)
In the `waitpid` tests, explicitly terminate the child processe and wait for them to exit, as dropping a `Command` otherwise leaves the process running. This fixes test hangs on macos.
1 parent ecd9879 commit eddd4a7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/process/wait.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ fn test_waitpid_none() {
2323
.unwrap();
2424
assert_eq!(pid, process::Pid::from_child(&child));
2525
assert!(status.stopped());
26+
27+
// Clean up the child process.
28+
unsafe { kill(child.id() as _, SIGKILL) };
29+
30+
let (pid, status) = process::waitpid(None, process::WaitOptions::UNTRACED)
31+
.expect("failed to wait")
32+
.unwrap();
33+
assert_eq!(pid, process::Pid::from_child(&child));
34+
assert!(status.signaled());
2635
}
2736

2837
#[test]
@@ -41,6 +50,15 @@ fn test_waitpid_some() {
4150
.unwrap();
4251
assert_eq!(rpid, pid);
4352
assert!(status.stopped());
53+
54+
// Clean up the child process.
55+
unsafe { kill(child.id() as _, SIGKILL) };
56+
57+
let (rpid, status) = process::waitpid(Some(pid), process::WaitOptions::UNTRACED)
58+
.expect("failed to wait")
59+
.unwrap();
60+
assert_eq!(rpid, pid);
61+
assert!(status.signaled());
4462
}
4563

4664
#[test]
@@ -59,6 +77,15 @@ fn test_waitpgid() {
5977
.unwrap();
6078
assert_eq!(pid, process::Pid::from_child(&child));
6179
assert!(status.stopped());
80+
81+
// Clean up the child process.
82+
unsafe { kill(child.id() as _, SIGKILL) };
83+
84+
let (pid, status) = process::waitpgid(pgid, process::WaitOptions::UNTRACED)
85+
.expect("failed to wait")
86+
.unwrap();
87+
assert_eq!(pid, process::Pid::from_child(&child));
88+
assert!(status.signaled());
6289
}
6390

6491
#[cfg(not(any(

0 commit comments

Comments
 (0)