mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-04-29 15:26:05 +02:00
refactor: cleanup proxy process management on windows
This commit is contained in:
@@ -2474,18 +2474,19 @@ mod tests {
|
||||
async fn test_cleanup_distinguishes_live_and_dead_proxy_configs() {
|
||||
use crate::proxy_storage::{save_proxy_config, ProxyConfig};
|
||||
|
||||
// Spawn a live child process to use its PID
|
||||
let mut live_child =
|
||||
std::process::Command::new(if cfg!(windows) { "timeout" } else { "sleep" })
|
||||
.args(if cfg!(windows) {
|
||||
vec!["/T", "30"]
|
||||
} else {
|
||||
vec!["30"]
|
||||
})
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
.spawn()
|
||||
.expect("spawn live child");
|
||||
// Spawn a live child process to use its PID.
|
||||
// On Windows, `timeout` requires console input and exits immediately in CI,
|
||||
// so use `ping` which works reliably in non-interactive contexts.
|
||||
let mut live_child = std::process::Command::new(if cfg!(windows) { "ping" } else { "sleep" })
|
||||
.args(if cfg!(windows) {
|
||||
vec!["-n", "30", "127.0.0.1"]
|
||||
} else {
|
||||
vec!["30"]
|
||||
})
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
.spawn()
|
||||
.expect("spawn live child");
|
||||
let live_pid = live_child.id();
|
||||
|
||||
// Spawn and kill a short-lived process to get a dead PID
|
||||
|
||||
@@ -174,7 +174,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_is_process_running_returns_false_for_nonexistent_pid() {
|
||||
// PID 0 is not a valid user process on any supported platform
|
||||
// PID 0 is the "System Idle Process" on Windows and sysinfo reports it as running,
|
||||
// so only assert on non-Windows platforms where PID 0 is not a real user process.
|
||||
#[cfg(not(windows))]
|
||||
assert!(
|
||||
!is_process_running(0),
|
||||
"is_process_running must return false for PID 0"
|
||||
|
||||
Reference in New Issue
Block a user