(t *testing.T)
| 323 | } |
| 324 | |
| 325 | func 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 |
nothing calls this directly
no test coverage detected