tsdb: fix flaky TestBlockRanges by using explicit compaction#18085
Merged
Conversation
aknuds1
requested review from
a team,
ArthurSens,
Nexucis,
alexgreenbank,
bwplotka,
codesome,
cstyan,
jesusvazquez,
juliusv,
krajorama,
roidelapluie and
tomwilkie
as code owners
February 14, 2026 15:41
aknuds1
force-pushed
the
arve/fix-test-block-ranges
branch
from
February 14, 2026 15:42
25a2414 to
283cc4e
Compare
aknuds1
removed request for
ArthurSens,
Nexucis,
alexgreenbank,
cstyan,
juliusv,
roidelapluie and
tomwilkie
February 14, 2026 16:10
aknuds1
force-pushed
the
arve/fix-test-block-ranges
branch
from
February 15, 2026 09:54
283cc4e to
ef5ce89
Compare
aknuds1
marked this pull request as draft
February 15, 2026 09:59
Replace polling loops (for range 100 { time.Sleep }) with explicit
db.Compact() calls after disabling background compaction, eliminating
CI flakiness on slow machines. Also fix incorrect overlap assertions
that were checking the wrong direction (LessOrEqual -> GreaterOrEqual).
Signed-off-by: Arve Knudsen <[email protected]>
aknuds1
force-pushed
the
arve/fix-test-block-ranges
branch
from
February 15, 2026 10:44
5a61c87 to
b0718d5
Compare
aknuds1
marked this pull request as ready for review
February 15, 2026 11:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue(s) does the PR fix:
N/A — fixes a flaky test discovered during local testing.
Does this PR introduce a user-facing change?
Summary
TestBlockRangesandTestBlockRanges_AppendV2are flaky because they rely on background auto-compaction via therun()goroutine, using a polling loop with a 10-second effective timeout. On slow or loaded CI machines, goroutine scheduling delays can cause this timeout to be insufficient.This PR fixes the flakiness by:
db.Compact(ctx)calls — makes compaction deterministic, removing all timing dependencydb.DisableCompactions()after eachOpen()— prevents the background goroutine from racing with explicit compactionLessOrEqual→GreaterOrEqual) — the original assertion checked adjacency, not non-overlap, which is what the test comment describesdb.Blocks()in a local variable before assertions — eliminates a potential TOCTOU race if background compaction were to run between callsThis approach is consistent with other tests in the codebase (e.g.,
TestNoEmptyBlocks,TestDeleteCompactionBlockAfterFailedReload) that already use explicitdb.Compact()withdb.DisableCompactions().Verified by running both tests 100 times each with
-race— all iterations passed.