From aedb0c0be55ac7d728787d0fec2e5b776fc66427 Mon Sep 17 00:00:00 2001 From: Lahfir Date: Sun, 12 Jul 2026 23:44:37 -0700 Subject: [PATCH] test: make deadline metrics scheduler-independent --- crates/macos/src/system/cg_window_tests.rs | 12 +++++++++--- crates/macos/src/system/process_tests.rs | 4 ++-- .../src/system/window_inventory_global_tests.rs | 14 +++++++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/crates/macos/src/system/cg_window_tests.rs b/crates/macos/src/system/cg_window_tests.rs index 7767449..1a305c6 100644 --- a/crates/macos/src/system/cg_window_tests.rs +++ b/crates/macos/src/system/cg_window_tests.rs @@ -47,11 +47,13 @@ fn changing_inventory_retries_until_two_consecutive_captures_match() { } #[test] -fn persistent_window_churn_times_out_with_attempt_metrics() { +fn persistent_window_churn_times_out_with_exact_attempt_metrics() { let mut visible = false; + let mut attempts = 0_u64; let error = stabilize_records_until( Instant::now() + std::time::Duration::from_millis(20), || { + attempts += 1; visible = !visible; Ok(records_fixture(visible)) }, @@ -60,8 +62,12 @@ fn persistent_window_churn_times_out_with_attempt_metrics() { assert_eq!(error.code, ErrorCode::Timeout); let details = error.details.unwrap(); - assert!(details["attempts"].as_u64().unwrap() >= 2); - assert!(details["churn_events"].as_u64().unwrap() >= 1); + assert!(attempts >= 1); + assert_eq!(details["attempts"].as_u64(), Some(attempts)); + assert_eq!( + details["churn_events"].as_u64(), + Some(attempts.saturating_sub(1)) + ); } #[test] diff --git a/crates/macos/src/system/process_tests.rs b/crates/macos/src/system/process_tests.rs index bb80968..dc1b733 100644 --- a/crates/macos/src/system/process_tests.rs +++ b/crates/macos/src/system/process_tests.rs @@ -1,7 +1,7 @@ use super::*; -const PROCESS_TIMEOUT: Duration = Duration::from_millis(300); -const PROCESS_TEST_LIMIT: Duration = Duration::from_secs(1); +const PROCESS_TIMEOUT: Duration = Duration::from_secs(1); +const PROCESS_TEST_LIMIT: Duration = Duration::from_secs(2); fn process_exists(process: i32) -> bool { unsafe extern "C" { diff --git a/crates/macos/src/system/window_inventory_global_tests.rs b/crates/macos/src/system/window_inventory_global_tests.rs index 4d2b412..cd6674a 100644 --- a/crates/macos/src/system/window_inventory_global_tests.rs +++ b/crates/macos/src/system/window_inventory_global_tests.rs @@ -264,15 +264,23 @@ fn stabilization_retries_churn_and_preserves_strict_failures() { } #[test] -fn persistent_owner_churn_times_out_with_attempt_metrics() { +fn persistent_owner_churn_times_out_with_exact_attempt_metrics() { + let mut attempts = 0_u64; let error = stabilize_global_with( Instant::now() + std::time::Duration::from_millis(20), - || Err(owner_churn_error(None, "test")), + || { + attempts += 1; + Err(owner_churn_error(None, "test")) + }, ) .unwrap_err(); assert_eq!(error.code, ErrorCode::Timeout); - assert!(error.details.unwrap()["attempts"].as_u64().unwrap() >= 2); + let details = error.details.unwrap(); + assert!(attempts >= 1); + assert_eq!(details["attempts"].as_u64(), Some(attempts)); + assert_eq!(details["last_code"], "APP_UNRESPONSIVE"); + assert_eq!(details["last_kind"], "global_window_owner_churn"); } #[test]