From ec251cbd3b1db23a26b1961c968eace8d2807db0 Mon Sep 17 00:00:00 2001 From: ZverGuy Date: Thu, 5 Nov 2026 02:21:21 +0700 Subject: [PATCH] test(observability-proxy): watch the metrics slot instead of probing The metrics slow-body and stalled-client tests probed the slot with requests of their own, which competed for the one slot under test and made them fail at random, under one shuffle seed reliably. They now read the limiter's slot count, as the logs tests do; 300 runs of the test and 20 shuffled runs of the package pass. Assisted-by: LLM Signed-off-by: ZverGuy --- .../observabilityproxy/server_deadline_test.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/internal/observabilityproxy/server_deadline_test.go b/internal/observabilityproxy/server_deadline_test.go index 03d03f218..abe1b3703 100644 --- a/internal/observabilityproxy/server_deadline_test.go +++ b/internal/observabilityproxy/server_deadline_test.go @@ -457,12 +457,12 @@ func TestServerMetricsRequestLifetime(t *testing.T) { pipe := servePipe(t, h.server) conn := pipe.send(t, "POST "+metricsRoot+"api/v1/query HTTP/1.1\r\nHost: proxy\r\nAuthorization: Bearer good\r\n"+ "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: 100\r\n\r\nquery=") - eventually(t, time.Second, func() bool { - return h.status(http.MethodGet, query, "good") == http.StatusTooManyRequests - }, "a metrics request with an unfinished body does not hold a concurrency slot") + eventually(t, time.Second, func() bool { return slotsHeld(h) == 1 }, + "a metrics request with an unfinished body does not hold a concurrency slot") if resp := readResponse(t, conn); resp.StatusCode != http.StatusRequestTimeout { t.Fatalf("unfinished body answered %d, want 408", resp.StatusCode) } + eventually(t, time.Second, func() bool { return slotsHeld(h) == 0 }, "the slot of an unfinished body was not released") }) t.Run("stalled client", func(t *testing.T) { // Larger than the server's write buffer, so the handler itself @@ -474,12 +474,9 @@ func TestServerMetricsRequestLifetime(t *testing.T) { }, func(w http.ResponseWriter, _ *http.Request) { _, _ = io.WriteString(w, big) }) pipe := servePipe(t, h.server) pipe.send(t, "GET "+query+" HTTP/1.1\r\nHost: proxy\r\nAuthorization: Bearer good\r\n\r\n") - eventually(t, time.Second, func() bool { - return h.status(http.MethodGet, query, "good") == http.StatusTooManyRequests - }, "the stalled metrics request never held its slot") - eventually(t, 2*time.Second, func() bool { - return h.status(http.MethodGet, query, "good") == http.StatusOK - }, "a metrics client that stopped reading keeps its concurrency slot") + eventually(t, time.Second, func() bool { return slotsHeld(h) == 1 }, "the stalled metrics request never held its slot") + eventually(t, 2*time.Second, func() bool { return slotsHeld(h) == 0 }, + "a metrics client that stopped reading keeps its concurrency slot") }) t.Run("truncated answer", func(t *testing.T) { h := newHarness(t, Config{}, func(w http.ResponseWriter, _ *http.Request) {