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

Function TestRecordStreamBufferDropped

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

Source from the content-addressed store, hash-verified

323}
324
325func TestRecordStreamBufferDropped(t *testing.T) {
326 t.Parallel()
327
328 t.Run("nil metrics does not panic", func(t *testing.T) {
329 t.Parallel()
330 var m *chatloop.Metrics
331 m.RecordStreamBufferDropped()
332 })
333
334 t.Run("increments monotonically", func(t *testing.T) {
335 t.Parallel()
336
337 reg := prometheus.NewRegistry()
338 m := chatloop.NewMetrics(reg)
339
340 m.RecordStreamBufferDropped()
341 m.RecordStreamBufferDropped()
342 m.RecordStreamBufferDropped()
343
344 families, err := reg.Gather()
345 require.NoError(t, err)
346
347 var found bool
348 for _, f := range families {
349 if f.GetName() != "coderd_chatd_stream_buffer_dropped_total" {
350 continue
351 }
352 found = true
353 require.Len(t, f.GetMetric(), 1)
354 assert.Equal(t, float64(3), f.GetMetric()[0].GetCounter().GetValue())
355 assert.Empty(t, f.GetMetric()[0].GetLabel(),
356 "stream_buffer_dropped_total must be an unlabeled counter")
357 }
358 assert.True(t, found, "stream_buffer_dropped_total metric not found")
359 })
360}
361
362// requireCounter gathers metrics from reg, finds the named counter
363// family, and asserts it has exactly one series with the given value

Callers

nothing calls this directly

Calls 8

NewMetricsFunction · 0.92
RunMethod · 0.65
GetNameMethod · 0.45
LenMethod · 0.45
EqualMethod · 0.45
GetValueMethod · 0.45
EmptyMethod · 0.45

Tested by

no test coverage detected