test(task): prove a retired timer is dropped and a changed interval reschedules

This commit is contained in:
Tunglies
2026-12-06 16:03:27 +08:00
parent c8356adfe5
commit e2c06e4946
+23
View File
@@ -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)]