id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/tests/time_rt.rs:2 | rx.recv().unwrap();
}
#[tokio::test]
async fn starving() {
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
struct Starve<T: Future<Output = ()> + Unpin>(T, u64);
impl<T: Future<Output = ()> + Unpin> Future for Starve<T> {
type Output = u64;
fn poll(mut... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_rt.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/tests/time_rt.rs | 41 | 88 |
tokio-rs/tokio:tokio/tests/time_rt.rs:1 | #![warn(rust_2018_idioms)]
use tokio::time::*;
use std::sync::mpsc;
#[test]
fn timer_with_threaded_runtime() {
use tokio::runtime::Runtime;
let rt = Runtime::new().unwrap();
let (tx, rx) = mpsc::channel();
rt.spawn(async move {
let when = Instant::now() + Duration::from_millis(100);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_rt.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/tests/time_rt.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
#![cfg(not(miri))] // Too slow on Miri.
use std::future::Future;
use std::task::Context;
use futures::task::noop_waker_ref;
use tokio::time::{self, Duration, Instant};
use tokio_test::{assert_elapsed, assert_pending, assert_ready, task};
#[tokio::test]
async fn i... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_sleep.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:2 | }
#[tokio::test]
async fn delayed_sleep_level_0() {
time::pause();
for &i in &[1, 10, 60] {
let now = Instant::now();
let dur = ms(i);
time::sleep_until(now + dur).await;
assert_elapsed!(now, dur);
}
}
#[tokio::test]
async fn sub_ms_delayed_sleep() {
time::pause();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_sleep.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:3 | }
#[tokio::test]
async fn reset_future_sleep_before_fire() {
time::pause();
let now = Instant::now();
let mut sleep = task::spawn(Box::pin(time::sleep_until(now + ms(100))));
assert_pending!(sleep.poll());
let mut sleep = sleep.into_inner();
sleep.as_mut().reset(Instant::now() + ms(200));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_sleep.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:4 | let now = Instant::now();
let mut sleep = task::spawn(Box::pin(time::sleep_until(now + ms(100))));
assert_pending!(sleep.poll());
let mut sleep = sleep.into_inner();
time::sleep(ms(10)).await;
sleep.as_mut().reset(now + ms(80));
sleep.await;
assert_elapsed!(now, ms(80));
}
#[tokio::tes... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_sleep.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:5 | assert!(!sleep.is_woken());
sleep.as_mut().reset(now + ms(40));
// TODO: is this required?
//assert!(sleep.is_woken());
assert_ready!(sleep.poll());
}
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery
#[test]
#[should_panic]
fn creating_sleep_outside_of_context() {
let now =... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_sleep.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:6 | for _ in 0..5u32 {
tokio::time::sleep(Duration::from_secs(
// about a year
365 * 24 * 3600,
))
.await;
}
let deadline = tokio::time::Instant::now()
+ Duration::from_secs(
// about 10 years
10 * 365 * 24 * 3600,
);
toki... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_sleep.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:7 | let deadline = timer.deadline();
timer.as_mut().await;
assert_ready!(timer
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref())));
timer
.as_mut()
.reset(tokio::time::Instant::now() + std::time::Duration::from_secs(600));
assert_ne!(deadline, timer.deadline());
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_sleep.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:8 | #[tokio::test]
async fn no_out_of_bounds_close_to_max() {
time::pause();
time::sleep(Duration::MAX - Duration::from_millis(1)).await;
}
fn ms(n: u64) -> Duration {
Duration::from_millis(n)
}
#[tokio::test]
async fn drop_after_reschedule_at_new_scheduled_time() {
use futures::poll;
tokio::time::pa... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_sleep.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:9 | let panicked = Arc::new(AtomicBool::new(false));
let list: Arc<Mutex<Vec<Pin<Box<tokio::time::Sleep>>>>> = Arc::new(Mutex::new(Vec::new()));
let arc_wake = Arc::new(DropWaker(panicked.clone(), list.clone()));
let arc_wake = futures::task::waker(arc_wake);
tokio::time::pause();
{
let mut l... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_sleep.rs | 321 | 366 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:7 | let deadline = timer.deadline();
timer.as_mut().await;
assert_ready!(timer
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref())));
timer
.as_mut()
.reset(tokio::time::Instant::now() + std::time::Duration::from_secs(600));
assert_ne!(deadline, timer.deadline());
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 161b8c80d58a4a070c7f41db18d43ea258737db7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/161b8c80d58a4a070c7f41db18d43ea258737db7/tokio/tests/time_sleep.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:8 | _ = 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;
}
fn ms(n: u64) -> Duration {
Duration::from_millis(n)
}
#[tokio::test]
async fn drop_after_reschedule_at_new_schedule... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 161b8c80d58a4a070c7f41db18d43ea258737db7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/161b8c80d58a4a070c7f41db18d43ea258737db7/tokio/tests/time_sleep.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:9 | use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::task::Context;
let panicked = Arc::new(AtomicBool::new(false));
let list: Arc<Mutex<Vec<Pin<Box<tokio::time::Sleep>>>>> = Arc::new(Mutex::new(Vec::new()));
let arc_wake = Arc::new(DropWaker(panicked.clone(), list.... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 161b8c80d58a4a070c7f41db18d43ea258737db7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/161b8c80d58a4a070c7f41db18d43ea258737db7/tokio/tests/time_sleep.rs | 321 | 369 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use std::future::Future;
use std::task::Context;
use futures::task::noop_waker_ref;
use tokio::time::{self, Duration, Instant};
use tokio_test::{assert_elapsed, assert_pending, assert_ready, task};
#[tokio::test]
async fn immediate_sleep() {
time::pause();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 8cd3383913e343b01e43b2bf4a36e466eaba3216 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8cd3383913e343b01e43b2bf4a36e466eaba3216/tokio/tests/time_sleep.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:2 | #[tokio::test]
async fn delayed_sleep_level_0() {
time::pause();
for &i in &[1, 10, 60] {
let now = Instant::now();
let dur = ms(i);
time::sleep_until(now + dur).await;
assert_elapsed!(now, dur);
}
}
#[tokio::test]
async fn sub_ms_delayed_sleep() {
time::pause();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 8cd3383913e343b01e43b2bf4a36e466eaba3216 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8cd3383913e343b01e43b2bf4a36e466eaba3216/tokio/tests/time_sleep.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:3 | #[tokio::test]
async fn reset_future_sleep_before_fire() {
time::pause();
let now = Instant::now();
let mut sleep = task::spawn(Box::pin(time::sleep_until(now + ms(100))));
assert_pending!(sleep.poll());
let mut sleep = sleep.into_inner();
sleep.as_mut().reset(Instant::now() + ms(200));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 8cd3383913e343b01e43b2bf4a36e466eaba3216 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8cd3383913e343b01e43b2bf4a36e466eaba3216/tokio/tests/time_sleep.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:4 | let mut sleep = task::spawn(Box::pin(time::sleep_until(now + ms(100))));
assert_pending!(sleep.poll());
let mut sleep = sleep.into_inner();
time::sleep(ms(10)).await;
sleep.as_mut().reset(now + ms(80));
sleep.await;
assert_elapsed!(now, ms(80));
}
#[tokio::test]
async fn reset_future_sleep_... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 8cd3383913e343b01e43b2bf4a36e466eaba3216 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8cd3383913e343b01e43b2bf4a36e466eaba3216/tokio/tests/time_sleep.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:5 | assert!(!sleep.is_woken());
sleep.as_mut().reset(now + ms(40));
// TODO: is this required?
//assert!(sleep.is_woken());
assert_ready!(sleep.poll());
}
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery
#[test]
#[should_panic]
fn creating_sleep_outside_of_context() {
let now =... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 8cd3383913e343b01e43b2bf4a36e466eaba3216 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8cd3383913e343b01e43b2bf4a36e466eaba3216/tokio/tests/time_sleep.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:7 | let deadline = timer.deadline();
timer.as_mut().await;
assert_ready!(timer
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref())));
timer
.as_mut()
.reset(tokio::time::Instant::now() + std::time::Duration::from_secs(600));
assert_ne!(deadline, timer.deadline());
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 8cd3383913e343b01e43b2bf4a36e466eaba3216 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8cd3383913e343b01e43b2bf4a36e466eaba3216/tokio/tests/time_sleep.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:8 | }
}
#[tokio::test]
async fn no_out_of_bounds_close_to_max() {
time::pause();
time::sleep(ms(MAX_DURATION - 1)).await;
}
fn ms(n: u64) -> Duration {
Duration::from_millis(n)
}
#[tokio::test]
async fn drop_after_reschedule_at_new_scheduled_time() {
use futures::poll;
tokio::time::pause();
let... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 8cd3383913e343b01e43b2bf4a36e466eaba3216 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8cd3383913e343b01e43b2bf4a36e466eaba3216/tokio/tests/time_sleep.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:9 | use std::sync::{Arc, Mutex};
use std::task::Context;
let panicked = Arc::new(AtomicBool::new(false));
let list: Arc<Mutex<Vec<Pin<Box<tokio::time::Sleep>>>>> = Arc::new(Mutex::new(Vec::new()));
let arc_wake = Arc::new(DropWaker(panicked.clone(), list.clone()));
let arc_wake = futures::task::waker(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 8cd3383913e343b01e43b2bf4a36e466eaba3216 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8cd3383913e343b01e43b2bf4a36e466eaba3216/tokio/tests/time_sleep.rs | 321 | 368 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:5 | assert!(!sleep.is_woken());
sleep.as_mut().reset(now + ms(40));
// TODO: is this required?
//assert!(sleep.is_woken());
assert_ready!(sleep.poll());
}
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery
#[test]
#[should_panic]
fn creating_sleep_outside_of_context() {
let now =... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | c445e467ce4363b3a9b6825268814a9bc27c0127 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c445e467ce4363b3a9b6825268814a9bc27c0127/tokio/tests/time_sleep.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:4 | let mut sleep = task::spawn(Box::pin(time::sleep_until(now + ms(100))));
assert_pending!(sleep.poll());
let mut sleep = sleep.into_inner();
time::sleep(ms(10)).await;
sleep.as_mut().reset(now + ms(80));
sleep.await;
assert_elapsed!(now, ms(80));
}
#[tokio::test]
async fn reset_future_sleep_... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 2a54ad01d0945c851a093849c83019de69e98dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2a54ad01d0945c851a093849c83019de69e98dee/tokio/tests/time_sleep.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:5 | assert!(!sleep.is_woken());
sleep.as_mut().reset(now + ms(40));
// TODO: is this required?
//assert!(sleep.is_woken());
assert_ready!(sleep.poll());
}
#[cfg(not(tokio_wasi))] // Wasi doesn't support panic recovery
#[test]
#[should_panic]
fn creating_sleep_outside_of_context() {
let now = Instant... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 2a54ad01d0945c851a093849c83019de69e98dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2a54ad01d0945c851a093849c83019de69e98dee/tokio/tests/time_sleep.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:7 | let deadline = timer.deadline();
timer.as_mut().await;
assert_ready!(timer
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref())));
timer
.as_mut()
.reset(tokio::time::Instant::now() + std::time::Duration::from_secs(600));
assert_ne!(deadline, timer.deadline());
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/tests/time_sleep.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:8 | async fn drop_after_reschedule_at_new_scheduled_time() {
use futures::poll;
tokio::time::pause();
let start = tokio::time::Instant::now();
let mut a = Box::pin(tokio::time::sleep(Duration::from_millis(5)));
let mut b = Box::pin(tokio::time::sleep(Duration::from_millis(5)));
let mut c = Box::p... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/tests/time_sleep.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:9 | 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));
lock.push(timer);
}
}
tokio::time::sleep(Duration::from_millis(11)).await;
assert!(
!panicked.l... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | fc9518b62714daac9a38b46c698b94ac5d5b1ca2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fc9518b62714daac9a38b46c698b94ac5d5b1ca2/tokio/tests/time_sleep.rs | 321 | 354 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:8 | async fn drop_after_reschedule_at_new_scheduled_time() {
use futures::poll;
tokio::time::pause();
let start = tokio::time::Instant::now();
let mut a = Box::pin(tokio::time::sleep(Duration::from_millis(5)));
let mut b = Box::pin(tokio::time::sleep(Duration::from_millis(5)));
let mut c = Box::p... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 57e08e714754420f8b3d8ffe863549d8acf761d0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/57e08e714754420f8b3d8ffe863549d8acf761d0/tokio/tests/time_sleep.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:9 | let mut timer = Box::pin(tokio::time::sleep(Duration::from_millis(10)));
let _ = timer.as_mut().poll(&mut Context::from_waker(&arc_wake));
lock.push(timer);
}
drop(lock);
tokio::time::sleep(Duration::from_millis(11)).await;
assert!(
!panicked.load(Ordering::SeqCst),
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 57e08e714754420f8b3d8ffe863549d8acf761d0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/57e08e714754420f8b3d8ffe863549d8acf761d0/tokio/tests/time_sleep.rs | 321 | 354 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:5 | assert!(!sleep.is_woken());
sleep.as_mut().reset(now + ms(40));
// TODO: is this required?
//assert!(sleep.is_woken());
assert_ready!(sleep.poll());
}
#[cfg(not(tokio_wasi))] // Wasi doesn't support panic recovery
#[test]
#[should_panic]
fn creating_sleep_outside_of_context() {
let now = Instant... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/time_sleep.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:6 | async fn multi_long_sleeps() {
tokio::time::pause();
for _ in 0..5u32 {
tokio::time::sleep(Duration::from_secs(
// about a year
365 * 24 * 3600,
))
.await;
}
let deadline = tokio::time::Instant::now()
+ Duration::from_secs(
// about 1... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/time_sleep.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:7 | let timer = tokio::time::sleep(std::time::Duration::from_millis(1));
tokio::pin!(timer);
let deadline = timer.deadline();
timer.as_mut().await;
assert_ready!(timer
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref())));
timer
.as_mut()
.reset(tokio::time::Inst... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/time_sleep.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:8 | }
#[tokio::test]
async fn drop_after_reschedule_at_new_scheduled_time() {
use futures::poll;
tokio::time::pause();
let start = tokio::time::Instant::now();
let mut a = Box::pin(tokio::time::sleep(Duration::from_millis(5)));
let mut b = Box::pin(tokio::time::sleep(Duration::from_millis(5)));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/time_sleep.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:9 | let mut lock = list.lock().unwrap();
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));
lock.push(timer);
}
drop(lock);
tokio::time::sleep(Duration::from_millis(11)).awa... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/time_sleep.rs | 321 | 357 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:5 | assert!(!sleep.is_woken());
sleep.as_mut().reset(now + ms(40));
// TODO: is this required?
//assert!(sleep.is_woken());
assert_ready!(sleep.poll());
}
#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery
#[test]
#[should_panic]
fn creating_sleep_outside_of_context() {
let now =... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 6d3f92dddc510e9276191cfab1b0432ce8248589 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6d3f92dddc510e9276191cfab1b0432ce8248589/tokio/tests/time_sleep.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:4 | let mut sleep = task::spawn(Box::pin(time::sleep_until(now + ms(100))));
assert_pending!(sleep.poll());
let mut sleep = sleep.into_inner();
time::sleep(ms(10)).await;
sleep.as_mut().reset(now + ms(80));
sleep.await;
assert_elapsed!(now, ms(80));
}
#[tokio::test]
async fn reset_future_sleep_... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 0826f763e04c5d86050c35bf7af9055e095263d3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0826f763e04c5d86050c35bf7af9055e095263d3/tokio/tests/time_sleep.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:5 | assert!(!sleep.is_woken());
sleep.as_mut().reset(now + ms(40));
// TODO: is this required?
//assert!(sleep.is_woken());
assert_ready!(sleep.poll());
}
#[test]
#[should_panic]
fn creating_sleep_outside_of_context() {
let now = Instant::now();
// This creates a delay outside of the context of... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 0826f763e04c5d86050c35bf7af9055e095263d3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0826f763e04c5d86050c35bf7af9055e095263d3/tokio/tests/time_sleep.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:6 | tokio::time::pause();
for _ in 0..5u32 {
tokio::time::sleep(Duration::from_secs(
// about a year
365 * 24 * 3600,
))
.await;
}
let deadline = tokio::time::Instant::now()
+ Duration::from_secs(
// about 10 years
10 * 365 * 24 *... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 0826f763e04c5d86050c35bf7af9055e095263d3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0826f763e04c5d86050c35bf7af9055e095263d3/tokio/tests/time_sleep.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:7 | tokio::pin!(timer);
let deadline = timer.deadline();
timer.as_mut().await;
assert_ready!(timer
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref())));
timer
.as_mut()
.reset(tokio::time::Instant::now() + std::time::Duration::from_secs(600));
assert_ne!(deadli... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 0826f763e04c5d86050c35bf7af9055e095263d3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0826f763e04c5d86050c35bf7af9055e095263d3/tokio/tests/time_sleep.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:8 | #[tokio::test]
async fn drop_after_reschedule_at_new_scheduled_time() {
use futures::poll;
tokio::time::pause();
let start = tokio::time::Instant::now();
let mut a = Box::pin(tokio::time::sleep(Duration::from_millis(5)));
let mut b = Box::pin(tokio::time::sleep(Duration::from_millis(5)));
let... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 0826f763e04c5d86050c35bf7af9055e095263d3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0826f763e04c5d86050c35bf7af9055e095263d3/tokio/tests/time_sleep.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:9 | 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));
lock.push(timer);
}
drop(lock);
tokio::time::sleep(Duration::from_millis(11)).await;
assert!(
!panicked.load(O... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 0826f763e04c5d86050c35bf7af9055e095263d3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0826f763e04c5d86050c35bf7af9055e095263d3/tokio/tests/time_sleep.rs | 321 | 356 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:6 | tokio::time::pause();
for _ in 0..5u32 {
tokio::time::sleep(Duration::from_secs(
// about a year
365 * 24 * 3600,
))
.await;
}
let deadline = tokio::time::Instant::now()
+ Duration::from_secs(
// about 10 years
10 * 365 * 24 *... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 0d9430b99cc699824cc8545afbb01e0a7c520428 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d9430b99cc699824cc8545afbb01e0a7c520428/tokio/tests/time_sleep.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:7 | 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/ign... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 0d9430b99cc699824cc8545afbb01e0a7c520428 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d9430b99cc699824cc8545afbb01e0a7c520428/tokio/tests/time_sleep.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:8 | #[tokio::test]
async fn exactly_max() {
time::pause();
time::sleep(ms(MAX_DURATION)).await;
}
#[tokio::test]
async fn no_out_of_bounds_close_to_max() {
time::pause();
time::sleep(ms(MAX_DURATION - 1)).await;
}
fn ms(n: u64) -> Duration {
Duration::from_millis(n)
}
#[tokio::test]
async fn drop_aft... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 0d9430b99cc699824cc8545afbb01e0a7c520428 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d9430b99cc699824cc8545afbb01e0a7c520428/tokio/tests/time_sleep.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:9 | async fn drop_from_wake() {
use std::future::Future;
use std::pin::Pin;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::task::Context;
let panicked = Arc::new(AtomicBool::new(false));
let list: Arc<Mutex<Vec<Pin<Box<tokio::time::Sleep>>>>> = Arc::new(Mut... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 0d9430b99cc699824cc8545afbb01e0a7c520428 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d9430b99cc699824cc8545afbb01e0a7c520428/tokio/tests/time_sleep.rs | 321 | 372 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:10 | impl futures::task::ArcWake for DropWaker {
fn wake_by_ref(arc_self: &Arc<Self>) {
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
*arc_self.1.lock().expect("panic in lock") = Vec::new()
}));
if result.is_err() {
arc_se... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 0d9430b99cc699824cc8545afbb01e0a7c520428 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d9430b99cc699824cc8545afbb01e0a7c520428/tokio/tests/time_sleep.rs | 361 | 372 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use std::future::Future;
use std::task::Context;
use futures::task::noop_waker_ref;
use tokio::time::{self, Duration, Instant};
use tokio_test::{assert_elapsed, assert_pending, assert_ready, task};
#[tokio::test]
async fn immediate_sleep() {
time::pause();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/tests/time_sleep.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:9 | async fn drop_from_wake() {
use std::future::Future;
use std::pin::Pin;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::task::Context;
let panicked = Arc::new(AtomicBool::new(false));
let list: Arc<Mutex<Vec<Pin<Box<tokio::time::Sleep>>>>> = Arc::new(Mut... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 8ef39dfb22974e6f5f6203e279912d3eac68017d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8ef39dfb22974e6f5f6203e279912d3eac68017d/tokio/tests/time_sleep.rs | 321 | 372 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use std::future::Future;
use std::task::Context;
use futures::task::noop_waker_ref;
use tokio::time::{self, Duration, Instant};
use tokio_test::{assert_pending, assert_ready, task};
macro_rules! assert_elapsed {
($now:expr, $ms:expr) => {{
let elapsed... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | d74d17307dd53215061c4a8a1f20a0e30461e296 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d74d17307dd53215061c4a8a1f20a0e30461e296/tokio/tests/time_sleep.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:2 | let sleep = time::sleep(Duration::from_millis(50));
tokio::pin!(sleep);
assert!(!sleep.is_elapsed());
assert!(futures::poll!(sleep.as_mut()).is_pending());
assert!(!sleep.is_elapsed());
sleep.as_mut().await;
assert!(sleep.is_elapsed());
}
#[tokio::test]
async fn delayed_sleep_level_0() {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | d74d17307dd53215061c4a8a1f20a0e30461e296 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d74d17307dd53215061c4a8a1f20a0e30461e296/tokio/tests/time_sleep.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:3 | }
}
#[tokio::test]
async fn delayed_sleep_wrapping_level_0() {
time::pause();
time::sleep(ms(5)).await;
let now = Instant::now();
time::sleep_until(now + ms(60)).await;
assert_elapsed!(now, 60);
}
#[tokio::test]
async fn reset_future_sleep_before_fire() {
time::pause();
let now = Insta... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | d74d17307dd53215061c4a8a1f20a0e30461e296 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d74d17307dd53215061c4a8a1f20a0e30461e296/tokio/tests/time_sleep.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:4 | let mut sleep = sleep.into_inner();
sleep.as_mut().reset(now + ms(80));
sleep.await;
assert_elapsed!(now, 80);
}
#[tokio::test]
async fn reset_past_sleep_before_fire() {
time::pause();
let now = Instant::now();
let mut sleep = task::spawn(Box::pin(time::sleep_until(now + ms(100))));
ass... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | d74d17307dd53215061c4a8a1f20a0e30461e296 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d74d17307dd53215061c4a8a1f20a0e30461e296/tokio/tests/time_sleep.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:5 | assert_elapsed!(now, 110);
}
#[tokio::test]
async fn reset_sleep_to_past() {
time::pause();
let now = Instant::now();
let mut sleep = task::spawn(Box::pin(time::sleep_until(now + ms(100))));
assert_pending!(sleep.poll());
time::sleep(ms(50)).await;
assert!(!sleep.is_woken());
sleep.as_... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | d74d17307dd53215061c4a8a1f20a0e30461e296 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d74d17307dd53215061c4a8a1f20a0e30461e296/tokio/tests/time_sleep.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:6 | }
#[tokio::test]
async fn short_sleeps() {
for i in 0..10000 {
if (i % 10) == 0 {
eprintln!("=== {}", i);
}
tokio::time::sleep(std::time::Duration::from_millis(0)).await;
}
}
#[tokio::test]
async fn multi_long_sleeps() {
tokio::time::pause();
for _ in 0..5u32 {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | d74d17307dd53215061c4a8a1f20a0e30461e296 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d74d17307dd53215061c4a8a1f20a0e30461e296/tokio/tests/time_sleep.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:7 | + Duration::from_secs(
// about 10 years
10 * 365 * 24 * 3600,
);
tokio::time::sleep_until(deadline).await;
assert!(tokio::time::Instant::now() >= deadline);
assert!(tokio::time::Instant::now() <= deadline + Duration::from_millis(1));
}
#[tokio::test]
#[should_panic(expect... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | d74d17307dd53215061c4a8a1f20a0e30461e296 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d74d17307dd53215061c4a8a1f20a0e30461e296/tokio/tests/time_sleep.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:8 | .reset(tokio::time::Instant::now() + std::time::Duration::from_secs(600));
assert_ne!(deadline, timer.deadline());
assert_pending!(timer
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref())));
assert_pending!(timer
.as_mut()
.poll(&mut Context::from_waker(noop_waker_r... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | d74d17307dd53215061c4a8a1f20a0e30461e296 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d74d17307dd53215061c4a8a1f20a0e30461e296/tokio/tests/time_sleep.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:9 | let mut b = Box::pin(tokio::time::sleep(Duration::from_millis(5)));
let mut c = Box::pin(tokio::time::sleep(Duration::from_millis(10)));
let _ = poll!(&mut a);
let _ = poll!(&mut b);
let _ = poll!(&mut c);
b.as_mut().reset(start + Duration::from_millis(10));
a.await;
drop(b);
}
#[tokio::... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | d74d17307dd53215061c4a8a1f20a0e30461e296 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d74d17307dd53215061c4a8a1f20a0e30461e296/tokio/tests/time_sleep.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:10 | tokio::time::sleep(Duration::from_millis(11)).await;
assert!(
!panicked.load(Ordering::SeqCst),
"paniced when dropping timers"
);
#[derive(Clone)]
struct DropWaker(
Arc<AtomicBool>,
Arc<Mutex<Vec<Pin<Box<tokio::time::Sleep>>>>>,
);
impl futures::task::ArcWake f... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | d74d17307dd53215061c4a8a1f20a0e30461e296 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d74d17307dd53215061c4a8a1f20a0e30461e296/tokio/tests/time_sleep.rs | 361 | 386 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:8 | .reset(tokio::time::Instant::now() + std::time::Duration::from_secs(600));
assert_ne!(deadline, timer.deadline());
assert_pending!(timer
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref())));
assert_pending!(timer
.as_mut()
.poll(&mut Context::from_waker(noop_waker_r... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 9706ca92a8deb69d6e29265f21424042fea966c5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9706ca92a8deb69d6e29265f21424042fea966c5/tokio/tests/time_sleep.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:9 | let mut b = tokio::time::sleep(Duration::from_millis(5));
let mut c = tokio::time::sleep(Duration::from_millis(10));
let _ = poll!(&mut a);
let _ = poll!(&mut b);
let _ = poll!(&mut c);
b.reset(start + Duration::from_millis(10));
a.await;
drop(b);
}
#[tokio::test]
async fn drop_from_wake... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 9706ca92a8deb69d6e29265f21424042fea966c5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9706ca92a8deb69d6e29265f21424042fea966c5/tokio/tests/time_sleep.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:10 | tokio::time::sleep(Duration::from_millis(11)).await;
assert!(
!panicked.load(Ordering::SeqCst),
"paniced when dropping timers"
);
#[derive(Clone)]
struct DropWaker(Arc<AtomicBool>, Arc<Mutex<Vec<tokio::time::Sleep>>>);
impl futures::task::ArcWake for DropWaker {
fn wake_by... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 9706ca92a8deb69d6e29265f21424042fea966c5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9706ca92a8deb69d6e29265f21424042fea966c5/tokio/tests/time_sleep.rs | 361 | 382 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:8 | .reset(tokio::time::Instant::now() + std::time::Duration::from_secs(600));
assert_ne!(deadline, timer.deadline());
assert_pending!(timer
.as_mut()
.poll(&mut Context::from_waker(noop_waker_ref())));
assert_pending!(timer
.as_mut()
.poll(&mut Context::from_waker(noop_waker_r... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | ae67851f11b7cc1f577de8ce21767ce3e2c7aff9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ae67851f11b7cc1f577de8ce21767ce3e2c7aff9/tokio/tests/time_sleep.rs | 281 | 310 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use tokio::time::{self, Duration, Instant};
use tokio_test::{assert_pending, assert_ready, task};
macro_rules! assert_elapsed {
($now:expr, $ms:expr) => {{
let elapsed = $now.elapsed();
let lower = ms($ms);
// Handles ms rounding
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 9d0c0dd22cfa028af63798671c781b1fd83562e2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d0c0dd22cfa028af63798671c781b1fd83562e2/tokio/tests/time_sleep.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:2 | assert_elapsed!(now, i);
}
}
#[tokio::test]
async fn sub_ms_delayed_sleep() {
time::pause();
for _ in 0..5 {
let now = Instant::now();
let deadline = now + ms(1) + Duration::new(0, 1);
time::sleep_until(deadline).await;
assert_elapsed!(now, 1);
}
}
#[tokio::test]
asy... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 9d0c0dd22cfa028af63798671c781b1fd83562e2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d0c0dd22cfa028af63798671c781b1fd83562e2/tokio/tests/time_sleep.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:3 | let mut sleep = sleep.into_inner();
sleep.reset(Instant::now() + ms(200));
sleep.await;
assert_elapsed!(now, 200);
}
#[tokio::test]
async fn reset_past_sleep_before_turn() {
time::pause();
let now = Instant::now();
let mut sleep = task::spawn(time::sleep_until(now + ms(100)));
assert_pe... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 9d0c0dd22cfa028af63798671c781b1fd83562e2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d0c0dd22cfa028af63798671c781b1fd83562e2/tokio/tests/time_sleep.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:4 | assert_elapsed!(now, 80);
}
#[tokio::test]
async fn reset_future_sleep_after_fire() {
time::pause();
let now = Instant::now();
let mut sleep = time::sleep_until(now + ms(100));
(&mut sleep).await;
assert_elapsed!(now, 100);
sleep.reset(now + ms(110));
sleep.await;
assert_elapsed!(now... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 9d0c0dd22cfa028af63798671c781b1fd83562e2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d0c0dd22cfa028af63798671c781b1fd83562e2/tokio/tests/time_sleep.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/time_sleep.rs:5 | #[should_panic]
fn creating_sleep_outside_of_context() {
let now = Instant::now();
// This creates a delay outside of the context of a mock timer. This tests
// that it will panic.
let _fut = time::sleep_until(now + ms(500));
}
#[should_panic]
#[tokio::test]
async fn greater_than_max() {
const YR_... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_sleep.rs | MIT | 9d0c0dd22cfa028af63798671c781b1fd83562e2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d0c0dd22cfa028af63798671c781b1fd83562e2/tokio/tests/time_sleep.rs | 161 | 197 |
tokio-rs/tokio:tokio/tests/time_throttle.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use tokio::stream::StreamExt;
use tokio::time;
use tokio_test::*;
use std::time::Duration;
#[tokio::test]
async fn usage() {
time::pause();
let mut stream = task::spawn(futures::stream::repeat(()).throttle(Duration::from_millis(100)));
assert_ready!(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_throttle.rs | MIT | 5cdb6f8fd6be35f971d8ef7ea8984f4d01965620 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5cdb6f8fd6be35f971d8ef7ea8984f4d01965620/tokio/tests/time_throttle.rs | 1 | 28 |
tokio-rs/tokio:tokio/tests/time_throttle.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use tokio::time::{self, throttle};
use tokio_test::*;
use std::time::Duration;
#[tokio::test]
async fn usage() {
time::pause();
let mut stream = task::spawn(throttle(
Duration::from_millis(100),
futures::stream::repeat(()),
));
as... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_throttle.rs | MIT | 4b85565bd7ad973cd990977ed251d3cecfb50d0b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b85565bd7ad973cd990977ed251d3cecfb50d0b/tokio/tests/time_throttle.rs | 1 | 30 |
tokio-rs/tokio:tokio/tests/time_throttle.rs:1 | #![warn(rust_2018_idioms)]
use tokio::sync::mpsc;
use tokio::time::throttle::Throttle;
use tokio::time::Instant;
use tokio_test::{assert_pending, assert_ready_eq};
use futures::future::poll_fn;
use futures::StreamExt;
use std::task::Poll;
use std::time::Duration;
#[tokio::test]
async fn throttle() {
let (mut tx,... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_throttle.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/tests/time_throttle.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/time_throttle.rs:2 | let mut stream = Throttle::new(rx, ms(0));
poll_fn(|cx| {
assert_pending!(stream.poll_next_unpin(cx));
for i in 0..3 {
tx.try_send(i).unwrap();
}
Poll::Ready(())
})
.await;
poll_fn(|cx| {
for i in 0..3 {
assert_ready_eq!(stream.poll_nex... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_throttle.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/tests/time_throttle.rs | 41 | 68 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use tokio::sync::oneshot;
use tokio::time::{self, timeout, timeout_at, Instant};
use tokio_test::*;
use futures::future::pending;
use std::time::Duration;
#[tokio::test]
async fn simultaneous_deadline_future_completion() {
// Create a future that is immediatel... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_timeout.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:2 | // Turn the timer, it runs for the elapsed time
time::advance(ms(90)).await;
assert_pending!(fut.poll());
// Complete the future
tx.send(()).unwrap();
assert!(fut.is_woken());
assert_ready_ok!(fut.poll()).unwrap();
}
#[tokio::test]
async fn future_and_timeout_in_future() {
time::pause();... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:3 | // Not yet complete
let (tx, rx) = oneshot::channel();
// copy-paste unstable `Duration::MAX`
let duration_max = Duration::from_secs(u64::MAX) + Duration::from_nanos(999_999_999);
// Wrap it with a deadline
let mut fut = task::spawn(timeout(duration_max, rx));
// Ready!
assert_pending!(fu... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:4 | #[tokio::test]
async fn deadline_future_elapses() {
time::pause();
// Wrap it with a deadline
let mut fut = task::spawn(timeout_at(Instant::now() + ms(300), pending::<()>()));
assert_pending!(fut.poll());
time::advance(ms(301)).await;
assert!(fut.is_woken());
assert_ready_err!(fut.poll()... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_timeout.rs | 121 | 151 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use tokio::sync::oneshot;
use tokio::time::{self, timeout, timeout_at, Instant};
use tokio_test::*;
use futures::future::pending;
use std::time::Duration;
#[tokio::test]
async fn simultaneous_deadline_future_completion() {
// Create a future that is immediatel... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | b2ada60e701d5c9e6644cf8fc42a100774f8e23f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/tests/time_timeout.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use tokio::sync::oneshot;
use tokio::time::{self, timeout, timeout_at, Instant};
use tokio_test::*;
use futures::future::pending;
use std::time::Duration;
#[tokio::test]
async fn simultaneous_deadline_future_completion() {
// Create a future that is immediatel... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | 54e6693dff86e6e9d687ed3952bbc2c68bb6db8d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/54e6693dff86e6e9d687ed3952bbc2c68bb6db8d/tokio/tests/time_timeout.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:3 | // Not yet complete
let (tx, rx) = oneshot::channel();
// copy-paste unstable `Duration::MAX`
let duration_max = Duration::from_secs(u64::MAX) + Duration::from_nanos(999_999_999);
// Wrap it with a deadline
let mut fut = task::spawn(timeout(duration_max, rx));
// Ready!
assert_pending!(fu... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | 54e6693dff86e6e9d687ed3952bbc2c68bb6db8d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/54e6693dff86e6e9d687ed3952bbc2c68bb6db8d/tokio/tests/time_timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:4 | async fn deadline_future_elapses() {
time::pause();
// Wrap it with a deadline
let mut fut = task::spawn(timeout_at(Instant::now() + ms(300), pending::<()>()));
assert_pending!(fut.poll());
time::advance(ms(301)).await;
assert!(fut.is_woken());
assert_ready_err!(fut.poll());
}
fn ms(n: ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | 54e6693dff86e6e9d687ed3952bbc2c68bb6db8d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/54e6693dff86e6e9d687ed3952bbc2c68bb6db8d/tokio/tests/time_timeout.rs | 121 | 150 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:3 | // Not yet complete
let (tx, rx) = oneshot::channel();
// copy-paste unstable `Duration::MAX`
let duration_max = Duration::from_secs(u64::MAX) + Duration::from_nanos(999_999_999);
// Wrap it with a deadline
let mut fut = task::spawn(timeout(duration_max, rx));
// Ready!
assert_pending!(fu... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | d2ad7afd21e4faef05ccccb0288bc814a954b990 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2ad7afd21e4faef05ccccb0288bc814a954b990/tokio/tests/time_timeout.rs | 81 | 137 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:4 | async fn deadline_future_elapses() {
time::pause();
// Wrap it with a deadline
let mut fut = task::spawn(timeout_at(Instant::now() + ms(300), pending::<()>()));
assert_pending!(fut.poll());
time::advance(ms(301)).await;
assert!(fut.is_woken());
assert_ready_err!(fut.poll());
}
fn ms(n: ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | d2ad7afd21e4faef05ccccb0288bc814a954b990 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2ad7afd21e4faef05ccccb0288bc814a954b990/tokio/tests/time_timeout.rs | 121 | 137 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:2 | // Turn the timer, it runs for the elapsed time
time::advance(ms(90)).await;
assert_pending!(fut.poll());
// Complete the future
tx.send(()).unwrap();
assert!(fut.is_woken());
assert_ready_ok!(fut.poll()).unwrap();
}
#[tokio::test]
async fn future_and_timeout_in_future() {
time::pause();... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | 7b4c999341809588a427a9a80d310ee4aa1c1a21 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b4c999341809588a427a9a80d310ee4aa1c1a21/tokio/tests/time_timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:3 | time::pause();
// Wrap it with a deadline
let mut fut = task::spawn(timeout_at(Instant::now(), pending::<()>()));
// Factor in jitter
// TODO: don't require this
time::advance(ms(1)).await;
assert_ready_err!(fut.poll());
}
#[tokio::test]
async fn deadline_future_elapses() {
time::pause()... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | 7b4c999341809588a427a9a80d310ee4aa1c1a21 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b4c999341809588a427a9a80d310ee4aa1c1a21/tokio/tests/time_timeout.rs | 81 | 110 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:1 | #![warn(rust_2018_idioms)]
use tokio::sync::oneshot;
use tokio::time::{self, timeout, timeout_at, Instant};
use tokio_test::*;
use futures::future::pending;
use std::time::Duration;
#[tokio::test]
async fn simultaneous_deadline_future_completion() {
// Create a future that is immediately ready
let mut fut = ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/tests/time_timeout.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:2 | time::advance(ms(90)).await;
assert_pending!(fut.poll());
// Complete the future
tx.send(()).unwrap();
assert!(fut.is_woken());
assert_ready_ok!(fut.poll()).unwrap();
}
#[tokio::test]
async fn future_and_timeout_in_future() {
time::pause();
// Not yet complete
let (tx, rx) = oneshot... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/tests/time_timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:3 | // Wrap it with a deadline
let mut fut = task::spawn(timeout_at(Instant::now(), pending::<()>()));
// Factor in jitter
// TODO: don't require this
time::advance(ms(1)).await;
assert_ready_err!(fut.poll());
}
#[tokio::test]
async fn deadline_future_elapses() {
time::pause();
// Wrap it wi... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/tests/time_timeout.rs | 81 | 109 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:1 | #![warn(rust_2018_idioms)]
use tokio::sync::oneshot;
use tokio::time::{self, Instant, Timeout};
use tokio_test::*;
use futures::future::pending;
use std::time::Duration;
#[tokio::test]
async fn simultaneous_deadline_future_completion() {
// Create a future that is immediately ready
let mut fut = task::spawn(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/tests/time_timeout.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:2 | time::advance(ms(90)).await;
assert_pending!(fut.poll());
// Complete the future
tx.send(()).unwrap();
assert!(fut.is_woken());
assert_ready_ok!(fut.poll()).unwrap();
}
#[tokio::test]
async fn future_and_timeout_in_future() {
time::pause();
// Not yet complete
let (tx, rx) = oneshot... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/tests/time_timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:3 | // Wrap it with a deadline
let mut fut = task::spawn(Timeout::new_at(pending::<()>(), Instant::now()));
// Factor in jitter
// TODO: don't require this
time::advance(ms(1)).await;
assert_ready_err!(fut.poll());
}
#[tokio::test]
async fn deadline_future_elapses() {
time::pause();
// Wrap ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/tests/time_timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/time_timeout.rs:4 | // Turn the timer, it runs for the elapsed time
time::advance(ms(90)).await;
assert_pending!(stream.poll_next());
// Complete the future
tx.try_send(()).unwrap();
let item = assert_ready!(stream.poll_next());
assert!(item.is_some());
}
#[tokio::test]
async fn idle_stream_timesout_periodicall... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_timeout.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/tests/time_timeout.rs | 121 | 166 |
tokio-rs/tokio:tokio/tests/time_wasm.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test;
#[wasm_bindgen_test]
#[should_panic]
fn instant_now_panics() {
let _ = tokio::time::Instant::now();
}
#[cfg(all(feature = "rt", not(feature = "time")))]
#[wasm_bindgen_test]
fn runti... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/time_wasm.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/time_wasm.rs | 1 | 40 |
tokio-rs/tokio:tokio/tests/timer.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "default")]
use tokio::prelude::*;
use tokio::timer::*;
use std::sync::mpsc;
use std::time::{Duration, Instant};
#[test]
fn timer_with_threaded_runtime() {
use tokio::runtime::Runtime;
let rt = Runtime::new().unwrap();
let (tx, rx) = mpsc::channel();
rt.s... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/timer.rs | MIT | ed5a94eb2db95b7cc142045fbbd5d68c6276e04e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ed5a94eb2db95b7cc142045fbbd5d68c6276e04e/tokio/tests/timer.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/timer.rs:2 | tx.send(()).unwrap();
});
rt.run().unwrap();
rx.recv().unwrap();
}
#[tokio::test]
async fn starving() {
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
struct Starve<T: Future<Output = ()> + Unpin>(T, u64);
impl<T: Future<Output = ()> + Unpin> Future for S... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/timer.rs | MIT | ed5a94eb2db95b7cc142045fbbd5d68c6276e04e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ed5a94eb2db95b7cc142045fbbd5d68c6276e04e/tokio/tests/timer.rs | 41 | 92 |
tokio-rs/tokio:tokio/tests/timer.rs:3 | async fn timeout() {
use tokio::sync::oneshot;
let (_tx, rx) = oneshot::channel::<()>();
let now = Instant::now();
let dur = Duration::from_millis(20);
let res = rx.timeout(dur).await;
assert!(res.is_err());
assert!(Instant::now() >= now + dur);
} | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/timer.rs | MIT | ed5a94eb2db95b7cc142045fbbd5d68c6276e04e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ed5a94eb2db95b7cc142045fbbd5d68c6276e04e/tokio/tests/timer.rs | 81 | 92 |
tokio-rs/tokio:tokio/tests/timer.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "default")]
use tokio::prelude::*;
use tokio::timer::*;
use std::sync::mpsc;
use std::time::{Duration, Instant};
#[test]
fn timer_with_threaded_runtime() {
use tokio::runtime::Runtime;
let rt = Runtime::new().unwrap();
let (tx, rx) = mpsc::channel();
rt.s... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/timer.rs | MIT | a791f4a758604768463d3ca2162b913dcea34c40 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a791f4a758604768463d3ca2162b913dcea34c40/tokio/tests/timer.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/timer.rs:2 | tokio::timer::delay(when).await;
assert!(Instant::now() >= when);
tx.send(()).unwrap();
});
rt.run().unwrap();
rx.recv().unwrap();
}
#[tokio::test]
async fn starving() {
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
struct Starve<T: Future<Ou... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/timer.rs | MIT | a791f4a758604768463d3ca2162b913dcea34c40 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a791f4a758604768463d3ca2162b913dcea34c40/tokio/tests/timer.rs | 41 | 94 |
tokio-rs/tokio:tokio/tests/timer.rs:3 | #[tokio::test]
async fn timeout() {
use tokio::sync::oneshot;
let (_tx, rx) = oneshot::channel::<()>();
let now = Instant::now();
let dur = Duration::from_millis(20);
let res = rx.timeout(dur).await;
assert!(res.is_err());
assert!(Instant::now() >= now + dur);
} | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/timer.rs | MIT | a791f4a758604768463d3ca2162b913dcea34c40 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a791f4a758604768463d3ca2162b913dcea34c40/tokio/tests/timer.rs | 81 | 94 |
tokio-rs/tokio:tokio/tests/timer.rs:1 | #![warn(rust_2018_idioms)]
#![feature(async_await)]
#![cfg(feature = "default")]
use tokio::prelude::*;
use tokio::timer::*;
use std::sync::mpsc;
use std::time::{Duration, Instant};
#[test]
fn timer_with_threaded_runtime() {
use tokio::runtime::Runtime;
let rt = Runtime::new().unwrap();
let (tx, rx) = m... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/timer.rs | MIT | 2d56312b89ba407272b161290d563551efc896a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2d56312b89ba407272b161290d563551efc896a6/tokio/tests/timer.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/timer.rs:3 | }
#[tokio::test]
async fn timeout() {
use tokio::sync::oneshot;
let (_tx, rx) = oneshot::channel::<()>();
let now = Instant::now();
let dur = Duration::from_millis(20);
let res = rx.timeout(dur).await;
assert!(res.is_err());
assert!(Instant::now() >= now + dur);
} | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/timer.rs | MIT | 2d56312b89ba407272b161290d563551efc896a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2d56312b89ba407272b161290d563551efc896a6/tokio/tests/timer.rs | 81 | 95 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.