diff --git a/tests/http_timeout.rs b/tests/http_timeout.rs new file mode 100644 index 0000000..de67f1b --- /dev/null +++ b/tests/http_timeout.rs @@ -0,0 +1,23 @@ +use wstd::future::FutureExt; +use wstd::http::{Client, Method, Request}; +use wstd::time::Duration; + +#[wstd::test] +async fn http_timeout() -> Result<(), Box> { + // This get request will connect to the server, which will then wait 1 second before + // returning a response. + let request = Request::new(Method::GET, "https://postman-echo.com/delay/1".parse()?); + let result = Client::new() + .send(request) + .timeout(Duration::from_millis(500)) + .await; + + assert!(result.is_err(), "response should be an error"); + let error = result.unwrap_err(); + assert!( + matches!(error.kind(), std::io::ErrorKind::TimedOut), + "expected TimedOut error, got: {error:?>}" + ); + + Ok(()) +}