summaryrefslogtreecommitdiffstats
path: root/tokio/tests/rt_basic.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/tests/rt_basic.rs')
-rw-r--r--tokio/tests/rt_basic.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/tokio/tests/rt_basic.rs b/tokio/tests/rt_basic.rs
new file mode 100644
index 00000000..039bb22f
--- /dev/null
+++ b/tokio/tests/rt_basic.rs
@@ -0,0 +1,34 @@
+#![warn(rust_2018_idioms)]
+
+use tokio::runtime::Runtime;
+use tokio::sync::oneshot;
+use tokio_test::{assert_err, assert_ok};
+
+use std::thread;
+use std::time::Duration;
+
+#[test]
+fn spawned_task_does_not_progress_without_block_on() {
+ let (tx, mut rx) = oneshot::channel();
+
+ let mut rt = rt();
+
+ rt.spawn(async move {
+ assert_ok!(tx.send("hello"));
+ });
+
+ thread::sleep(Duration::from_millis(50));
+
+ assert_err!(rx.try_recv());
+
+ let out = rt.block_on(async { assert_ok!(rx.await) });
+
+ assert_eq!(out, "hello");
+}
+
+fn rt() -> Runtime {
+ tokio::runtime::Builder::new()
+ .basic_scheduler()
+ .build()
+ .unwrap()
+}