MCPcopy
hub / github.com/grafana/tempo / Test_counter_onUpdate

Function Test_counter_onUpdate

modules/generator/registry/counter_test.go:385–414  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

383}
384
385func Test_counter_onUpdate(t *testing.T) {
386 var seriesUpdated int
387 lifecycler := &mockLimiter{
388 onAddFunc: func(hash uint64, _ uint32, lbls labels.Labels) (labels.Labels, uint64) {
389 return lbls, hash
390 },
391 onUpdateFunc: func(_ uint64, count uint32) {
392 assert.Equal(t, uint32(1), count)
393 seriesUpdated++
394 },
395 }
396
397 c := newCounter("my_counter", lifecycler, map[string]string{}, 15*time.Minute)
398
399 // Add initial series
400 c.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 1.0)
401 c.Inc(buildTestLabels([]string{"label"}, []string{"value-2"}), 2.0)
402
403 // No updates yet (new series don't trigger OnUpdate)
404 assert.Equal(t, 0, seriesUpdated)
405
406 // Update existing series
407 c.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 1.0)
408 assert.Equal(t, 1, seriesUpdated)
409
410 // Update both series
411 c.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 3.0)
412 c.Inc(buildTestLabels([]string{"label"}, []string{"value-2"}), 4.0)
413 assert.Equal(t, 3, seriesUpdated)
414}

Callers

nothing calls this directly

Calls 4

newCounterFunction · 0.85
buildTestLabelsFunction · 0.85
IncMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected