mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
test: add a block_on function to tokio-test (#1431)
This commit is contained in:
committed by
Carl Lerche
parent
338b37884a
commit
fe90d61446
@@ -0,0 +1,28 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![feature(async_await)]
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio_test::block_on;
|
||||
use tokio_timer::Delay;
|
||||
|
||||
#[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 delay() {
|
||||
let deadline = Instant::now() + Duration::from_millis(100);
|
||||
let delay = Delay::new(deadline);
|
||||
|
||||
assert_eq!((), block_on(delay));
|
||||
}
|
||||
Reference in New Issue
Block a user