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: