Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/util/queryeviction/evictor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
querier_stats "github.com/cortexproject/cortex/pkg/querier/stats"
"github.com/cortexproject/cortex/pkg/util/resource"
"github.com/cortexproject/cortex/pkg/util/services"
"github.com/cortexproject/cortex/pkg/util/test"
)

type mockMonitor struct {
Expand Down Expand Up @@ -138,7 +139,10 @@ func TestCPUCheckedBeforeHeap(t *testing.T) {
evictor := startEvictor(t, newMockMonitor(0.95, 0.95), reg, testEvictorConfig(0.9, 0.9, 0))
waitEvicted(t, evicted)

assert.Equal(t, float64(1), promtest.ToFloat64(evictor.evictionsTotal.WithLabelValues(string(resource.CPU))))
// The eviction callback runs before the counter is incremented, so poll for it.
test.Poll(t, time.Second, float64(1), func() any {
return promtest.ToFloat64(evictor.evictionsTotal.WithLabelValues(string(resource.CPU)))
})
assert.Equal(t, float64(0), promtest.ToFloat64(evictor.evictionsTotal.WithLabelValues(string(resource.Heap))))
}

Expand Down Expand Up @@ -207,7 +211,9 @@ func TestPrometheusMetrics_IncrementedCorrectly(t *testing.T) {
waitEvicted(t, evicted)
}

assert.Equal(t, float64(3), promtest.ToFloat64(evictor.evictionsTotal.WithLabelValues(string(resource.CPU))))
test.Poll(t, time.Second, float64(3), func() any {
return promtest.ToFloat64(evictor.evictionsTotal.WithLabelValues(string(resource.CPU)))
})
}

func TestNewQueryEvictor_ReturnsNilWhenDisabled(t *testing.T) {
Expand Down