diff --git a/pkg/streamingpromql/operators/series_merging_test.go b/pkg/streamingpromql/operators/series_merging_test.go index 0212c68b48..026947df4e 100644 --- a/pkg/streamingpromql/operators/series_merging_test.go +++ b/pkg/streamingpromql/operators/series_merging_test.go @@ -18,8 +18,9 @@ func TestMergeSeries(t *testing.T) { input []types.InstantVectorSeriesData sourceSeriesIndices []int - expectedOutput types.InstantVectorSeriesData - expectedConflict *MergeConflict + expectedOutput types.InstantVectorSeriesData + expectedConflict *MergeConflict + expectInputHPointSlicesCleared bool }{ "no input series": { input: []types.InstantVectorSeriesData{}, @@ -120,6 +121,7 @@ func TestMergeSeries(t *testing.T) { {T: 6, H: &histogram.FloatHistogram{Count: 60, Sum: 600}}, }, }, + expectInputHPointSlicesCleared: true, }, "two float only input series with no overlap, series not in time order": { input: []types.InstantVectorSeriesData{ @@ -178,6 +180,7 @@ func TestMergeSeries(t *testing.T) { {T: 6, H: &histogram.FloatHistogram{Count: 60, Sum: 600}}, }, }, + expectInputHPointSlicesCleared: true, }, "three float only input series with no overlap": { input: []types.InstantVectorSeriesData{ @@ -256,6 +259,7 @@ func TestMergeSeries(t *testing.T) { {T: 9, H: &histogram.FloatHistogram{Count: 90, Sum: 900}}, }, }, + expectInputHPointSlicesCleared: true, }, "two float only input series with overlap": { input: []types.InstantVectorSeriesData{ @@ -314,6 +318,7 @@ func TestMergeSeries(t *testing.T) { {T: 6, H: &histogram.FloatHistogram{Count: 60, Sum: 600}}, }, }, + expectInputHPointSlicesCleared: true, }, "three float only input series with overlap": { input: []types.InstantVectorSeriesData{ @@ -380,6 +385,7 @@ func TestMergeSeries(t *testing.T) { {T: 6, H: &histogram.FloatHistogram{Count: 60, Sum: 600}}, }, }, + expectInputHPointSlicesCleared: true, }, "float only input series with conflict": { input: []types.InstantVectorSeriesData{ @@ -546,6 +552,7 @@ func TestMergeSeries(t *testing.T) { {T: 6, H: &histogram.FloatHistogram{Count: 6, Sum: 6}}, }, }, + expectInputHPointSlicesCleared: true, }, "mixed float and histogram input series, series not in time order": { input: []types.InstantVectorSeriesData{ @@ -581,6 +588,7 @@ func TestMergeSeries(t *testing.T) { {T: 6, H: &histogram.FloatHistogram{Count: 6, Sum: 6}}, }, }, + expectInputHPointSlicesCleared: true, }, "mixed float and histogram input series, series in conflict on different types": { input: []types.InstantVectorSeriesData{ @@ -690,6 +698,7 @@ func TestMergeSeries(t *testing.T) { {T: 10, H: &histogram.FloatHistogram{Count: 10, Sum: 10}}, }, }, + expectInputHPointSlicesCleared: true, }, "input series exclusively with floats, histograms, or mixed, all overlap": { input: []types.InstantVectorSeriesData{ @@ -743,6 +752,7 @@ func TestMergeSeries(t *testing.T) { {T: 10, H: &histogram.FloatHistogram{Count: 10, Sum: 10}}, }, }, + expectInputHPointSlicesCleared: true, }, } @@ -758,6 +768,14 @@ func TestMergeSeries(t *testing.T) { require.Nil(t, conflict) require.Equal(t, testCase.expectedOutput, result) } + + if testCase.expectInputHPointSlicesCleared { + for sliceIdx, slice := range testCase.input { + for pointIdx, point := range slice.Histograms { + require.Nilf(t, point.H, "expected point at index %v of HPoint slice at index %v to have been cleared, but it was not", pointIdx, sliceIdx) + } + } + } }) } }