Skip to content

[test] Fix unstable test BatchScannerITCase.testKvSnapshotLease#3305

Open
Kaixuan-Duan wants to merge 1 commit into
apache:mainfrom
Kaixuan-Duan:issue-3218-unstable-testKvSnapshotLease
Open

[test] Fix unstable test BatchScannerITCase.testKvSnapshotLease#3305
Kaixuan-Duan wants to merge 1 commit into
apache:mainfrom
Kaixuan-Duan:issue-3218-unstable-testKvSnapshotLease

Conversation

@Kaixuan-Duan
Copy link
Copy Markdown
Contributor

Purpose

Linked issue: close #3218

Brief change log

The test BatchScannerITCase.testKvSnapshotLease is 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 calls kvSnapshotManager.triggerSnapshot() which submits the task asynchronously to guardedExecutor, then immediately checks currentSnapshotId(). 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 method buildExpectedBucketSnapshots() 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

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.

[test] Unstable test BatchScannerITCase.testKvSnapshotLease

1 participant