From 8b89b2e36c4ae5b98e6672e86ec0ab1cdd7af77f Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 15 Oct 2026 13:40:27 +0800 Subject: [PATCH] =?UTF-8?q?tests:=20two=20waits=20that=20went=20red=20at?= =?UTF-8?q?=20load=2080=E2=80=93100=20leave=20room:=20the=20reasoning=20re?= =?UTF-8?q?lay=20is=20timed=20by=20the=20vendor's=20clock,=20otel=20waits?= =?UTF-8?q?=20a=20minute=20for=20its=20export?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both went red in full runs of go test ./... on a machine at load 80–100. Neither is a fault in what they test. - TestChatReasoningRelayedAsItComes: "first thought after 924ms" against a 700ms bound from before the request, while the thought still came ~1s ahead of the text. The bound timed the gateway's start, not the relay. slowThinker now records when it wrote each event. The test checks that the first thought reached the client before the vendor wrote the text. That is the guarantee, and a slow start no longer counts against it. - plugins/otel TestOnExportsOffSendsNothing waited 10s for the first export. It now waits a minute, as other waits for a plugin's first work do. Run: go test -count=5 for the relay test, all ok. Broken by hand: refusesAfterThinking returns true, so the reasoning is held as Claude's is. The test went red ("reached the client 489µs after the vendor wrote the text"). Full go test ./... ran with the middleware point commit before this one (see its body). --- internal/gateway/chat_reasoning_relay_test.go | 19 +++++++++---------- internal/gateway/thinking_streams_test.go | 2 ++ plugins/otel/otel_test.go | 8 +++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/internal/gateway/chat_reasoning_relay_test.go b/internal/gateway/chat_reasoning_relay_test.go index e40adc488..032170374 100644 --- a/internal/gateway/chat_reasoning_relay_test.go +++ b/internal/gateway/chat_reasoning_relay_test.go @@ -34,32 +34,31 @@ func TestChatReasoningRelayedAsItComes(t *testing.T) { gw := httptest.NewServer(New().Handler()) t.Cleanup(gw.Close) - start := time.Now() res, err := http.Post(gw.URL+"/v1/chat/completions", "application/json", strings.NewReader(`{"model":"wb/deepseek-v4.1-flash","stream":true,"reasoning_effort":"max","messages":[{"role":"user","content":"hi"}]}`)) if err != nil { t.Fatal(err) } defer res.Body.Close() - var firstThought, firstText time.Time + var firstThought time.Time rd := bufio.NewReader(res.Body) for { ln, err := rd.ReadString('\n') if firstThought.IsZero() && strings.Contains(ln, `"reasoning_content":"hmm"`) { firstThought = time.Now() } - if firstText.IsZero() && strings.Contains(ln, `"content":"done"`) { - firstText = time.Now() - } if err != nil { break } } - if firstThought.IsZero() || firstText.IsZero() { - t.Fatal("no reasoning or no text reached the client") + if firstThought.IsZero() { + t.Fatal("no reasoning reached the client") } - // the first thought is sent 200ms in, the text a second after it - if firstThought.Sub(start) > 700*time.Millisecond || firstText.Sub(firstThought) < 700*time.Millisecond { - t.Fatalf("reasoning held: first thought after %v, %v before the text", firstThought.Sub(start), firstText.Sub(firstThought)) + <-up.done + // by the vendor's own clock, so a slow start under load doesn't count: + // the first thought reaches the client before the vendor has even + // written the text, a second after it + if text := up.sent[6]; !firstThought.Before(text) { + t.Fatalf("reasoning held: the first thought reached the client %v after the vendor wrote the text", firstThought.Sub(text)) } } diff --git a/internal/gateway/thinking_streams_test.go b/internal/gateway/thinking_streams_test.go index 8dd239876..25e2930f7 100644 --- a/internal/gateway/thinking_streams_test.go +++ b/internal/gateway/thinking_streams_test.go @@ -18,6 +18,7 @@ type slowThinker struct { events []string gap time.Duration done chan time.Time + sent []time.Time // when each event was written; read after done } func (s *slowThinker) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -28,6 +29,7 @@ func (s *slowThinker) ServeHTTP(w http.ResponseWriter, r *http.Request) { for _, ev := range s.events { io.WriteString(w, ev+"\n\n") f.Flush() + s.sent = append(s.sent, time.Now()) time.Sleep(s.gap) } s.done <- time.Now() diff --git a/plugins/otel/otel_test.go b/plugins/otel/otel_test.go index aaa096e0c..df6a80135 100644 --- a/plugins/otel/otel_test.go +++ b/plugins/otel/otel_test.go @@ -53,11 +53,13 @@ func TestOnExportsOffSendsNothing(t *testing.T) { rt := pluginrt.New([]pluginrt.Manifest{manifest(t)}) defer rt.Stop() // seen is every model the collector got until want came, or "" when it - // didn't within 10s (the first export prices its rows, which loads the - // catalog) + // didn't within a minute. The first export prices its rows, which loads + // the catalog: 10s wasn't enough on a machine at load 100 (the full + // suite). Waiting longer costs a passing run nothing, and "off sends + // nothing" doesn't hang on it: what came before model-again is checked. seen := func(want string) string { var got strings.Builder - deadline := time.After(10 * time.Second) + deadline := time.After(time.Minute) for { select { case b := <-received: