-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
time: delay the cancellation of timers #7467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
20a1daf
3e65b07
7618162
4b0a866
78d433f
4727a56
d7f9c72
161ca91
09b27cf
58a13e3
8407dd6
89e132f
9b336b1
cf7211a
8ac5933
ca49b99
fb027a6
9e294d5
abffd46
ccd0ae8
f91caf7
88292d8
bb932b0
4b15736
e89259e
5eee490
6626ad0
65276ac
e4b1e68
009d158
c1e0522
0f3c9ec
6b8eed5
6bb207d
0e9a7e1
93ebb38
6a4f048
2385b3d
782bcba
2fcfb4b
9657e6d
1fff994
c208c3a
fda223d
070ddd6
102e2d2
5d17c33
a17bdde
40cc384
36e71a0
a5c384d
ebd1df1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
#![cfg(feature = "full")] | ||
|
||
use futures::StreamExt; | ||
use tokio::time::{self, sleep, sleep_until, Duration, Instant}; | ||
use tokio::time::{self, sleep, Duration, Instant}; | ||
use tokio_test::{assert_pending, assert_ready, task}; | ||
use tokio_util::time::DelayQueue; | ||
|
||
|
@@ -82,8 +82,6 @@ async fn single_short_delay() { | |
|
||
sleep(ms(5)).await; | ||
|
||
assert!(queue.is_woken()); | ||
|
||
let entry = assert_ready_some!(poll!(queue)); | ||
assert_eq!(*entry.get_ref(), "foo"); | ||
|
||
|
@@ -221,7 +219,7 @@ async fn reset_much_later() { | |
|
||
sleep(ms(20)).await; | ||
|
||
assert!(queue.is_woken()); | ||
assert_ready_some!(poll!(queue)); | ||
} | ||
|
||
// Reproduces tokio-rs/tokio#849. | ||
|
@@ -248,7 +246,7 @@ async fn reset_twice() { | |
|
||
sleep(ms(20)).await; | ||
|
||
assert!(queue.is_woken()); | ||
assert_ready_some!(poll!(queue)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note
|
||
} | ||
|
||
/// Regression test: Given an entry inserted with a deadline in the past, so | ||
|
@@ -412,8 +410,6 @@ async fn expire_first_key_when_reset_to_expire_earlier() { | |
|
||
sleep(ms(100)).await; | ||
|
||
assert!(queue.is_woken()); | ||
|
||
let entry = assert_ready_some!(poll!(queue)).into_inner(); | ||
assert_eq!(entry, "one"); | ||
} | ||
|
@@ -435,8 +431,6 @@ async fn expire_second_key_when_reset_to_expire_earlier() { | |
|
||
sleep(ms(100)).await; | ||
|
||
assert!(queue.is_woken()); | ||
|
||
let entry = assert_ready_some!(poll!(queue)).into_inner(); | ||
assert_eq!(entry, "two"); | ||
} | ||
|
@@ -457,8 +451,6 @@ async fn reset_first_expiring_item_to_expire_later() { | |
queue.reset_at(&one, now + ms(300)); | ||
sleep(ms(250)).await; | ||
|
||
assert!(queue.is_woken()); | ||
|
||
let entry = assert_ready_some!(poll!(queue)).into_inner(); | ||
assert_eq!(entry, "two"); | ||
} | ||
|
@@ -522,43 +514,6 @@ async fn insert_after_ready_poll() { | |
assert_eq!("3", res[2]); | ||
} | ||
|
||
#[tokio::test] | ||
async fn reset_later_after_slot_starts() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NoteThis test was removed because it was testing the behavior of |
||
time::pause(); | ||
|
||
let mut queue = task::spawn(DelayQueue::new()); | ||
|
||
let now = Instant::now(); | ||
|
||
let foo = queue.insert_at("foo", now + ms(100)); | ||
|
||
assert_pending!(poll!(queue)); | ||
|
||
sleep_until(now + Duration::from_millis(80)).await; | ||
|
||
assert!(!queue.is_woken()); | ||
|
||
// At this point the queue hasn't been polled, so `elapsed` on the wheel | ||
// for the queue is still at 0 and hence the 1ms resolution slots cover | ||
// [0-64). Resetting the time on the entry to 120 causes it to get put in | ||
// the [64-128) slot. As the queue knows that the first entry is within | ||
// that slot, but doesn't know when, it must wake immediately to advance | ||
// the wheel. | ||
queue.reset_at(&foo, now + ms(120)); | ||
assert!(queue.is_woken()); | ||
|
||
assert_pending!(poll!(queue)); | ||
|
||
sleep_until(now + Duration::from_millis(119)).await; | ||
assert!(!queue.is_woken()); | ||
|
||
sleep(ms(1)).await; | ||
assert!(queue.is_woken()); | ||
|
||
let entry = assert_ready_some!(poll!(queue)).into_inner(); | ||
assert_eq!(entry, "foo"); | ||
} | ||
|
||
#[tokio::test] | ||
async fn reset_inserted_expired() { | ||
time::pause(); | ||
|
@@ -584,43 +539,6 @@ async fn reset_inserted_expired() { | |
assert_eq!(queue.len(), 0); | ||
} | ||
|
||
#[tokio::test] | ||
async fn reset_earlier_after_slot_starts() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NoteThis test was removed because it was testing the behavior of |
||
time::pause(); | ||
|
||
let mut queue = task::spawn(DelayQueue::new()); | ||
|
||
let now = Instant::now(); | ||
|
||
let foo = queue.insert_at("foo", now + ms(200)); | ||
|
||
assert_pending!(poll!(queue)); | ||
|
||
sleep_until(now + Duration::from_millis(80)).await; | ||
|
||
assert!(!queue.is_woken()); | ||
|
||
// At this point the queue hasn't been polled, so `elapsed` on the wheel | ||
// for the queue is still at 0 and hence the 1ms resolution slots cover | ||
// [0-64). Resetting the time on the entry to 120 causes it to get put in | ||
// the [64-128) slot. As the queue knows that the first entry is within | ||
// that slot, but doesn't know when, it must wake immediately to advance | ||
// the wheel. | ||
queue.reset_at(&foo, now + ms(120)); | ||
assert!(queue.is_woken()); | ||
|
||
assert_pending!(poll!(queue)); | ||
|
||
sleep_until(now + Duration::from_millis(119)).await; | ||
assert!(!queue.is_woken()); | ||
|
||
sleep(ms(1)).await; | ||
assert!(queue.is_woken()); | ||
|
||
let entry = assert_ready_some!(poll!(queue)).into_inner(); | ||
assert_eq!(entry, "foo"); | ||
} | ||
|
||
#[tokio::test] | ||
async fn insert_in_past_after_poll_fires_immediately() { | ||
time::pause(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note
queue.reset_at
resets innerSleep
, however, the new implementation will drop the inner timer and create a new one. So the waker will not be called, we have to poll manually.