mod common;
use std::io::Write;
use std::time::{Duration, Instant};
use common::RawServer;
use rightkit_http::testing::loopback_config;
use rightkit_http::*;
#[test]
fn f5_blocking_retry_sleep_does_not_outlive_the_request_deadline() {
let server = RawServer::start(|s, _, _| {
let _ = s.write_all(
b"HTTP/1.1 503 Service Unavailable\r\nContent-Length: 1\r\nConnection: close\r\n\r\n",
);
let _ = s.flush();
std::thread::sleep(Duration::from_secs(8));
});
let c = Client::new(ClientConfig {
retry: RetryPolicy {
max_attempts: 3,
initial_backoff: Duration::from_millis(1000),
max_backoff: Duration::from_millis(1000),
multiplier: 1.0,
jitter: 0.0,
..RetryPolicy::default()
},
request_timeout: Duration::from_secs(10),
response_timeout: Some(Duration::from_secs(10)),
..loopback_config()
});
let started = Instant::now();
let result = c.send_any(&Request::get(server.url("/")).deadline(Duration::from_millis(1500)));
let took = started.elapsed();
match &result {
Err(HttpError::Timeout { .. }) => {}
Ok(resp) if resp.status == 503 => {}
other => panic!("unexpected outcome: {other:?}"),
}
assert!(
took < Duration::from_millis(2000),
"slept past the deadline: {took:?}"
);
}