diff --git a/crates/clash-verge-task/tests/timers.rs b/crates/clash-verge-task/tests/timers.rs index bf349f538..5b2a9e3f0 100644 --- a/crates/clash-verge-task/tests/timers.rs +++ b/crates/clash-verge-task/tests/timers.rs @@ -139,19 +139,21 @@ async fn apply_reports_removals_first_and_reenable_changes_nothing() { timers.apply(HashMap::from([ ("a".to_owned(), plan(MINUTE, MINUTE)), ("b".to_owned(), plan(MINUTE, 2 * MINUTE)), - ("c".to_owned(), plan(MINUTE, 3 * MINUTE)), + ("c".to_owned(), plan(10 * MINUTE, 3 * MINUTE)), ])); let mut tail = timers.apply(HashMap::from([ ("a".to_owned(), plan(2 * MINUTE, 2 * MINUTE)), - ("c".to_owned(), plan(MINUTE, 3 * MINUTE)), - ("d".to_owned(), plan(MINUTE, MINUTE)), + ("c".to_owned(), plan(10 * MINUTE, 3 * MINUTE)), + ("d".to_owned(), plan(4 * MINUTE, MINUTE)), ])); assert_eq!(tail.remove(0), TimerChange::Removed("b".to_owned())); assert_eq!(tail.len(), 2); // HashMap order decides which of these comes first assert!(tail.contains(&TimerChange::Added("d".to_owned()))); assert!(tail.contains(&TimerChange::Updated("a".to_owned()))); + tokio::time::advance(2 * MINUTE).await; + assert_eq!(take_expired(&mut timers).await.as_deref(), Some("a")); assert!(timers.start(&"a".to_owned())); - let retired = timers.apply(HashMap::from([("c".to_owned(), plan(MINUTE, 3 * MINUTE))])); + let retired = timers.apply(HashMap::from([("c".to_owned(), plan(10 * MINUTE, 3 * MINUTE))])); assert_eq!(retired.len(), 2, "the running key is retired and the idle one removed"); assert!(retired.contains(&TimerChange::Retired("a".to_owned()))); assert!(retired.contains(&TimerChange::Removed("d".to_owned()))); @@ -159,7 +161,7 @@ async fn apply_reports_removals_first_and_reenable_changes_nothing() { timers .apply(HashMap::from([ ("a".to_owned(), plan(2 * MINUTE, 2 * MINUTE)), - ("c".to_owned(), plan(MINUTE, 3 * MINUTE)), + ("c".to_owned(), plan(10 * MINUTE, 3 * MINUTE)), ])) .is_empty() ); @@ -184,6 +186,8 @@ async fn finishing_an_unknown_or_cleared_key_does_nothing() { let mut timers = KeyedTimers::new(); assert!(!timers.finish(&"missing".to_owned())); timers.apply(HashMap::from([("a".to_owned(), plan(MINUTE, MINUTE))])); + tokio::time::advance(MINUTE).await; + assert_eq!(take_expired(&mut timers).await.as_deref(), Some("a")); assert!(timers.start(&"a".to_owned())); timers.clear(); assert!(!timers.finish(&"a".to_owned()));