| 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 | )] |
| 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 | fn panics_when_no_reactor() { |
| 24 | let srv = TcpListener::bind("127.0.0.1:0" ).unwrap(); |
| 25 | let addr = srv.local_addr().unwrap(); |
| 26 | block_on(TcpStream::connect(&addr)).unwrap(); |
| 27 | } |
| 28 | |
| 29 | async fn timeout_value() { |
| 30 | let (_tx, rx) = oneshot::channel::<()>(); |
| 31 | let dur = Duration::from_millis(10); |
| 32 | let _ = timeout(dur, rx).await; |
| 33 | } |
| 34 | |
| 35 | #[test] |
| 36 | #[should_panic ( |
| 37 | expected = "there is no reactor running, must be called from the context of a Tokio 1.x runtime" |
| 38 | )] |
| 39 | fn io_panics_when_no_tokio_context() { |
| 40 | let _ = tokio::net::TcpListener::from_std(std::net::TcpListener::bind("127.0.0.1:0" ).unwrap()); |
| 41 | } |
| 42 | |