MCPcopy Index your code
hub / github.com/coder/coder / TestRecordCompaction

Function TestRecordCompaction

coderd/x/chatd/chatloop/metrics_test.go:200–279  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

198}
199
200func TestRecordCompaction(t *testing.T) {
201 t.Parallel()
202
203 t.Run("nil metrics does not panic", func(t *testing.T) {
204 t.Parallel()
205 var m *chatloop.Metrics
206 m.RecordCompaction("anthropic", "claude-sonnet-4-5", true, nil)
207 })
208
209 tests := []struct {
210 name string
211 compacted bool
212 err error
213 wantLabel string
214 wantCount int
215 }{
216 {
217 name: "success",
218 compacted: true,
219 err: nil,
220 wantLabel: chatloop.CompactionResultSuccess,
221 wantCount: 1,
222 },
223 {
224 name: "error",
225 compacted: false,
226 err: assert.AnError,
227 wantLabel: chatloop.CompactionResultError,
228 wantCount: 1,
229 },
230 {
231 name: "timeout",
232 compacted: false,
233 err: context.DeadlineExceeded,
234 wantLabel: chatloop.CompactionResultTimeout,
235 wantCount: 1,
236 },
237 {
238 name: "threshold_not_reached",
239 compacted: false,
240 err: nil,
241 wantLabel: "",
242 wantCount: 0,
243 },
244 {
245 name: "canceled",
246 compacted: false,
247 err: context.Canceled,
248 wantLabel: "",
249 wantCount: 0,
250 },
251 }
252
253 for _, tt := range tests {
254 t.Run(tt.name, func(t *testing.T) {
255 t.Parallel()
256
257 reg := prometheus.NewRegistry()

Callers

nothing calls this directly

Calls 5

RecordCompactionMethod · 0.95
NewMetricsFunction · 0.92
requireCounterFunction · 0.85
RunMethod · 0.65
GetNameMethod · 0.45

Tested by

no test coverage detected