summaryrefslogtreecommitdiffstats
path: root/vendor/tokio/tests/time_sleep.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/tokio/tests/time_sleep.rs
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tokio/tests/time_sleep.rs')
-rw-r--r--vendor/tokio/tests/time_sleep.rs52
1 files changed, 24 insertions, 28 deletions
diff --git a/vendor/tokio/tests/time_sleep.rs b/vendor/tokio/tests/time_sleep.rs
index e3e27b0c9..94022e3c0 100644
--- a/vendor/tokio/tests/time_sleep.rs
+++ b/vendor/tokio/tests/time_sleep.rs
@@ -24,7 +24,7 @@ async fn immediate_sleep() {
async fn is_elapsed() {
time::pause();
- let sleep = time::sleep(Duration::from_millis(50));
+ let sleep = time::sleep(Duration::from_millis(10));
tokio::pin!(sleep);
@@ -168,6 +168,7 @@ async fn reset_sleep_to_past() {
assert_ready!(sleep.poll());
}
+#[cfg(not(tokio_wasi))] // Wasi doesn't support panic recovery
#[test]
#[should_panic]
fn creating_sleep_outside_of_context() {
@@ -188,10 +189,7 @@ async fn greater_than_max() {
#[tokio::test]
async fn short_sleeps() {
- for i in 0..10000 {
- if (i % 10) == 0 {
- eprintln!("=== {}", i);
- }
+ for _ in 0..10000 {
tokio::time::sleep(std::time::Duration::from_millis(0)).await;
}
}
@@ -236,22 +234,6 @@ async fn long_sleeps() {
}
#[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));
tokio::pin!(timer);
@@ -286,6 +268,20 @@ async fn exactly_max() {
}
#[tokio::test]
+async fn issue_5183() {
+ time::pause();
+
+ let big = std::time::Duration::from_secs(u64::MAX / 10);
+ // This is a workaround since awaiting sleep(big) will never finish.
+ #[rustfmt::skip]
+ tokio::select! {
+ biased;
+ _ = tokio::time::sleep(big) => {}
+ _ = tokio::time::sleep(std::time::Duration::from_nanos(1)) => {}
+ }
+}
+
+#[tokio::test]
async fn no_out_of_bounds_close_to_max() {
time::pause();
time::sleep(ms(MAX_DURATION - 1)).await;
@@ -333,18 +329,18 @@ async fn drop_from_wake() {
tokio::time::pause();
- let mut lock = list.lock().unwrap();
+ {
+ let mut lock = list.lock().unwrap();
- for _ in 0..100 {
- let mut timer = Box::pin(tokio::time::sleep(Duration::from_millis(10)));
+ for _ in 0..100 {
+ let mut timer = Box::pin(tokio::time::sleep(Duration::from_millis(10)));
- let _ = timer.as_mut().poll(&mut Context::from_waker(&arc_wake));
+ let _ = timer.as_mut().poll(&mut Context::from_waker(&arc_wake));
- lock.push(timer);
+ lock.push(timer);
+ }
}
- drop(lock);
-
tokio::time::sleep(Duration::from_millis(11)).await;
assert!(