From bd8371b965b254a3cc5cacb606f9cb75369754be Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Wed, 15 Nov 2023 22:57:22 +1100 Subject: [PATCH] Fix running tests in `pidfd_reaper` Signed-off-by: Jiahao XU --- tokio/src/process/unix/pidfd_reaper.rs | 49 +++++++++++++++++--------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/tokio/src/process/unix/pidfd_reaper.rs b/tokio/src/process/unix/pidfd_reaper.rs index 4254cb341a2..9b071d0ef73 100644 --- a/tokio/src/process/unix/pidfd_reaper.rs +++ b/tokio/src/process/unix/pidfd_reaper.rs @@ -176,31 +176,46 @@ where #[cfg(all(test, not(loom)))] mod test { use super::*; + use crate::runtime::Builder as RuntimeBuilder; use std::process::Command; - #[crate::test] - async fn test_pidfd_reaper_poll() { - let child = Command::new("true").spawn().unwrap(); - let mut pidfd_reaper = PidfdReaper::new(child).unwrap(); + fn run_test(fut: &mut dyn Future) { + RuntimeBuilder::new_current_thread() + .enable_io() + .build() + .unwrap() + .block_on(fut) + } + + #[test] + fn test_pidfd_reaper_poll() { + run_test(async { + let child = Command::new("true").spawn().unwrap(); + let mut pidfd_reaper = PidfdReaper::new(child).unwrap(); - let exit_status = pidfd_reaper.await.unwrap(); - assert!(exit_status.success()); + let exit_status = pidfd_reaper.await.unwrap(); + assert!(exit_status.success()); + }); } - #[crate::test] - async fn test_pidfd_reaper_kill() { - let child = Command::new("sleep").arg("1800").spawn().unwrap(); - let mut pidfd_reaper = PidfdReaper::new(child).unwrap(); + #[test] + fn test_pidfd_reaper_kill() { + run_test(async { + let child = Command::new("sleep").arg("1800").spawn().unwrap(); + let mut pidfd_reaper = PidfdReaper::new(child).unwrap(); - pidfd_reaper.kill().unwrap(); + pidfd_reaper.kill().unwrap(); - let exit_status = pidfd_reaper.await.unwrap(); - assert!(!exit_status.success()); + let exit_status = pidfd_reaper.await.unwrap(); + assert!(!exit_status.success()); + }); } - #[crate::test] - async fn test_pidfd_reaper_drop() { - let child = Command::new("true").spawn().unwrap(); - let mut pidfd_reaper = PidfdReaper::new(child).unwrap(); + #[test] + fn test_pidfd_reaper_drop() { + run_test(async { + let child = Command::new("true").spawn().unwrap(); + let mut pidfd_reaper = PidfdReaper::new(child).unwrap(); + }); } }