1 | #![warn(rust_2018_idioms)] |
---|---|
2 | |
3 | use tokio::time::{sleep_until, Duration, Instant}; |
4 | use tokio_test::block_on; |
5 | |
6 | #[test] |
7 | fn async_block() { |
8 | assert_eq!(4, block_on(async { 4 })); |
9 | } |
10 | |
11 | async fn five() -> u8 { |
12 | 5 |
13 | } |
14 | |
15 | #[test] |
16 | fn async_fn() { |
17 | assert_eq!(5, block_on(five())); |
18 | } |
19 | |
20 | #[test] |
21 | fn test_sleep() { |
22 | let deadline = Instant::now() + Duration::from_millis(100); |
23 | |
24 | block_on(async { |
25 | sleep_until(deadline).await; |
26 | }); |
27 | } |
28 |