From beb1dd4d6e65ff7267de9308c3b709c3732ed572 Mon Sep 17 00:00:00 2001 From: zergzorg Date: Sun, 24 May 2026 00:58:38 +0300 Subject: [PATCH] Stabilize ccusage timeout cleanup test --- src-tauri/src/plugin_engine/host_api.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/plugin_engine/host_api.rs b/src-tauri/src/plugin_engine/host_api.rs index 2bdd8aa4..c10d9f61 100644 --- a/src-tauri/src/plugin_engine/host_api.rs +++ b/src-tauri/src/plugin_engine/host_api.rs @@ -4092,12 +4092,28 @@ esac fn ccusage_timeout_kills_descendant_and_closes_pipes() { use std::io::Write; use std::os::unix::fs::PermissionsExt; + use std::path::Path; use std::time::{Duration, Instant}; fn pid_exists(pid: i32) -> bool { unsafe { libc::kill(pid, 0) == 0 } } + fn read_pid_file(path: &Path, deadline: Instant) -> i32 { + loop { + if let Ok(pid_text) = std::fs::read_to_string(path) { + let pid_text = pid_text.trim(); + if !pid_text.is_empty() { + return pid_text.parse().expect("parse descendant pid"); + } + } + if Instant::now() >= deadline { + panic!("descendant pid file was not created at {}", path.display()); + } + std::thread::sleep(Duration::from_millis(20)); + } + } + let test_id = format!( "openusage-ccusage-timeout-{}", std::time::SystemTime::now() @@ -4136,7 +4152,7 @@ wait CcusageProvider::Codex, "codex", CcusageCommandFlavor::Current, - Duration::from_millis(100), + Duration::from_secs(1), ); assert_eq!(result, CcusageRunnerResult::TimedOut); @@ -4145,11 +4161,7 @@ wait "timeout cleanup should not hang on inherited stdout/stderr pipes" ); - let descendant_pid: i32 = std::fs::read_to_string(&pid_path) - .expect("read descendant pid") - .trim() - .parse() - .expect("parse descendant pid"); + let descendant_pid = read_pid_file(&pid_path, Instant::now() + Duration::from_secs(1)); let deadline = Instant::now() + Duration::from_secs(2); while pid_exists(descendant_pid) && Instant::now() < deadline {