From e80fc7dc5d722e2e81378d82d8510dc027b954c1 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 16 Oct 2026 21:31:35 +0800 Subject: [PATCH] tests: TestFailOpen cuts only the spin short, not the throw and the string It set the request limit to 50ms for all three hooks. In a full go test ./... run (on bff7cbd24) the string case ran past 50ms under load, and was counted "took too long" instead of "returned neither": state {... Calls:3 AvgMicro:44471 Failures:3 Last:onRequest: took too long ...} Now the throw and the string run under the normal 250ms limit, and only the spin gets 50ms. Reproduced by injection: an 80ms busy loop in the string hook gives that exact state line on the old test and passes on the new one. -race -count=20 passes. --- internal/middleware/middleware_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/middleware/middleware_test.go b/internal/middleware/middleware_test.go index 3467cde68..f42d372e7 100644 --- a/internal/middleware/middleware_test.go +++ b/internal/middleware/middleware_test.go @@ -128,7 +128,6 @@ func TestReject(t *testing.T) { func TestFailOpen(t *testing.T) { was := requestLimit - requestLimit = 50 * time.Millisecond defer func() { requestLimit = was }() e := file(t, ` let n = 0; @@ -143,6 +142,12 @@ export function onRequest(body) { use(t, e) for _, kind := range []string{"throw", "spin", "string"} { in := `{"kind":"` + kind + `"}` + // Only the spin is cut short: under a full run's load a throw or a + // string can take longer than 50ms, and would fail for the limit. + requestLimit = was + if kind == "spin" { + requestLimit = 50 * time.Millisecond + } r := Begin(info()) start := time.Now() body, rej := r.Request([]byte(in))