From 48416ce0894ef7bef0ef9c064609b4aa76a0d9b6 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 6 Nov 2026 09:29:21 +0000 Subject: [PATCH] tools/capver: test 429 and dropped-connection retries --- tools/capver/main_test.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/capver/main_test.go b/tools/capver/main_test.go index 49b7e963d..5dfc18323 100644 --- a/tools/capver/main_test.go +++ b/tools/capver/main_test.go @@ -16,7 +16,7 @@ func TestFetch(t *testing.T) { tests := []struct { name string - statuses []int // served in order; the last one repeats + statuses []int // served in order; the last one repeats; 0 drops the connection wantBody string wantErr error wantCalls int32 @@ -33,6 +33,18 @@ func TestFetch(t *testing.T) { wantBody: "body", wantCalls: 2, }, + { + name: "rate-limited-then-ok", + statuses: []int{http.StatusTooManyRequests, http.StatusOK}, + wantBody: "body", + wantCalls: 2, + }, + { + name: "dropped-connection-then-ok", + statuses: []int{0, http.StatusOK}, + wantBody: "body", + wantCalls: 2, + }, { name: "always-unavailable-fails", statuses: []int{http.StatusServiceUnavailable}, @@ -53,7 +65,13 @@ func TestFetch(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { n := int(calls.Add(1)) - 1 - w.WriteHeader(tt.statuses[min(n, len(tt.statuses)-1)]) + + status := tt.statuses[min(n, len(tt.statuses)-1)] + if status == 0 { + panic(http.ErrAbortHandler) + } + + w.WriteHeader(status) _, _ = w.Write([]byte("body")) })) defer srv.Close()