[test] Fix unstable test BatchScannerITCase.testKvSnapshotLease#3305
Open
Kaixuan-Duan wants to merge 1 commit into
Open
[test] Fix unstable test BatchScannerITCase.testKvSnapshotLease#3305Kaixuan-Duan wants to merge 1 commit into
Kaixuan-Duan wants to merge 1 commit into
Conversation
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.
Purpose
Linked issue: close #3218
Brief change log
The test
BatchScannerITCase.testKvSnapshotLeaseis flaky because it hardcodes expected snapshot IDs ({0L, 0L, 0L},{1L, 1L, 1L}) assuming snapshot IDs always start from 0 and increment in lockstep across all buckets.However,
FlussClusterExtension.triggerSnapshot()has a race condition: it callskvSnapshotManager.triggerSnapshot()which submits the task asynchronously to guardedExecutor, then immediately checkscurrentSnapshotId(). If the async task hasn't executed yet, the method returns null and skips waiting for that bucket's snapshot. The background snapshot still completes eventually, potentially causing snapshot IDs to diverge from the hardcoded expectations.The fix replaces all hardcoded snapshot IDs with dynamically computed values based on the actual snapshot IDs returned by
admin.getLatestKvSnapshots(). A helper methodbuildExpectedBucketSnapshots()is introduced to construct the expected Long[] array from the actual consumeBuckets map.Tests
Since the flakiness is caused by a race condition in snapshot ID assignment, it cannot be reliably reproduced in a single run.
The key verification is that the test no longer relies on hardcoded snapshot IDs — it dynamically reads actual snapshot IDs from the cluster and uses them to construct assertions, making it resilient to any snapshot ID offset caused by async timing.
./mvnw -pl fluss-client -Dtest='BatchScannerITCase.testKvSnapshotLease' -DfailIfNoTests=false test
API and Format
Documentation