Skip to content

Commit

Permalink
Fix test hangs on macos. (#1170)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sunfishcode authored Sep 17, 2024
1 parent ecd9879 commit eddd4a7
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/process/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ fn test_waitpid_none() {
.unwrap();
assert_eq!(pid, process::Pid::from_child(&child));
assert!(status.stopped());

// Clean up the child process.
unsafe { kill(child.id() as _, SIGKILL) };

let (pid, status) = process::waitpid(None, process::WaitOptions::UNTRACED)
.expect("failed to wait")
.unwrap();
assert_eq!(pid, process::Pid::from_child(&child));
assert!(status.signaled());
}

#[test]
Expand All @@ -41,6 +50,15 @@ fn test_waitpid_some() {
.unwrap();
assert_eq!(rpid, pid);
assert!(status.stopped());

// Clean up the child process.
unsafe { kill(child.id() as _, SIGKILL) };

let (rpid, status) = process::waitpid(Some(pid), process::WaitOptions::UNTRACED)
.expect("failed to wait")
.unwrap();
assert_eq!(rpid, pid);
assert!(status.signaled());
}

#[test]
Expand All @@ -59,6 +77,15 @@ fn test_waitpgid() {
.unwrap();
assert_eq!(pid, process::Pid::from_child(&child));
assert!(status.stopped());

// Clean up the child process.
unsafe { kill(child.id() as _, SIGKILL) };

let (pid, status) = process::waitpgid(pgid, process::WaitOptions::UNTRACED)
.expect("failed to wait")
.unwrap();
assert_eq!(pid, process::Pid::from_child(&child));
assert!(status.signaled());
}

#[cfg(not(any(
Expand Down

0 comments on commit eddd4a7

Please sign in to comment.