Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskorn committed Oct 14, 2024
1 parent 53c9b2e commit 026dede
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pkg/streamingpromql/operators/series_merging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -743,6 +752,7 @@ func TestMergeSeries(t *testing.T) {
{T: 10, H: &histogram.FloatHistogram{Count: 10, Sum: 10}},
},
},
expectInputHPointSlicesCleared: true,
},
}

Expand All @@ -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)
}
}
}
})
}
}

0 comments on commit 026dede

Please sign in to comment.