fix: context leak in TestChatStream_EarlyCancel

Add defer cancel() so the context is always cancelled, even when the
loop exits early due to an error before reaching 5 events.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
dj-oyu 2026-02-24 17:18:46 +09:00
parent 72c4066210
commit 5bebfce972

View file

@ -637,6 +637,7 @@ func TestChatStream_EarlyCancel(t *testing.T) {
p := NewProviderWithOptions("key", server.URL, "", Options{Stream: true})
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ch, err := p.ChatStream(ctx, []Message{{Role: "user", Content: "hi"}}, nil, "test", nil)
if err != nil {
t.Fatalf("ChatStream() error = %v", err)