|
11 | 11 |
|
12 | 12 | #![allow(dead_code)] |
13 | 13 |
|
| 14 | +use std::time::Duration; |
| 15 | + |
14 | 16 | use hotdata::Client; |
15 | 17 |
|
| 18 | +/// Connect-phase ceiling for the shared test client. |
| 19 | +/// |
| 20 | +/// `reqwest::Client::default()` (what the SDK uses when no client is supplied) |
| 21 | +/// has no connect timeout, so an unreachable API host blocks each call on the |
| 22 | +/// OS-level TCP timeout (~60s observed in CI). With ~20 scenario binaries run |
| 23 | +/// sequentially by `cargo test`, a transient connectivity blip turns into a |
| 24 | +/// ~20-minute red run. Bounding the connect phase fails fast — and lets hyper |
| 25 | +/// fall through to the next resolved address — so an outage is cheap to retry. |
| 26 | +const CONNECT_TIMEOUT: Duration = Duration::from_secs(10); |
| 27 | + |
| 28 | +/// Overall per-request ceiling. Generous enough for the tiny fixture upload and |
| 29 | +/// each poll request; purely a backstop against a hung socket. |
| 30 | +const REQUEST_TIMEOUT: Duration = Duration::from_secs(60); |
| 31 | + |
| 32 | +/// Build the reqwest client every scenario shares: identical to the SDK default |
| 33 | +/// except for the bounded [`CONNECT_TIMEOUT`]/[`REQUEST_TIMEOUT`]. Pass it via |
| 34 | +/// `ClientBuilder::reqwest_client` (or assign to `Configuration::client`) so a |
| 35 | +/// down API host can't stall the suite. |
| 36 | +pub fn test_http_client() -> reqwest::Client { |
| 37 | + reqwest::Client::builder() |
| 38 | + .connect_timeout(CONNECT_TIMEOUT) |
| 39 | + .timeout(REQUEST_TIMEOUT) |
| 40 | + .build() |
| 41 | + .expect("building the test reqwest client should not fail") |
| 42 | +} |
| 43 | + |
16 | 44 | /// Default API host. The auth-token -> JWT exchange and every endpoint live on |
17 | 45 | /// the API host, so the ergonomic `Client` always points here unless overridden |
18 | 46 | /// by `HOTDATA_SDK_TEST_API_URL`. |
@@ -67,6 +95,7 @@ pub fn client_or_skip() -> Option<Client> { |
67 | 95 | .api_token(env.api_key.expect("checked above")) |
68 | 96 | .workspace_id(env.workspace_id.expect("checked above")) |
69 | 97 | .base_url(env.api_url) |
| 98 | + .reqwest_client(test_http_client()) |
70 | 99 | .build() |
71 | 100 | .expect("Client::build with valid credentials should not fail"); |
72 | 101 | Some(client) |
|
0 commit comments