[fix][test] Fix flaky AuditorBookieTest.testBookieClusterRestart - #26122
Merged
Conversation
### Motivation `AuditorBookieTest.testBookieClusterRestart` is flaky. Two independent problems combine to make it fail intermittently: 1. The "cluster restart" tears the cluster down with `stopBKCluster()` and recreates the bookies via `startBKCluster()`, which allocates fresh data directories and pulls ports from `PortManager`. `PortManager` can hand back a port a just-stopped bookie used, so a new bookie may land on a recycled host:port with a different data directory. That fails bookie cookie validation against the cookie still registered in the metadata store: `BookieException$InvalidCookieException`. 2. `stopAuditorElectors()` shuts the electors down but never clears the `auditorElectors` map. The same test instance is reused across test methods (and across TestNG retries), so a later run that iterates over `auditorElectors` observes stale, already-stopped electors whose `isRunning()` returns false, tripping the "Auditor elector is not running\!" assertion. ### Modifications - Restart the cluster with `restartBookies()`, which preserves each bookie's identity (host:port and data dirs) so cookie validation passes. This also drops the no-longer-needed `metadataServiceUri` juggling. - Clear the `auditorElectors` map in `stopAuditorElectors()` so stale electors are not re-checked by a subsequent test method or retry. ### Verification Ran the class with `@Test(invocationCount = 10)` and `-PtestRetryCount=0` (which reproduces the same-instance retry scenario from CI): all 10 invocations pass. Assisted-by: Claude Code (Opus 4.8)
merlimat
approved these changes
Jun 30, 2026
10 tasks
RobertIndie
pushed a commit
that referenced
this pull request
Jul 1, 2026
) (cherry picked from commit 116212f)
lhotari
added a commit
that referenced
this pull request
Jul 2, 2026
) (cherry picked from commit 116212f)
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.
Fixes: #21538
Motivation
AuditorBookieTest.testBookieClusterRestartis flaky (issue #21538). Investigating a recent failure showed two independent problems that combine to make the test fail intermittently:Bookie cookie mismatch on restart. The test "restarts" the cluster with
stopBKCluster()followed bystartBKCluster().startBKCluster()recreates the bookies with fresh data directories and pulls new ports fromPortManager.PortManagercan hand back a port a just-stopped bookie used, so a new bookie may come up on a recycledhost:portwith a different data directory. That fails bookie cookie validation against the cookie still registered in the metadata store, throwingBookieException$InvalidCookieExceptionfromstartBKCluster():Stale auditor electors leaking across runs.
stopAuditorElectors()shuts the electors down but never clears theauditorElectorsmap. The same test instance is reused across test methods (and across TestNG retries), so a later run that iterates overauditorElectorsobserves stale, already-stopped electors whoseisRunning()returnsfalse, tripping the assertion:This is the assertion reported in Flaky-test: AuditorBookieTest.testBookieClusterRestart #21538. It surfaced on a retry: the first attempt failed with the cookie mismatch (1), and the retry — running on the same instance with the previous run's shut-down electors still in the map — failed on this assertion in a few milliseconds.
Modifications
restartBookies()helper, which preserves each bookie's identity (host:portand data directories) so cookie validation passes. This also drops the no-longer-neededmetadataServiceUrijuggling thatstartBKCluster()required.auditorElectorsmap instopAuditorElectors()so stale, shut-down electors are not re-checked by a subsequent test method or retry.Verifying this change
This change is already covered by the existing
AuditorBookieTest.It was verified by running the class with
@Test(invocationCount = 10)and-PtestRetryCount=0, which reproduces the same-instance retry scenario from CI: all 10 invocations oftestBookieClusterRestartpass (0 failures, 0 skipped).spotlessCheck,checkstyleMain, andcheckstyleTestpass.Does this pull request potentially affect one of the following parts: