We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6cf89c8 commit d359e14Copy full SHA for d359e14
1 file changed
tests/http_timeout.rs
@@ -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