MCPcopy Create free account
hub / github.com/astercloud/aster / TestRunBatch_ProgressCallback

Function TestRunBatch_ProgressCallback

pkg/evals/batch_test.go:124–176  ·  view source on GitHub ↗

TestRunBatch_ProgressCallback 测试进度回调

(t *testing.T)

Source from the content-addressed store, hash-verified

122
123// TestRunBatch_ProgressCallback 测试进度回调
124func TestRunBatch_ProgressCallback(t *testing.T) {
125 mockProvider := &MockProvider{
126 response: `{"score": 0.75, "reason": "进度测试"}`,
127 }
128
129 testCases := make([]*BatchTestCase, 5)
130 for i := range 5 {
131 testCases[i] = &BatchTestCase{
132 ID: string(rune('A' + i)),
133 Input: &TextEvalInput{Answer: "测试"},
134 }
135 }
136
137 scorers := []Scorer{
138 NewFaithfulnessScorer(mockProvider),
139 }
140
141 var progressCalls int
142 var lastCompleted, lastTotal int
143
144 cfg := &BatchConfig{
145 TestCases: testCases,
146 Scorers: scorers,
147 Concurrency: 2,
148 ProgressCallback: func(completed, total int) {
149 progressCalls++
150 lastCompleted = completed
151 lastTotal = total
152 },
153 }
154
155 result, err := RunBatch(context.Background(), cfg)
156 if err != nil {
157 t.Fatalf("RunBatch() error = %v", err)
158 }
159
160 // 验证进度回调被调用
161 if progressCalls == 0 {
162 t.Error("ProgressCallback was never called")
163 }
164
165 if lastCompleted != 5 {
166 t.Errorf("Last completed = %d, want 5", lastCompleted)
167 }
168
169 if lastTotal != 5 {
170 t.Errorf("Last total = %d, want 5", lastTotal)
171 }
172
173 if result.Summary.SuccessfulCases != 5 {
174 t.Errorf("SuccessfulCases = %d, want 5", result.Summary.SuccessfulCases)
175 }
176}
177
178// TestRunBatch_StopOnError 测试遇错停止
179func TestRunBatch_StopOnError(t *testing.T) {

Callers

nothing calls this directly

Calls 3

NewFaithfulnessScorerFunction · 0.85
RunBatchFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected