From 35724bcffc949972f1d7d174ba02090db15b98c6 Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Sat, 29 Aug 2026 16:09:19 +0200 Subject: [PATCH] test(service): fix flaky serialization test by filtering non-/info requests The handler counted every request regardless of path, so the background status-update goroutine AddDeviceByHost spawns after a successful probe could land before the assertion and be mistaken for a second concurrent seed probe, occasionally failing with request count 2 instead of 1. Filter by path like the existing TestDiscoverDevicesRetriesConfiguredHosts test. Co-Authored-By: Claude Sonnet 5 --- pkg/service/soundtouchweb/discovery_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/service/soundtouchweb/discovery_test.go b/pkg/service/soundtouchweb/discovery_test.go index 909f2e7a..5364bf15 100644 --- a/pkg/service/soundtouchweb/discovery_test.go +++ b/pkg/service/soundtouchweb/discovery_test.go @@ -256,7 +256,15 @@ func TestSeedExtraDevicesSerializesConcurrentRuns(t *testing.T) { var infoRequests atomic.Int32 release := make(chan struct{}) + // Only /info blocks and counts. A successful registration spawns its own + // background status-update request (see the comment below), which must + // not be mistaken for a second concurrent seed probe. server := httptest.NewTestServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/info" { + http.NotFound(w, r) + return + } + infoRequests.Add(1) <-release // block until the test lets the handler respond @@ -285,6 +293,14 @@ func TestSeedExtraDevicesSerializesConcurrentRuns(t *testing.T) { if got := infoRequests.Load(); got != 1 { t.Fatalf("/info request count = %d, want 1 (concurrent seeds were not serialized)", got) } + + // AddDeviceByHost spawns a one-shot status-update goroutine and a 30s- + // ticker poll loop on successful registration (see + // TestDiscoverDevicesRetriesConfiguredHosts). Give them a moment to + // finish before the deferred server.Close() runs, so a still-in-flight + // request against the closing httptest server doesn't produce log noise + // or -race flakiness. + time.Sleep(50 * time.Millisecond) } func TestRemoveDeviceIfMatchKeepsReplacement(t *testing.T) {