(t *testing.T)
| 356 | } |
| 357 | |
| 358 | func Test_gauge_demandDecay(t *testing.T) { |
| 359 | lifecycler := &mockLimiter{} |
| 360 | g := newGauge("my_gauge", lifecycler, map[string]string{}, 15*time.Minute) |
| 361 | |
| 362 | // Add series |
| 363 | for i := 0; i < 40; i++ { |
| 364 | lbls := buildTestLabels([]string{"label"}, []string{fmt.Sprintf("value-%d", i)}) |
| 365 | g.Inc(lbls, 1.0) |
| 366 | } |
| 367 | |
| 368 | initialDemand := g.countSeriesDemand() |
| 369 | assert.Greater(t, initialDemand, 0) |
| 370 | |
| 371 | // Advance the cardinality tracker enough times to clear the window |
| 372 | for i := 0; i < 5; i++ { |
| 373 | g.removeStaleSeries(time.Now().Add(time.Hour).UnixMilli()) |
| 374 | } |
| 375 | |
| 376 | // Demand should have decreased or be zero |
| 377 | finalDemand := g.countSeriesDemand() |
| 378 | assert.LessOrEqual(t, finalDemand, initialDemand/2, "demand should significantly decay") |
| 379 | } |
| 380 | |
| 381 | func Test_gauge_onUpdate(t *testing.T) { |
| 382 | var seriesUpdated int |
nothing calls this directly
no test coverage detected