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 <noreply@anthropic.com>
This commit is contained in:
Tobias Gesellchen
2026-08-29 16:14:56 +02:00
co-authored by Claude Sonnet 5
parent a21b4d71ae
commit 35724bcffc
@@ -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) {