diff --git a/pkg/streamingpromql/limiting/memory_consumption.go b/pkg/streamingpromql/limiting/memory_consumption.go index fc6ce516092..ad6010075dd 100644 --- a/pkg/streamingpromql/limiting/memory_consumption.go +++ b/pkg/streamingpromql/limiting/memory_consumption.go @@ -52,7 +52,7 @@ func (l *MemoryConsumptionTracker) IncreaseMemoryConsumption(b uint64) error { // DecreaseMemoryConsumption decreases the current memory consumption by b bytes. func (l *MemoryConsumptionTracker) DecreaseMemoryConsumption(b uint64) { if b > l.CurrentEstimatedMemoryConsumptionBytes { - panic("Memory consumption tracking is negative. This indicates something has been returned to a pool more than once.") + panic("Estimated memory consumption of this query is negative. This indicates something has been returned to a pool more than once, which is a bug.") } l.CurrentEstimatedMemoryConsumptionBytes -= b } diff --git a/pkg/streamingpromql/limiting/memory_consumption_test.go b/pkg/streamingpromql/limiting/memory_consumption_test.go index f407d64d94d..17634b04767 100644 --- a/pkg/streamingpromql/limiting/memory_consumption_test.go +++ b/pkg/streamingpromql/limiting/memory_consumption_test.go @@ -46,13 +46,7 @@ func TestMemoryConsumptionTracker_Unlimited(t *testing.T) { assertRejectedQueriesCount(t, reg, 0) // Test reducing memory consumption to a negative panics - defer func() { - if r := recover(); r == nil { - t.Errorf("We did not panic on negative memory consumption") - } - }() - - tracker.DecreaseMemoryConsumption(150) + require.Panics(t, func() { tracker.DecreaseMemoryConsumption(150) }) } func TestMemoryConsumptionTracker_Limited(t *testing.T) { @@ -104,13 +98,7 @@ func TestMemoryConsumptionTracker_Limited(t *testing.T) { assertRejectedQueriesCount(t, reg, 1) // Test reducing memory consumption to a negative panics - defer func() { - if r := recover(); r == nil { - t.Errorf("We did not panic on negative memory consumption") - } - }() - - tracker.DecreaseMemoryConsumption(150) + require.Panics(t, func() { tracker.DecreaseMemoryConsumption(150) }) } func assertRejectedQueriesCount(t *testing.T, reg *prometheus.Registry, expectedRejectionCount int) {