Skip model progress after caller cancellation
This commit is contained in:
@@ -29,6 +29,41 @@ type reply struct {
|
||||
content string
|
||||
}
|
||||
|
||||
func TestCanceledCallSkipsProgress(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
cancelBefore bool
|
||||
wantStarts int
|
||||
}{
|
||||
{name: "canceled before start", cancelBefore: true},
|
||||
{name: "canceled during start", wantStarts: 1},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
if tc.cancelBefore {
|
||||
cancel()
|
||||
}
|
||||
starts, finishes := 0, 0
|
||||
client := RoleClient{hooks: CallHooks{
|
||||
OnProgress: func(_ structuredoutput.DiagnosticContext, counts *outcomes.ExecutionCounts, _ error) {
|
||||
if counts == nil {
|
||||
starts++
|
||||
cancel()
|
||||
} else {
|
||||
finishes++
|
||||
}
|
||||
},
|
||||
}}
|
||||
var result map[string]any
|
||||
_, err := client.CompleteStructured(ctx, structuredoutput.Request{}, &result)
|
||||
if !errors.Is(err, context.Canceled) || starts != tc.wantStarts || finishes != 0 {
|
||||
t.Fatalf("progress starts = %d, finishes = %d, error = %v", starts, finishes, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func adapterFixture(t *testing.T, replies []reply, retries, repairs int, hook func(*http.Request)) (*Runtime, *atomic.Int32, string) {
|
||||
return adapterFixtureWithPrompt(t, replies, retries, repairs, hook, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user