From 44830790b87bdcdf2541502188dffc242f812c5b Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Sun, 23 Aug 2026 21:10:23 +0200 Subject: [PATCH] test(player): adopt httptest.NewTestServer (Go 1.27) in the new discovery test NewTestServer registers its own t.Cleanup(Close) instead of needing a manual defer, and fails the test on a handler panic instead of just logging it. It defaults to an in-memory transport reachable only via Server.Client(), which wouldn't work here since our production client.NewClient dials a real address rather than using that client -- calling Start() instead of Client() opts back into a real loopback listener, identical to the old NewServer, confirmed by reading the actual go1.27.0 source (server.go's Start implementation). This is a proactive adoption of a new stdlib idiom, not one of the review findings from the previous commit; it doesn't change the goroutine-drain fix from that commit, which is a separate concern Close()'s "wait for outstanding requests" guarantee doesn't fully cover (a goroutine that hasn't started its request yet at Close() time isn't "outstanding"). Verified: 10x -count re-run under -race, full suite + lint clean. Co-Authored-By: Claude Sonnet 5 --- pkg/service/soundtouchweb/discovery_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/service/soundtouchweb/discovery_test.go b/pkg/service/soundtouchweb/discovery_test.go index 362c19f7..e63976be 100644 --- a/pkg/service/soundtouchweb/discovery_test.go +++ b/pkg/service/soundtouchweb/discovery_test.go @@ -14,7 +14,13 @@ func TestDiscoverDevicesRetriesConfiguredHosts(t *testing.T) { var available atomic.Bool var infoRequests atomic.Int32 - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // NewTestServer (Go 1.27) registers its own t.Cleanup(Close) instead of + // needing a manual defer, and fails the test on a handler panic. It + // defaults to an in-memory transport reachable only via Server.Client(), + // but our production client.NewClient dials a real address, so Start() + // (rather than Client()) is used here to get a real loopback listener, + // same as the old NewServer -- see https://pkg.go.dev/net/http/httptest#NewTestServer. + server := httptest.NewTestServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/info" { http.NotFound(w, r) return @@ -29,7 +35,7 @@ func TestDiscoverDevicesRetriesConfiguredHosts(t *testing.T) { w.Header().Set("Content-Type", "application/xml") _, _ = w.Write([]byte(`Configured speakerSoundTouch 10`)) })) - defer server.Close() + server.Start() t.Setenv("UPNP_ENABLED", "false") t.Setenv("MDNS_ENABLED", "false")