summaryrefslogtreecommitdiffstats
path: root/tokio-test/tests
diff options
context:
space:
mode:
authorGeoff Shannon <geoffpshannon@gmail.com>2019-08-13 21:10:26 -0700
committerCarl Lerche <me@carllerche.com>2019-08-13 21:10:26 -0700
commitfe90d61446b592d4e95bc226edd81c5994ceaa24 (patch)
tree5fa6d758408f8225d957fccf01e6abda957c13f9 /tokio-test/tests
parent338b37884a73782fe72d4e9a0616010bcd12180e (diff)
test: add a block_on function to tokio-test (#1431)
Diffstat (limited to 'tokio-test/tests')
-rw-r--r--tokio-test/tests/block_on.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/tokio-test/tests/block_on.rs b/tokio-test/tests/block_on.rs
new file mode 100644
index 00000000..7d56ec62
--- /dev/null
+++ b/tokio-test/tests/block_on.rs
@@ -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));
+}