| 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::get("https://postman-echo.com/delay/1").body(Body::empty())?; |
| 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 | } |