Skip to content

Commit

Permalink
Fix running tests in pidfd_reaper
Browse files Browse the repository at this point in the history
Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu committed Nov 15, 2023
1 parent 64afdd0 commit 92b8831
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions tokio/src/process/unix/pidfd_reaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,31 +176,49 @@ where
#[cfg(all(test, not(loom)))]
mod test {
use super::*;
use crate::runtime::{Builder as RuntimeBuilder, Runtime};
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 create_runtime() -> Runtime {
RuntimeBuilder::new_current_thread()
.enable_io()
.build()
.unwrap()
}

let exit_status = pidfd_reaper.await.unwrap();
assert!(exit_status.success());
fn run_test(fut: impl Future<Output = ()>) {
create_runtime().block_on(fut)
}

#[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_poll() {
run_test(async {
let child = Command::new("true").spawn().unwrap();
let pidfd_reaper = PidfdReaper::new(child).unwrap();

let exit_status = pidfd_reaper.await.unwrap();
assert!(exit_status.success());
});
}

pidfd_reaper.kill().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();

let exit_status = pidfd_reaper.await.unwrap();
assert!(!exit_status.success());
pidfd_reaper.kill().unwrap();

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 _pidfd_reaper = PidfdReaper::new(child).unwrap();
});
}
}

0 comments on commit 92b8831

Please sign in to comment.