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.
This commit is contained in:
yetone
2026-10-16 22:58:41 +08:00
parent 7d7dba31ae
commit e80fc7dc5d
+6 -1
View File
@@ -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))