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:
parent
8f68847d55
commit
904c5213dd
1 changed files with 1 additions and 0 deletions
|
|
@ -637,6 +637,7 @@ func TestChatStream_EarlyCancel(t *testing.T) {
|
||||||
p := NewProviderWithOptions("key", server.URL, "", Options{Stream: true})
|
p := NewProviderWithOptions("key", server.URL, "", Options{Stream: true})
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
ch, err := p.ChatStream(ctx, []Message{{Role: "user", Content: "hi"}}, nil, "test", nil)
|
ch, err := p.ChatStream(ctx, []Message{{Role: "user", Content: "hi"}}, nil, "test", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ChatStream() error = %v", err)
|
t.Fatalf("ChatStream() error = %v", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue