From 91e091daec24bc6e45dd89e3d74167cae5fe2231 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Sun, 6 Dec 2026 12:36:52 +0800 Subject: [PATCH] test(task): pin that a changed interval adds no fire while a run is in flight Mutation testing showed the suite could not tell whether apply arms an extra queue entry for a running key whose interval changed. The test now advances past the new first delay during the run and expects nothing to fire, then exactly one expiry after the run reports back. The idle case also asserts that the reset timer does not fire at once. --- crates/clash-verge-task/tests/timers.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/clash-verge-task/tests/timers.rs b/crates/clash-verge-task/tests/timers.rs index 2cd83241f..4a4f2331c 100644 --- a/crates/clash-verge-task/tests/timers.rs +++ b/crates/clash-verge-task/tests/timers.rs @@ -123,6 +123,7 @@ async fn an_idle_timer_with_a_changed_interval_fires_after_the_new_first_delay() timers.apply(HashMap::from([("a".to_owned(), plan(MINUTE, MINUTE))])), vec![TimerChange::Updated("a".to_owned())] ); + assert!(nothing_due(&mut timers).await, "a changed timer does not fire at once"); tokio::time::advance(MINUTE).await; assert_eq!( take_expired(&mut timers).await.as_deref(), @@ -203,9 +204,18 @@ async fn an_interval_changed_during_a_run_is_reported_and_used_on_finish() { ); assert!(nothing_due(&mut timers).await); assert_eq!(timers.interval(&"a".to_owned()), Some(5 * MINUTE)); + + // The new plan's first delay is not a fire time while the run is still in flight. + tokio::time::advance(5 * MINUTE).await; + assert!( + nothing_due(&mut timers).await, + "a changed interval must not queue a second run beside the one in flight" + ); + assert!(!timers.finish(&"a".to_owned())); tokio::time::advance(5 * MINUTE - Duration::from_secs(1)).await; assert!(nothing_due(&mut timers).await); tokio::time::advance(Duration::from_secs(1)).await; assert_eq!(take_expired(&mut timers).await.as_deref(), Some("a")); + assert!(nothing_due(&mut timers).await, "exactly one run after the change"); }