From 8d6e9bad49c651d3bdb5bd71d6fc45a3d64c678a Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 8 Oct 2026 21:20:46 +0800 Subject: [PATCH] gateway tests: the burst tests allow the moment a first word takes to reach magpie (TestCodexBackendBurstTellsNoSpeed red on macOS CI at 58f45d05: Millis 612, TTFT 13) de5455b8's tests asserted that the time from the first word to the end was at least the upstream's 600 ms wait. The fake upstream starts that wait once it has sent the first word, and magpie stamps TTFT when the word arrives, so the span is the gap less the delivery time: 599 ms on a busy macOS runner. TestBurstTellsNoSpeed had the same `span < gap` check; both now want 90% of the gap. The speed assertions they guard (a burst tells no speed, a steady stream keeps it) are unchanged. Run in docker golang:1.26.8 as uid 1000: go vet -tags nogui ./internal/gateway; go test -race -count=15 -cpu 1,4 -run 'TestCodexBackendBurstTellsNoSpeed|TestBurstTellsNoSpeed' pass. Not reproduced locally with an injected delay; the CI log above is the red. --- internal/gateway/ttft_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/gateway/ttft_test.go b/internal/gateway/ttft_test.go index 6925b81f..3f1dac90 100644 --- a/internal/gateway/ttft_test.go +++ b/internal/gateway/ttft_test.go @@ -354,7 +354,10 @@ func TestBurstTellsNoSpeed(t *testing.T) { } u := lastUsage(t) span := u.Millis - u.TTFT - if u.TTFT <= 0 || span < gap.Milliseconds() { + // the upstream's wait starts when it sent the first word, + // which magpie reads a moment later: the span is the gap + // less that moment (599 ms of 600 on a busy macOS runner) + if u.TTFT <= 0 || span < gap.Milliseconds()*9/10 { t.Fatalf("usage ttft %d, ms %d; want the end %v after the first word", u.TTFT, u.Millis, gap) } r := lastRoute(s) @@ -386,7 +389,9 @@ func TestCodexBackendBurstTellsNoSpeed(t *testing.T) { t.Fatalf("%d %s", code, body) } u := lastUsage(t) - if u.Millis-u.TTFT < 600 || u.Output != 1000 { + // the end after the wait, less the moment the first word took to + // reach magpie (599 ms of 600 on macOS CI at 58f45d05) + if u.Millis-u.TTFT < 540 || u.Output != 1000 { t.Fatalf("usage %+v", u) } if n, w := u.Decode(); n != 0 || w != 0 {