Skip to content

Commit

Permalink
test: Fix flaky TestQuerier_ValidateQueryTimeRange_MaxQueryLength (#1…
Browse files Browse the repository at this point in the history
…0529)

Use a consistent value for "now" to ensure the error message matches
the expected error in tests.

Fixes #10094

Signed-off-by: Nick Pillitteri <[email protected]>
  • Loading branch information
56quarters authored Jan 28, 2025
1 parent 0aeb211 commit 266a393
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pkg/querier/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ func TestQuerier_ValidateQueryTimeRange(t *testing.T) {

func TestQuerier_ValidateQueryTimeRange_MaxQueryLength(t *testing.T) {
const maxQueryLength = 30 * 24 * time.Hour
now := time.Now()

tests := map[string]struct {
query string
Expand All @@ -744,26 +745,26 @@ func TestQuerier_ValidateQueryTimeRange_MaxQueryLength(t *testing.T) {
}{
"should allow query on short time range and rate time window close to the limit": {
query: "rate(foo[29d])",
queryStartTime: time.Now().Add(-time.Hour),
queryEndTime: time.Now(),
queryStartTime: now.Add(-time.Hour),
queryEndTime: now,
expected: nil,
},
"should allow query on large time range close to the limit and short rate time window": {
query: "rate(foo[1m])",
queryStartTime: time.Now().Add(-maxQueryLength).Add(time.Hour),
queryEndTime: time.Now(),
queryStartTime: now.Add(-maxQueryLength).Add(time.Hour),
queryEndTime: now,
expected: nil,
},
"should forbid query on short time range and rate time window over the limit": {
query: "rate(foo[31d])",
queryStartTime: time.Now().Add(-time.Hour),
queryEndTime: time.Now(),
queryStartTime: now.Add(-time.Hour),
queryEndTime: now,
expected: errors.Errorf("expanding series: %s", NewMaxQueryLengthError(745*time.Hour-time.Millisecond, 720*time.Hour)),
},
"should forbid query on large time range over the limit and short rate time window": {
query: "rate(foo[1m])",
queryStartTime: time.Now().Add(-maxQueryLength).Add(-time.Hour),
queryEndTime: time.Now(),
queryStartTime: now.Add(-maxQueryLength).Add(-time.Hour),
queryEndTime: now,
expected: errors.Errorf("expanding series: %s", NewMaxQueryLengthError((721*time.Hour)+time.Minute-time.Millisecond, 720*time.Hour)),
},
}
Expand Down

0 comments on commit 266a393

Please sign in to comment.