Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2368336

Browse files
authored
Merge pull request #95 from kpp/add_tests_io_timeout
add tests for io::timeout
2 parents dfd520c + b95dd13 commit 2368336

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

‎tests/io_timeout.rs‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
fn io_timeout_timedout() {
9+
task::block_on(async {
10+
io::timeout(Duration::from_secs(1), async {
11+
let stdin = io::stdin();
12+
let mut line = String::new();
13+
let _n = stdin.read_line(&mut line).await?;
14+
Ok(())
15+
})
16+
.await
17+
.unwrap(); // We should panic with a timeout error
18+
});
19+
}
20+
21+
#[test]
22+
#[should_panic(expected = "My custom error")]
23+
fn io_timeout_future_err() {
24+
task::block_on(async {
25+
io::timeout(Duration::from_secs(1), async {
26+
Err::<(), io::Error>(io::Error::new(io::ErrorKind::Other, "My custom error"))
27+
})
28+
.await
29+
.unwrap(); // We should panic with our own error
30+
});
31+
}
32+
33+
#[test]
34+
fn io_timeout_future_ok() {
35+
task::block_on(async {
36+
io::timeout(Duration::from_secs(1), async { Ok(()) })
37+
.await
38+
.unwrap(); // We shouldn't panic at all
39+
});
40+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /