From 28aac9da3578891bdce341b87a8638a52363deb7 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 18 Aug 2026 12:46:06 -0700 Subject: [PATCH] fix flaky HTTPS integration test Signed-off-by: James Sturtevant --- .../tests/http_integration.rs | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/hyperlight_sandbox/tests/http_integration.rs b/src/hyperlight_sandbox/tests/http_integration.rs index a71715d..c23f62f 100644 --- a/src/hyperlight_sandbox/tests/http_integration.rs +++ b/src/hyperlight_sandbox/tests/http_integration.rs @@ -122,20 +122,36 @@ fn chunked_body_streams_correctly() { #[test] fn send_https_get_request() { async { - let req = HttpRequest { - url: url::Url::parse("https://httpbin.org/get").unwrap(), - method: "GET".to_string(), - headers: vec![], - body: HttpRequest::body_from_bytes(None), - }; - - let resp = http::send_http_request(req) - .await - .expect("HTTPS GET to httpbin.org failed — TLS or DNS issue"); - assert_eq!(resp.status, 200); - - let echo: serde_json::Value = serde_json::from_slice(&resp.body).unwrap(); - assert!(echo["url"].as_str().unwrap().contains("httpbin.org")); + const MAX_ATTEMPTS: usize = 3; + let mut backoff = std::time::Duration::from_millis(250); + + for attempt in 1..=MAX_ATTEMPTS { + let req = HttpRequest { + url: url::Url::parse("https://github.com/hyperlight-dev/hyperlight-sandbox") + .unwrap(), + method: "GET".to_string(), + headers: vec![], + body: HttpRequest::body_from_bytes(None), + }; + + match http::send_http_request(req).await { + Ok(resp) if resp.status < 500 => { + assert_eq!(resp.status, 200); + assert!(String::from_utf8_lossy(&resp.body).contains("hyperlight-sandbox")); + return; + } + Ok(resp) if attempt == MAX_ATTEMPTS => { + panic!("HTTPS GET to github.com returned status {}", resp.status); + } + Err(error) if attempt == MAX_ATTEMPTS => { + panic!("HTTPS GET to github.com failed after {MAX_ATTEMPTS} attempts: {error}"); + } + Ok(_) | Err(_) => {} + } + + tokio::time::sleep(backoff).await; + backoff = backoff.saturating_mul(2); + } } .block_on(); }