2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-01-16 10:49:55 +00:00
async-std/tests/io_timeout.rs

49 lines
1.2 KiB
Rust
Raw Normal View History

2019-08-21 09:57:00 +00:00
use std::time::Duration;
use async_std::io;
use async_std::task;
#[test]
#[should_panic(expected = "timed out")]
2020-05-07 21:20:44 +00:00
#[cfg(not(any(
target_os = "unknown",
target_arch = "arm",
target_arch = "mips",
target_arch = "powerpc",
target_arch = "powerpc64",
target_arch = "x86",
)))] // stdin tests fail when running through cross
2019-08-21 09:57:00 +00:00
fn io_timeout_timedout() {
task::block_on(async {
io::timeout(Duration::from_secs(1), async {
let stdin = io::stdin();
let mut line = String::new();
let _n = stdin.read_line(&mut line).await?;
2019-08-21 09:57:00 +00:00
Ok(())
})
.await
.unwrap(); // We should panic with a timeout error
});
}
#[test]
#[should_panic(expected = "My custom error")]
fn io_timeout_future_err() {
task::block_on(async {
io::timeout(Duration::from_secs(1), async {
Err::<(), io::Error>(io::Error::new(io::ErrorKind::Other, "My custom error"))
})
.await
.unwrap(); // We should panic with our own error
});
}
#[test]
fn io_timeout_future_ok() {
task::block_on(async {
io::timeout(Duration::from_secs(1), async { Ok(()) })
.await
.unwrap(); // We shouldn't panic at all
});
}