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