mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-06 23:00:15 +08:00
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.
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user