mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
tokio-timer: fix DelayQueue bug when inserting shorter delay (#863)
Reset the delay of the queue in case an item that expires sooner than the last inserted is put into the queue.
This commit is contained in:
committed by
Carl Lerche
parent
fbad6297c5
commit
12546d1d9c
@@ -279,3 +279,35 @@ fn remove_expired_item() {
|
||||
assert_eq!(entry.into_inner(), "foo");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expires_before_last_insert() {
|
||||
mocked(|timer, time| {
|
||||
let mut queue = DelayQueue::new();
|
||||
let mut task = MockTask::new();
|
||||
|
||||
|
||||
let epoch = time.now();
|
||||
|
||||
queue.insert_at("foo", epoch + ms(10_000));
|
||||
|
||||
// Delay should be set to 8.192s here.
|
||||
task.enter(|| {
|
||||
assert_not_ready!(queue);
|
||||
});
|
||||
|
||||
// Delay should be set to the delay of the new item here
|
||||
queue.insert_at("bar", epoch + ms(600));
|
||||
|
||||
task.enter(|| {
|
||||
assert_not_ready!(queue);
|
||||
});
|
||||
|
||||
advance(timer, ms(600));
|
||||
|
||||
assert!(task.is_notified());
|
||||
let entry = assert_ready!(queue).unwrap().into_inner();
|
||||
assert_eq!(entry, "bar");
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user