Skip to content

Commit d359e14

Browse files
committed
add test showing that timeout on http::Client::send panics
1 parent 6cf89c8 commit d359e14

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/http_timeout.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

0 commit comments

Comments
 (0)