mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-25 12:00:35 +00:00
time: prevent panicking in sleep() with large durations (#4495)
This commit is contained in:
parent
37917b821d
commit
0826f763e0
@ -129,7 +129,7 @@ impl ClockTime {
|
||||
.unwrap_or_else(|| Duration::from_secs(0));
|
||||
let ms = dur.as_millis();
|
||||
|
||||
ms.try_into().expect("Duration too far into the future")
|
||||
ms.try_into().unwrap_or(u64::MAX)
|
||||
}
|
||||
|
||||
pub(self) fn tick_to_duration(&self, t: u64) -> Duration {
|
||||
|
@ -235,22 +235,6 @@ async fn long_sleeps() {
|
||||
assert!(tokio::time::Instant::now() <= deadline + Duration::from_millis(1));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[should_panic(expected = "Duration too far into the future")]
|
||||
async fn very_long_sleeps() {
|
||||
tokio::time::pause();
|
||||
|
||||
// Some platforms (eg macos) can't represent times this far in the future
|
||||
if let Some(deadline) = tokio::time::Instant::now().checked_add(Duration::from_secs(1u64 << 62))
|
||||
{
|
||||
tokio::time::sleep_until(deadline).await;
|
||||
} else {
|
||||
// make it pass anyway (we can't skip/ignore the test based on the
|
||||
// result of checked_add)
|
||||
panic!("Duration too far into the future (test ignored)")
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reset_after_firing() {
|
||||
let timer = tokio::time::sleep(std::time::Duration::from_millis(1));
|
||||
|
Loading…
x
Reference in New Issue
Block a user