From e2c06e494609facc99848257b2833a7005066109 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Sun, 6 Dec 2026 10:50:03 +0800 Subject: [PATCH] test(task): prove a retired timer is dropped and a changed interval reschedules --- crates/clash-verge-task/tests/timers.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/clash-verge-task/tests/timers.rs b/crates/clash-verge-task/tests/timers.rs index efeb35f85..2cd83241f 100644 --- a/crates/clash-verge-task/tests/timers.rs +++ b/crates/clash-verge-task/tests/timers.rs @@ -99,6 +99,7 @@ async fn a_profile_disabled_mid_update_is_dropped_when_it_reports_back() { timers.apply(HashMap::new()), vec![TimerChange::Retired("local".to_owned())] ); + assert_eq!(timers.interval("local"), None, "a retired timer reports no deadline"); assert!( timers.finish(&"local".to_owned()), "a task retired mid-update must not outlive the update" @@ -107,6 +108,28 @@ async fn a_profile_disabled_mid_update_is_dropped_when_it_reports_back() { tokio::time::advance(Duration::from_secs(7200)).await; assert!(nothing_due(&mut timers).await, "and must never be scheduled again"); + // Re-enabling starts from scratch; a leftover entry would report no change. + assert_eq!( + timers.apply(HashMap::from([("local".to_owned(), plan(Duration::ZERO, 60 * MINUTE))])), + vec![TimerChange::Added("local".to_owned())] + ); +} + +#[tokio::test(start_paused = true)] +async fn an_idle_timer_with_a_changed_interval_fires_after_the_new_first_delay() { + let mut timers = KeyedTimers::new(); + timers.apply(HashMap::from([("a".to_owned(), plan(60 * MINUTE, 60 * MINUTE))])); + assert_eq!( + timers.apply(HashMap::from([("a".to_owned(), plan(MINUTE, MINUTE))])), + vec![TimerChange::Updated("a".to_owned())] + ); + tokio::time::advance(MINUTE).await; + assert_eq!( + take_expired(&mut timers).await.as_deref(), + Some("a"), + "the old fire time an hour out must not survive the change" + ); + assert!(nothing_due(&mut timers).await); } #[tokio::test(start_paused = true)]