Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(process): Use pidfd on Linux for tokio::process::Child::wait #6152

Merged
merged 17 commits into from
Jan 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix running tests in pidfd_reaper
Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu committed Dec 31, 2023
commit 5f62be6bcee9962ad674bb7953983d0000985db6
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();
});
}
}