From 76d6296edf668e8a10e2abe02ee01ae502a4de65 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 11 Nov 2026 08:58:10 +0800 Subject: [PATCH] gateway: the key-slot keepalive test skips SSE comments before the first chunk TestKeyConcurrencyKeepsStreamAlive went red on macOS CI (Race run 42920368236 at 8fa91a852) with `first = ": keepalive\n"`. The test sets keepHeldAfter to 10ms, so a first chunk slower than that under -race comes after a keepalive comment, and the test read that comment as the vendor's reply. The first read now skips comment and blank lines and checks the first data line. Broken by hand: a 60ms sleep before slowVendor's first chunk for "first" turned the old test red 3 of 3 with CI's exact message; the new test passed under it. The sleep is reverted. Run on mote: gofmt -l (clean), go vet ./internal/gateway, and go test -race ./internal/gateway -run "TestKeyConcurrency|TestKeySlot" -count=10: ok. Not run: the full suite (test-only change in one test). --- internal/gateway/key_slots_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/gateway/key_slots_test.go b/internal/gateway/key_slots_test.go index af07588d6..aa7b69578 100644 --- a/internal/gateway/key_slots_test.go +++ b/internal/gateway/key_slots_test.go @@ -222,8 +222,16 @@ func TestKeyConcurrencyKeepsStreamAlive(t *testing.T) { return res } first := post("first") - if line, _ := bufio.NewReader(first.Body).ReadString('\n'); !strings.Contains(line, "from first") { - t.Fatalf("first = %q", line) + // keepHeldAfter is 10ms here, so a slow first chunk (under -race on CI) + // can come after a ": keepalive" comment: the first data line is the one + // about the vendor's reply. + r := bufio.NewReader(first.Body) + line, err := r.ReadString('\n') + for err == nil && (strings.HasPrefix(line, ":") || strings.TrimSpace(line) == "") { + line, err = r.ReadString('\n') + } + if !strings.Contains(line, "from first") { + t.Fatalf("first = %q (%v)", line, err) } // the second has its headers while it waits, nothing sent upstream second := post("second")