From 4daf3e3e1219792953e34ca9e6f515fd91fa49a2 Mon Sep 17 00:00:00 2001 From: andrussal Date: Wed, 10 Dec 2025 13:38:37 +0100 Subject: [PATCH] Share lifecycle helpers for node processes --- .../core/src/nodes/common/lifecycle/kill.rs | 8 ++++++++ .../core/src/nodes/common/lifecycle/lifecycle.rs | 8 ++++++++ .../core/src/nodes/common/lifecycle/mod.rs | 1 + .../core/src/nodes/common/lifecycle/monitor.rs | 11 +++++++++-- testing-framework/core/src/nodes/executor.rs | 5 ++--- testing-framework/core/src/nodes/validator.rs | 10 +++------- 6 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 testing-framework/core/src/nodes/common/lifecycle/kill.rs create mode 100644 testing-framework/core/src/nodes/common/lifecycle/lifecycle.rs diff --git a/testing-framework/core/src/nodes/common/lifecycle/kill.rs b/testing-framework/core/src/nodes/common/lifecycle/kill.rs new file mode 100644 index 0000000..0454e4a --- /dev/null +++ b/testing-framework/core/src/nodes/common/lifecycle/kill.rs @@ -0,0 +1,8 @@ +#![allow(dead_code)] + +use std::process::Child; + +/// Shared cleanup helpers for child processes. +pub fn kill_child(child: &mut Child) { + let _ = child.kill(); +} diff --git a/testing-framework/core/src/nodes/common/lifecycle/lifecycle.rs b/testing-framework/core/src/nodes/common/lifecycle/lifecycle.rs new file mode 100644 index 0000000..15f049f --- /dev/null +++ b/testing-framework/core/src/nodes/common/lifecycle/lifecycle.rs @@ -0,0 +1,8 @@ +#![allow(dead_code)] + +use std::process::Child; + +/// Shared lifecycle hooks (placeholder). +pub fn kill_child(child: &mut Child) { + let _ = child.kill(); +} diff --git a/testing-framework/core/src/nodes/common/lifecycle/mod.rs b/testing-framework/core/src/nodes/common/lifecycle/mod.rs index 3f06df7..fb09b1f 100644 --- a/testing-framework/core/src/nodes/common/lifecycle/mod.rs +++ b/testing-framework/core/src/nodes/common/lifecycle/mod.rs @@ -1,3 +1,4 @@ pub mod cleanup; +pub mod kill; pub mod monitor; pub mod spawn; diff --git a/testing-framework/core/src/nodes/common/lifecycle/monitor.rs b/testing-framework/core/src/nodes/common/lifecycle/monitor.rs index 4e03638..bc0afaa 100644 --- a/testing-framework/core/src/nodes/common/lifecycle/monitor.rs +++ b/testing-framework/core/src/nodes/common/lifecycle/monitor.rs @@ -1,4 +1,11 @@ #![allow(dead_code)] -/// Shared monitoring helpers (placeholder). -pub struct Monitor; +use std::process::Child; + +/// Check if a child process is still running. +pub fn is_running(child: &mut Child) -> bool { + match child.try_wait() { + Ok(None) => true, + Ok(Some(_)) | Err(_) => false, + } +} diff --git a/testing-framework/core/src/nodes/executor.rs b/testing-framework/core/src/nodes/executor.rs index 41f87c5..bba602b 100644 --- a/testing-framework/core/src/nodes/executor.rs +++ b/testing-framework/core/src/nodes/executor.rs @@ -31,6 +31,7 @@ use crate::{ common::{ binary::{BinaryConfig, BinaryResolver}, config::{injection::inject_ibd_into_cryptarchia, paths::ensure_recovery_paths}, + lifecycle::kill::kill_child, }, }, }; @@ -62,9 +63,7 @@ impl Drop for Executor { println!("failed to persist tempdir: {e}"); } - if let Err(e) = self.child.kill() { - println!("failed to kill the child process: {e}"); - } + kill_child(&mut self.child); } } diff --git a/testing-framework/core/src/nodes/validator.rs b/testing-framework/core/src/nodes/validator.rs index 5663b71..0065da2 100644 --- a/testing-framework/core/src/nodes/validator.rs +++ b/testing-framework/core/src/nodes/validator.rs @@ -30,6 +30,7 @@ use crate::{ common::{ binary::{BinaryConfig, BinaryResolver}, config::{injection::inject_ibd_into_cryptarchia, paths::ensure_recovery_paths}, + lifecycle::kill::kill_child, }, }, }; @@ -66,19 +67,14 @@ impl Drop for Validator { println!("failed to persist tempdir: {e}"); } - if let Err(e) = self.child.kill() { - println!("failed to kill the child process: {e}"); - } + kill_child(&mut self.child); } } impl Validator { /// Check if the validator process is still running pub fn is_running(&mut self) -> bool { - match self.child.try_wait() { - Ok(None) => true, - Ok(Some(_)) | Err(_) => false, - } + crate::nodes::common::lifecycle::monitor::is_running(&mut self.child) } /// Wait for the validator process to exit, with a timeout