Skip to content

Commit

Permalink
Add Unit Test demonstrating tokio-rs#2473
Browse files Browse the repository at this point in the history
This test demonstrates a panic that occurs when the user inserts an
item with an instant in the past, and then tries to reset the timeout
using the returned key
  • Loading branch information
fegies committed Jun 5, 2020
1 parent be4577e commit ccf3dee
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tokio/tests/time_delay_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,27 @@ async fn reset_later_after_slot_starts() {
assert_eq!(entry, "foo");
}

#[tokio::test]
async fn reset_inserted_expired() {
time::pause();
let mut queue = task::spawn(DelayQueue::new());
let now = Instant::now();

let key = queue.insert_at("foo", now - ms(100));

// this causes the panic described in #2473
queue.reset_at(&key, now + ms(100));

assert_eq!(1, queue.len());

delay_for(ms(200)).await;

let entry = assert_ready_ok!(poll!(queue)).into_inner();
assert_eq!(entry, "foo");

assert_eq!(queue.len(), 0);
}

#[tokio::test]
async fn reset_earlier_after_slot_starts() {
time::pause();
Expand Down

0 comments on commit ccf3dee

Please sign in to comment.