2019-08-13 21:10:26 -07:00
|
|
|
#![warn(rust_2018_idioms)]
|
|
|
|
|
|
2020-10-01 02:24:33 -05:00
|
|
|
use tokio::time::{sleep_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]
|
2020-10-08 22:35:12 -05:00
|
|
|
fn test_sleep() {
|
2019-08-13 21:10:26 -07:00
|
|
|
let deadline = Instant::now() + Duration::from_millis(100);
|
2019-12-14 09:01:47 +03:00
|
|
|
|
|
|
|
|
block_on(async {
|
2020-10-01 02:24:33 -05:00
|
|
|
sleep_until(deadline).await;
|
2019-12-14 09:01:47 +03:00
|
|
|
});
|
2019-08-13 21:10:26 -07:00
|
|
|
}
|