MCPcopy Create free account
hub / github.com/cortexproject/cortex / testLimiter

Function testLimiter

pkg/alertmanager/alertmanager_test.go:289–310  ·  view source on GitHub ↗

testLimiter sends sequence of alerts to limiter, and checks if limiter updated reacted correctly.

(t *testing.T, limits Limits, ops []callbackOp)

Source from the content-addressed store, hash-verified

287
288// testLimiter sends sequence of alerts to limiter, and checks if limiter updated reacted correctly.
289func testLimiter(t *testing.T, limits Limits, ops []callbackOp) {
290 reg := prometheus.NewPedanticRegistry()
291
292 limiter := newAlertsLimiter("test", limits, reg)
293
294 for ix, op := range ops {
295 if op.delete {
296 limiter.PostDelete(op.alert)
297 } else {
298 err := limiter.PreStore(op.alert, op.existing)
299 require.Equal(t, op.expectedInsertError, err, "op %d", ix)
300 if err == nil {
301 limiter.PostStore(op.alert, op.existing)
302 }
303 }
304
305 count, totalSize := limiter.currentStats()
306
307 assert.Equal(t, op.expectedCount, count, "wrong count, op %d", ix)
308 assert.Equal(t, op.expectedTotalSize, totalSize, "wrong total size, op %d", ix)
309 }
310}

Calls 6

newAlertsLimiterFunction · 0.85
PostDeleteMethod · 0.80
PreStoreMethod · 0.80
PostStoreMethod · 0.80
currentStatsMethod · 0.80
EqualMethod · 0.65

Tested by

no test coverage detected