2019-08-13 21:10:26 -07:00
|
|
|
#![warn(rust_2018_idioms)]
|
|
|
|
|
|
2019-11-15 22:11:13 -08:00
|
|
|
use tokio::time::{delay_until, Duration, Instant};
|
2019-08-13 21:10:26 -07:00
|
|
|
use tokio_test::block_on;
|
2019-10-21 16:45:13 -07:00
|
|
|
|
2019-08-13 21:10:26 -07:00
|
|
|
#[test]
|
|
|
|
|
fn async_block() {
|
|
|
|
|
assert_eq!(4, block_on(async { 4 }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn five() -> u8 {
|
|
|
|
|
5
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn async_fn() {
|
|
|
|
|
assert_eq!(5, block_on(five()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2019-08-20 17:39:55 +02:00
|
|
|
fn test_delay() {
|
2019-08-13 21:10:26 -07:00
|
|
|
let deadline = Instant::now() + Duration::from_millis(100);
|
2019-11-20 12:24:41 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
(),
|
|
|
|
|
block_on(async {
|
|
|
|
|
delay_until(deadline).await;
|
|
|
|
|
})
|
|
|
|
|
);
|
2019-08-13 21:10:26 -07:00
|
|
|
}
|