File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
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 . unwrap ( ) ; // We should panic with a timeout error
17
+ } ) ;
18
+ }
19
+
20
+ #[ test]
21
+ #[ should_panic( expected = "My custom error" ) ]
22
+ fn io_timeout_future_err ( ) {
23
+ task:: block_on ( async {
24
+ io:: timeout ( Duration :: from_secs ( 1 ) , async {
25
+ Err :: < ( ) , io:: Error > ( io:: Error :: new ( io:: ErrorKind :: Other , "My custom error" ) )
26
+ } )
27
+ . await . unwrap ( ) ; // We should panic with our own error
28
+ } ) ;
29
+ }
30
+
31
+ #[ test]
32
+ fn io_timeout_future_ok ( ) {
33
+ task:: block_on ( async {
34
+ io:: timeout ( Duration :: from_secs ( 1 ) , async {
35
+ Ok ( ( ) )
36
+ } )
37
+ . await . unwrap ( ) ; // We shouldn't panic at all
38
+ } ) ;
39
+ }
You can’t perform that action at this time.
0 commit comments