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).
This commit is contained in:
yetone
2026-11-11 08:58:10 +08:00
parent 28a79bc33a
commit 76d6296edf
+10 -2
View File
@@ -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")