mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
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 <maximbel2003@gmail.com>
This commit is contained in:
1 parent
d2feb9b7c2
commit
ec251cbd3b
1 file changed
+6
-9
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user