Skip to content

Fix flaky TestDistributorQuerier_QueryIngestersWithinBoundary#7419

Open
CharlieTLe wants to merge 1 commit intocortexproject:masterfrom
CharlieTLe:flaky-test
Open

Fix flaky TestDistributorQuerier_QueryIngestersWithinBoundary#7419
CharlieTLe wants to merge 1 commit intocortexproject:masterfrom
CharlieTLe:flaky-test

Conversation

@CharlieTLe
Copy link
Copy Markdown
Member

Summary

  • Inject a nowFn func() time.Time into distributorQuerier so tests can control the clock, fixing the wall-clock race condition that caused flakiness on slow ARM CI runners
  • Replace assert.InDelta with exact assert.Equal now that the clock is deterministic in tests
  • Default to time.Now in production (pass nil for nowFn)

Closes #7415

Test plan

  • go test -count=100 -run TestDistributorQuerier_QueryIngestersWithinBoundary ./pkg/querier/... passes all 100 iterations
  • Full go test ./pkg/querier/... suite passes with no regressions

🤖 Generated with Claude Code

…cting clock

The test was flaky because it captured `time.Now()` at setup, but
`distributorQuerier.Select()` called `time.Now()` again internally.
On slow CI runners, the clock drift could exceed the 10-second margin
in the "maxT well after lookback boundary" subtest, causing the query
to short-circuit with an empty result.

Inject a `nowFn` function into `distributorQuerier` (defaulting to
`time.Now`) so tests can freeze time. Replace the `InDelta` assertion
with an exact `Equal` now that the clock is deterministic.

Closes cortexproject#7415

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Charlie Le <charlie_le@apple.com>
@CharlieTLe CharlieTLe marked this pull request as ready for review April 12, 2026 21:00
Copy link
Copy Markdown
Member

@SungJin1212 SungJin1212 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size/M type/flaky-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: TestDistributorQuerier_QueryIngestersWithinBoundary due to wall-clock race condition

2 participants