Skip to content

tsdb: fix flaky TestQuerierShouldNotFailIfOOOCompactionOccurs* tests - #19108

Merged
krajorama merged 1 commit into
prometheus:mainfrom
junkerderprovinz:fix/flaky-ooo-compaction-tests
Jul 7, 2026
Merged

krajorama merged 1 commit into
prometheus:mainfrom
junkerderprovinz:fix/flaky-ooo-compaction-tests

Conversation

@junkerderprovinz

Copy link
Copy Markdown
Contributor

Which issue(s) does the PR fix:

Part of #17941 (the remaining TestQuerierShouldNotFailIfOOOCompactionOccursAfterRetrievingQuerier_AppendV2 / _Iterators_AppendV2 Windows item; intentionally not Fixes so the meta issue stays open).

What this PR does:

All six TestQuerierShouldNotFailIfOOOCompactionOccurs* tests (three in db_test.go, three _AppendV2 variants) wait at most one second for CompactOOOHead to complete after closing the blocking querier:

require.Eventually(t, compactionComplete.Load, time.Second, 10*time.Millisecond, ...)

That window sits right at the failure boundary by construction: the compaction goroutine only notices the querier close by polling in 500ms intervals (WaitForPendingReadersForOOOChunksAtOrBefore, head.go#L1393-L1397), and after it notices it still has to garbage collect chunks and truncate the WBL. On slow Windows CI runners that regularly exceeds one second, producing the failures posted in #17941.

Two changes, test-only:

  1. Widen the require.Eventually window from 1s to 1min. Eventually returns as soon as the condition holds, so fast runners lose nothing; slow runners stop flaking.
  2. Move the require calls out of the compaction goroutine. require must not be called from non-test goroutines (t.FailNow only works on the test goroutine). This is also what produced the confusing secondary compact ooo head: populate block: context canceled failures in the CI logs: after the Eventually timeout failed the test, cleanup closed the DB, and the still-running goroutine's require.NoError fired with the cancellation error. The goroutine now reports its error through a channel and all assertions (including the chunksRemoved metric check) happen on the test goroutine after completion.

The initial time.Sleep(time.Second) + require.False (asserting compaction blocks while the querier is open) is left untouched — its semantics are unaffected.

Verification

Ran natively on Windows (the platform where the flake reproduces): all six tests, three runs each, green (go test ./tsdb/ -run "TestQuerierShouldNotFailIfOOOCompactionOccurs" -count=3).

Release notes for end users (ALL commits must be considered).

Reviewers should verify clarity and quality.

NONE

These tests (and their _AppendV2 variants) waited at most one second for
CompactOOOHead to finish after closing the blocking querier. The
compaction goroutine only re-checks for pending readers in 500ms
intervals (WaitForPendingReadersForOOOChunksAtOrBefore) and still has to
garbage collect chunks and truncate the WBL after it notices the close,
so the one second window sits right at the failure boundary and
regularly times out on slow Windows CI runners.

Widen the wait to a minute (require.Eventually returns as soon as the
condition holds, so fast runners lose nothing) and move the require
calls out of the compaction goroutine: require must not be called from
non-test goroutines, and its late FailNow there produced the confusing
secondary "compact ooo head: populate block: context canceled" failures
when the DB was closed during cleanup after the timeout.

Part of prometheus#17941

Signed-off-by: junkerderprovinz <[email protected]>

@krajorama krajorama left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, LGTM, if this works out and you have time consider refactoring to reduce code duplication

@krajorama
krajorama merged commit 870b8b1 into prometheus:main Jul 7, 2026
62 of 64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants