mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
timer: fix out of bounds error (#2184)
This commit is contained in:
parent
00e3c29e48
commit
e2230f3392
@ -43,7 +43,7 @@ pub(crate) struct Wheel<T> {
|
|||||||
const NUM_LEVELS: usize = 6;
|
const NUM_LEVELS: usize = 6;
|
||||||
|
|
||||||
/// The maximum duration of a delay
|
/// The maximum duration of a delay
|
||||||
const MAX_DURATION: u64 = 1 << (6 * NUM_LEVELS);
|
const MAX_DURATION: u64 = (1 << (6 * NUM_LEVELS)) - 1;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum InsertError {
|
pub(crate) enum InsertError {
|
||||||
|
@ -155,6 +155,22 @@ async fn greater_than_max() {
|
|||||||
time::delay_until(Instant::now() + ms(YR_5)).await;
|
time::delay_until(Instant::now() + ms(YR_5)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const NUM_LEVELS: usize = 6;
|
||||||
|
const MAX_DURATION: u64 = (1 << (6 * NUM_LEVELS)) - 1;
|
||||||
|
|
||||||
|
#[should_panic]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn exactly_max() {
|
||||||
|
// TODO: this should not panic but `time::ms()` is acting up
|
||||||
|
time::delay_for(ms(MAX_DURATION)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn no_out_of_bounds_close_to_max() {
|
||||||
|
time::pause();
|
||||||
|
time::delay_for(ms(MAX_DURATION - 1)).await;
|
||||||
|
}
|
||||||
|
|
||||||
fn ms(n: u64) -> Duration {
|
fn ms(n: u64) -> Duration {
|
||||||
Duration::from_millis(n)
|
Duration::from_millis(n)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user