diff options
Diffstat (limited to 'tests/block_on.rs')
-rw-r--r-- | tests/block_on.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/block_on.rs b/tests/block_on.rs new file mode 100644 index 0000000..efaaf51 --- /dev/null +++ b/tests/block_on.rs @@ -0,0 +1,27 @@ +#![warn(rust_2018_idioms)] + +use tokio::time::{sleep_until, Duration, Instant}; +use tokio_test::block_on; + +#[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] +fn test_sleep() { + let deadline = Instant::now() + Duration::from_millis(100); + + block_on(async { + sleep_until(deadline).await; + }); +} |