File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ use wstd:: future:: FutureExt ;
2
+ use wstd:: http:: { Client , Method , Request } ;
3
+ use wstd:: time:: Duration ;
4
+
5
+ #[ wstd:: test]
6
+ async fn http_timeout ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
7
+ // This get request will connect to the server, which will then wait 1 second before
8
+ // returning a response.
9
+ let request = Request :: new ( Method :: GET , "https://postman-echo.com/delay/1" . parse ( ) ?) ;
10
+ let result = Client :: new ( )
11
+ . send ( request)
12
+ . timeout ( Duration :: from_millis ( 500 ) )
13
+ . await ;
14
+
15
+ assert ! ( result. is_err( ) , "response should be an error" ) ;
16
+ let error = result. unwrap_err ( ) ;
17
+ assert ! (
18
+ matches!( error. kind( ) , std:: io:: ErrorKind :: TimedOut ) ,
19
+ "expected TimedOut error, got: {error:?>}"
20
+ ) ;
21
+
22
+ Ok ( ( ) )
23
+ }
You can’t perform that action at this time.
0 commit comments