Skip to content

Commit 5f8a5c5

Browse files
committed
add retry for test that is flaky on CI, probably due to resource contention
1 parent a48c05b commit 5f8a5c5

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

internal/api/proxy_test.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,25 @@ func TestWithProxyTransport_ProxyAuth(t *testing.T) {
247247
})
248248

249249
t.Run("https proxy with auth", func(t *testing.T) {
250-
proxyURL := startProxyWithAuth(t, true, "user", "s3cret")
251-
transport := withProxyTransport(newTestTransport(), proxyURL, "")
252-
t.Cleanup(transport.CloseIdleConnections)
253-
client := &http.Client{Transport: transport, Timeout: 10 * time.Second}
254-
255-
resp, err := client.Get(target.URL)
256-
if err != nil {
257-
t.Fatalf("GET through authenticated https proxy: %v", err)
250+
// Under the race detector on resource-constrained CI hosts
251+
// the TLS handshake to the proxy can sporadically fail with
252+
// "first record does not look like a TLS handshake" / EOF.
253+
// Retry with a fresh proxy + transport to tolerate this.
254+
var resp *http.Response
255+
var lastErr error
256+
for attempt := range 3 {
257+
proxyURL := startProxyWithAuth(t, true, "user", "s3cret")
258+
transport := withProxyTransport(newTestTransport(), proxyURL, "")
259+
client := &http.Client{Transport: transport, Timeout: 10 * time.Second}
260+
resp, lastErr = client.Get(target.URL)
261+
transport.CloseIdleConnections()
262+
if lastErr == nil {
263+
break
264+
}
265+
t.Logf("attempt %d: %v", attempt+1, lastErr)
266+
}
267+
if lastErr != nil {
268+
t.Fatalf("GET through authenticated https proxy (after retries): %v", lastErr)
258269
}
259270
defer resp.Body.Close()
260271
if _, err := io.ReadAll(resp.Body); err != nil {

0 commit comments

Comments
 (0)