mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-06 23:00:15 +08:00
test(task): start only keys the queue returned in the queue tests
Two queue tests called `start` on an armed key that `next_expired` had not returned, which the documented contract rules out. They now let the key expire first and take it from the queue.
This commit is contained in:
@@ -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()));
|
||||
|
||||
Reference in New Issue
Block a user