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