Skip to content

Commit 28aac9d

Browse files
committed
fix flaky HTTPS integration test
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent 2b22e93 commit 28aac9d

1 file changed

Lines changed: 30 additions & 14 deletions

File tree

‎src/hyperlight_sandbox/tests/http_integration.rs‎

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,36 @@ fn chunked_body_streams_correctly() {
122122
#[test]
123123
fn send_https_get_request() {
124124
async {
125-
let req = HttpRequest {
126-
url: url::Url::parse("https://httpbin.org/get").unwrap(),
127-
method: "GET".to_string(),
128-
headers: vec![],
129-
body: HttpRequest::body_from_bytes(None),
130-
};
131-
132-
let resp = http::send_http_request(req)
133-
.await
134-
.expect("HTTPS GET to httpbin.org failed — TLS or DNS issue");
135-
assert_eq!(resp.status, 200);
136-
137-
let echo: serde_json::Value = serde_json::from_slice(&resp.body).unwrap();
138-
assert!(echo["url"].as_str().unwrap().contains("httpbin.org"));
125+
const MAX_ATTEMPTS: usize = 3;
126+
let mut backoff = std::time::Duration::from_millis(250);
127+
128+
for attempt in 1..=MAX_ATTEMPTS {
129+
let req = HttpRequest {
130+
url: url::Url::parse("https://github.com/hyperlight-dev/hyperlight-sandbox")
131+
.unwrap(),
132+
method: "GET".to_string(),
133+
headers: vec![],
134+
body: HttpRequest::body_from_bytes(None),
135+
};
136+
137+
match http::send_http_request(req).await {
138+
Ok(resp) if resp.status < 500 => {
139+
assert_eq!(resp.status, 200);
140+
assert!(String::from_utf8_lossy(&resp.body).contains("hyperlight-sandbox"));
141+
return;
142+
}
143+
Ok(resp) if attempt == MAX_ATTEMPTS => {
144+
panic!("HTTPS GET to github.com returned status {}", resp.status);
145+
}
146+
Err(error) if attempt == MAX_ATTEMPTS => {
147+
panic!("HTTPS GET to github.com failed after {MAX_ATTEMPTS} attempts: {error}");
148+
}
149+
Ok(_) | Err(_) => {}
150+
}
151+
152+
tokio::time::sleep(backoff).await;
153+
backoff = backoff.saturating_mul(2);
154+
}
139155
}
140156
.block_on();
141157
}

0 commit comments

Comments
 (0)