summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tokio/src/time/wheel/mod.rs2
-rw-r--r--tokio/tests/time_delay.rs16
2 files changed, 17 insertions, 1 deletions
diff --git a/tokio/src/time/wheel/mod.rs b/tokio/src/time/wheel/mod.rs
index c5f0f458..a2ef27fc 100644
--- a/tokio/src/time/wheel/mod.rs
+++ b/tokio/src/time/wheel/mod.rs
@@ -43,7 +43,7 @@ pub(crate) struct Wheel<T> {
const NUM_LEVELS: usize = 6;
/// 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)]
pub(crate) enum InsertError {
diff --git a/tokio/tests/time_delay.rs b/tokio/tests/time_delay.rs
index 9ab5b709..e763ae03 100644
--- a/tokio/tests/time_delay.rs
+++ b/tokio/tests/time_delay.rs
@@ -155,6 +155,22 @@ async fn greater_than_max() {
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 {
Duration::from_millis(n)
}