Skip to content

Commit 458f390

Browse files
committed
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 0f3ff9a commit 458f390

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
@@ -22,6 +22,15 @@ fn test_waitpid_none() {
2222
.expect("failed to wait")
2323
.unwrap();
2424
assert!(status.stopped());
25+
26+
// Clean up the child process.
27+
unsafe { kill(child.id() as _, SIGKILL) };
28+
29+
let (pid, status) = process::waitpid(None, process::WaitOptions::UNTRACED)
30+
.expect("failed to wait")
31+
.unwrap();
32+
assert_eq!(pid, process::Pid::from_child(&child));
33+
assert!(status.signaled());
2534
}
2635

2736
#[test]
@@ -39,6 +48,15 @@ fn test_waitpid_some() {
3948
.expect("failed to wait")
4049
.unwrap();
4150
assert!(status.stopped());
51+
52+
// Clean up the child process.
53+
unsafe { kill(child.id() as _, SIGKILL) };
54+
55+
let (rpid, status) = process::waitpid(Some(pid), process::WaitOptions::UNTRACED)
56+
.expect("failed to wait")
57+
.unwrap();
58+
assert_eq!(rpid, pid);
59+
assert!(status.signaled());
4260
}
4361

4462
#[test]
@@ -56,6 +74,15 @@ fn test_waitpgid() {
5674
.expect("failed to wait")
5775
.unwrap();
5876
assert!(status.stopped());
77+
78+
// Clean up the child process.
79+
unsafe { kill(child.id() as _, SIGKILL) };
80+
81+
let (pid, status) = process::waitpgid(pgid, process::WaitOptions::UNTRACED)
82+
.expect("failed to wait")
83+
.unwrap();
84+
assert_eq!(pid, process::Pid::from_child(&child));
85+
assert!(status.signaled());
5986
}
6087

6188
#[cfg(not(any(

0 commit comments

Comments
 (0)