1 use tokio::net::TcpStream;
2 use tokio::sync::oneshot;
3 use tokio::time::{timeout, Duration};
4 
5 use futures::executor::block_on;
6 
7 use std::net::TcpListener;
8 
9 #[test]
10 #[should_panic(
11     expected = "there is no reactor running, must be called from the context of a Tokio 1.x runtime"
12 )]
timeout_panics_when_no_tokio_context()13 fn timeout_panics_when_no_tokio_context() {
14     block_on(timeout_value());
15 }
16 
17 #[test]
18 #[should_panic(
19     expected = "there is no reactor running, must be called from the context of a Tokio 1.x runtime"
20 )]
panics_when_no_reactor()21 fn panics_when_no_reactor() {
22     let srv = TcpListener::bind("127.0.0.1:0").unwrap();
23     let addr = srv.local_addr().unwrap();
24     block_on(TcpStream::connect(&addr)).unwrap();
25 }
26 
timeout_value()27 async fn timeout_value() {
28     let (_tx, rx) = oneshot::channel::<()>();
29     let dur = Duration::from_millis(10);
30     let _ = timeout(dur, rx).await;
31 }
32 
33 #[test]
34 #[should_panic(
35     expected = "there is no reactor running, must be called from the context of a Tokio 1.x runtime"
36 )]
io_panics_when_no_tokio_context()37 fn io_panics_when_no_tokio_context() {
38     let _ = tokio::net::TcpListener::from_std(std::net::TcpListener::bind("127.0.0.1:0").unwrap());
39 }
40