1 use std::time::Duration;
2 
3 use async_std::io;
4 use async_std::task;
5 
6 #[test]
7 #[should_panic(expected = "timed out")]
8 #[cfg(not(any(
9     target_os = "unknown",
10     target_arch = "arm",
11     target_arch = "mips",
12     target_arch = "powerpc",
13     target_arch = "powerpc64",
14     target_arch = "x86",
15 )))] // stdin tests fail when running through cross
io_timeout_timedout()16 fn io_timeout_timedout() {
17     task::block_on(async {
18         io::timeout(Duration::from_secs(1), async {
19             let stdin = io::stdin();
20             let mut line = String::new();
21             let _n = stdin.read_line(&mut line).await?;
22             Ok(())
23         })
24         .await
25         .unwrap(); // We should panic with a timeout error
26     });
27 }
28 
29 #[test]
30 #[should_panic(expected = "My custom error")]
io_timeout_future_err()31 fn io_timeout_future_err() {
32     task::block_on(async {
33         io::timeout(Duration::from_secs(1), async {
34             Err::<(), io::Error>(io::Error::new(io::ErrorKind::Other, "My custom error"))
35         })
36         .await
37         .unwrap(); // We should panic with our own error
38     });
39 }
40 
41 #[test]
io_timeout_future_ok()42 fn io_timeout_future_ok() {
43     task::block_on(async {
44         io::timeout(Duration::from_secs(1), async { Ok(()) })
45             .await
46             .unwrap(); // We shouldn't panic at all
47     });
48 }
49