Skip to content

Commit

Permalink
update tests to check for samples on the boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwanthgoli committed Jan 21, 2025
1 parent ab12c43 commit efebcce
Showing 1 changed file with 61 additions and 9 deletions.
70 changes: 61 additions & 9 deletions tools/querytee/response_comparator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,21 @@ func TestCompareMatrix_SamplesOutsideComparableWindow(t *testing.T) {
{
name: "skip samples before window",
expected: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[0,"1"],[5,"2"],[15,"3"],[20,"4"]]}
{"metric":{"foo":"bar"},"values":[[0,"1"],[5,"2"],[10,"3"],[20,"4"]]}
]`),
actual: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[5,"1"],[15,"3"],[20,"4"]]}
{"metric":{"foo":"bar"},"values":[[5,"1"],[10,"3"],[20,"4"]]}
]`),
skipSamplesBefore: time.Unix(10, 0),
evaluationTime: time.Unix(100, 0),
},
{
name: "skip recent samples",
expected: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[5,"1"],[25,"2"],[80,"3"],[94,"4"],[96,"5"]]}
{"metric":{"foo":"bar"},"values":[[5,"1"],[25,"2"],[90,"3"],[94,"4"],[96,"5"]]}
]`),
actual: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[5,"1"],[25,"2"],[80,"3"],[95, "4"]]}
{"metric":{"foo":"bar"},"values":[[5,"1"],[25,"2"],[90,"3"],[95, "4"]]}
]`),
skipRecentSamples: 10 * time.Second,
evaluationTime: time.Unix(100, 0),
Expand All @@ -148,6 +148,32 @@ func TestCompareMatrix_SamplesOutsideComparableWindow(t *testing.T) {
skipRecentSamples: 10 * time.Second,
evaluationTime: time.Unix(100, 0),
},
{
name: "mismatch in sample value on the right boundary",
expected: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[5,"1"],[25,"2"],[90,"3"],[94,"4"],[96,"5"]]}
]`),
actual: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[5,"1"],[25,"2"],[90,"4"],[95, "4"]]}
]`),
skipSamplesBefore: time.Unix(10, 0),
skipRecentSamples: 10 * time.Second,
evaluationTime: time.Unix(100, 0),
err: errors.New("float sample pair does not match for metric {foo=\"bar\"}: expected value 3 for timestamp 90 but got 4"),
},
{
name: "mismatch in sample value on the left boundary",
expected: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[10,"1"],[25,"2"],[90,"3"],[94,"4"],[96,"5"]]}
]`),
actual: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[10,"0"],[25,"2"],[90,"3"],[95, "4"]]}
]`),
skipSamplesBefore: time.Unix(10, 0),
skipRecentSamples: 10 * time.Second,
evaluationTime: time.Unix(100, 0),
err: errors.New("float sample pair does not match for metric {foo=\"bar\"}: expected value 1 for timestamp 10 but got 0"),
},
{
name: "skip entire series",
expected: json.RawMessage(`[
Expand All @@ -173,7 +199,7 @@ func TestCompareMatrix_SamplesOutsideComparableWindow(t *testing.T) {
return
}
require.Error(t, err)
require.Equal(t, tc.err.Error(), err.Error())
require.ErrorContains(t, err, tc.err.Error())
})
}
}
Expand Down Expand Up @@ -600,21 +626,21 @@ func TestCompareStreams_SamplesOutsideComparableWindow(t *testing.T) {
{
name: "skip samples before window",
expected: json.RawMessage(`[
{"stream":{"foo":"bar"},"values":[["5","1"],["15","2"],["50","3"],["95","4"]]}
{"stream":{"foo":"bar"},"values":[["5","1"],["10","2"],["50","3"],["95","4"]]}
]`),
actual: json.RawMessage(`[
{"stream":{"foo":"bar"},"values":[["2","0"],["15","2"],["50","3"],["95","4"]]}
{"stream":{"foo":"bar"},"values":[["2","0"],["10","2"],["50","3"],["95","4"]]}
]`),
skipSamplesBefore: time.Unix(0, 10),
evaluationTime: time.Unix(0, 100),
},
{
name: "skip recent samples",
expected: json.RawMessage(`[
{"stream":{"foo":"bar"},"values":[["5","1"],["15","2"],["50","3"],["95","4"]]}
{"stream":{"foo":"bar"},"values":[["5","1"],["15","2"],["90","3"],["95","4"]]}
]`),
actual: json.RawMessage(`[
{"stream":{"foo":"bar"},"values":[["5","1"],["15","2"],["50","3"]]}
{"stream":{"foo":"bar"},"values":[["5","1"],["15","2"],["90","3"]]}
]`),
skipRecentSamples: 10 * time.Nanosecond,
evaluationTime: time.Unix(0, 100),
Expand All @@ -631,6 +657,32 @@ func TestCompareStreams_SamplesOutsideComparableWindow(t *testing.T) {
skipSamplesBefore: time.Unix(0, 10),
evaluationTime: time.Unix(0, 100),
},
{
name: "mismatch in sample value on the right boundary",
expected: json.RawMessage(`[
{"stream":{"foo":"bar"},"values":[["5","1"],["15","2"],["50","3"],["90","4"]]}
]`),
actual: json.RawMessage(`[
{"stream":{"foo":"bar"},"values":[["15","2"],["50","3"],["90","5"]]}
]`),
skipRecentSamples: 10 * time.Nanosecond,
skipSamplesBefore: time.Unix(0, 10),
evaluationTime: time.Unix(0, 100),
err: errors.New("expected line 4 for timestamp 90 but got 5 for stream {foo=\"bar\"}"),
},
{
name: "mismatch in sample value on the left boundary",
expected: json.RawMessage(`[
{"stream":{"foo":"bar"},"values":[["5","1"],["10","2"],["50","3"],["90","4"]]}
]`),
actual: json.RawMessage(`[
{"stream":{"foo":"bar"},"values":[["10","22"],["50","3"],["90","5"]]}
]`),
skipRecentSamples: 10 * time.Nanosecond,
skipSamplesBefore: time.Unix(0, 10),
evaluationTime: time.Unix(0, 100),
err: errors.New("expected line 2 for timestamp 10 but got 22 for stream {foo=\"bar\"}"),
},
} {
t.Run(tc.name, func(t *testing.T) {
summary, err := compareStreams(tc.expected, tc.actual, tc.evaluationTime, SampleComparisonOptions{
Expand Down

0 comments on commit efebcce

Please sign in to comment.