From d8b8936f4672a2d5bdea204fb4155198bb2efbb0 Mon Sep 17 00:00:00 2001 From: sneak Date: Sun, 4 Oct 2026 04:13:50 +0000 Subject: [PATCH] Point the unreachable-app test at port 1 (closes #51) TestAnswers502WhenTheAppCannotBeReached closed a listener and pointed smallwebwaf at its port, which another test running in parallel could open in between, so the test sometimes got that server's answer instead of a 502. It now uses 127.0.0.1:1: nothing listens there, and a test listening on port 0 is always given a port from 32768 up, so no test can take it. No other test reuses a closed listener's port. Model: opus-5-5 --- internal/proxy/passthrough_test.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/internal/proxy/passthrough_test.go b/internal/proxy/passthrough_test.go index 66caee7..c788d1f 100644 --- a/internal/proxy/passthrough_test.go +++ b/internal/proxy/passthrough_test.go @@ -5,7 +5,6 @@ import ( "bytes" "errors" "io" - "net" "net/http" "slices" "strings" @@ -354,15 +353,8 @@ func TestRefusesHeadersOver32KiB(t *testing.T) { func TestAnswers502WhenTheAppCannotBeReached(t *testing.T) { t.Parallel() - listener, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", localhost+":0") - if err != nil { - t.Fatalf("listen: %v", err) - } - - closedAddr := listener.Addr().String() - _ = listener.Close() - - addr, out := startProxy(t, "http://"+closedAddr, nil) + // No test can listen on port 1: listening on port 0 gets one from 32768 up. + addr, out := startProxy(t, "http://"+localhost+":1", nil) wantStatus(t, get(t, addr, "/"), http.StatusBadGateway) wantLine(t, out.requestLine(t), http.StatusBadGateway, -- 2.54.0