about summary refs log tree commit diff stats
path: root/crates
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-18 18:12:11 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-18 18:12:11 +0200
commit7cc99ec385857dc6e33072f9e7865ee2a93a8d69 (patch)
tree4e24669c86665c6fe1e746c15f44e90050b5185b /crates
parentperf(crates/yt/db/extractor_hash/realize): Allow passing in a `all_hashes` (diff)
downloadyt-7cc99ec385857dc6e33072f9e7865ee2a93a8d69.zip
test(crates/yt/tests/_testenv): Store `Child`s instead of PIDs
That avoids killing a random process if the original process has already
exited.
Diffstat (limited to 'crates')
-rw-r--r--crates/yt/tests/_testenv/init.rs15
-rw-r--r--crates/yt/tests/_testenv/mod.rs4
-rw-r--r--crates/yt/tests/_testenv/run.rs6
3 files changed, 8 insertions, 17 deletions
diff --git a/crates/yt/tests/_testenv/init.rs b/crates/yt/tests/_testenv/init.rs
index a584dc9..d797ed8 100644
--- a/crates/yt/tests/_testenv/init.rs
+++ b/crates/yt/tests/_testenv/init.rs
@@ -3,11 +3,8 @@ use std::{
     fs::{self, OpenOptions},
     io::{self, Write},
     path::PathBuf,
-    process,
 };
 
-use libc::SIGINT;
-
 use crate::{_testenv::Paths, testenv::TestEnv};
 
 fn target_dir() -> PathBuf {
@@ -122,16 +119,8 @@ impl TestEnv {
 
 impl Drop for TestEnv {
     fn drop(&mut self) {
-        for _ in &self.spawned_childs {
-            // unsafe {
-            // TODO(@bpeetz): Use the PidFd feature. <2025-07-07>
-            // I would rather have zombie processes instead of killing random pid (they could have
-            // been recycled since we spawned the original command.)
-            // assert_eq!(
-            //     libc::kill(i32::try_from(*pid).expect("Should be small enough"), SIGINT),
-            //     0
-            // );
-            // };
+        for child in &mut self.spawned_childs {
+            drop(child.kill());
         }
     }
 }
diff --git a/crates/yt/tests/_testenv/mod.rs b/crates/yt/tests/_testenv/mod.rs
index fe3f3b8..4798d5d 100644
--- a/crates/yt/tests/_testenv/mod.rs
+++ b/crates/yt/tests/_testenv/mod.rs
@@ -1,6 +1,6 @@
 //! This code was taken from *fd* at 30-06-2025.
 
-use std::path::PathBuf;
+use std::{path::PathBuf, process};
 
 mod init;
 mod run;
@@ -14,7 +14,7 @@ pub(crate) struct TestEnv {
 
     pub(crate) paths: Paths,
 
-    pub(crate) spawned_childs: Vec<u32>,
+    pub(crate) spawned_childs: Vec<process::Child>,
 }
 
 pub(crate) struct Paths {
diff --git a/crates/yt/tests/_testenv/run.rs b/crates/yt/tests/_testenv/run.rs
index 74f5e86..85c914f 100644
--- a/crates/yt/tests/_testenv/run.rs
+++ b/crates/yt/tests/_testenv/run.rs
@@ -125,9 +125,11 @@ impl TestEnv {
         #[allow(clippy::zombie_processes)]
         let mut child = cmd.spawn().expect("yt spawn");
 
-        self.spawned_childs.push(child.id());
+        let stdout = child.stdout.take().expect("Was piped");
 
-        child.stdout.take().expect("Was piped")
+        self.spawned_childs.push(child);
+
+        stdout
     }
 
     fn finalize_cmd(mut cmd: process::Command, args: &[&str]) -> String {