MINOR: Fix flaky testDescribeQuorumRequestToControllers and testCannotResignIfObserver - #23283
Merged
Conversation
…tResignIfObserver KRaftClusterTest#testDescribeQuorumRequestToControllers: the test forces a leader change and asserts the new leader differs, but it observed the change with a single in-flight DescribeQuorum request that raced the old leader's resignation. DescribeQuorum is answered on the same raft IO thread that performs the resignation and branches purely on quorum.isLeader(), so when the request was handled before that thread resigned, the old leader answered with itself as leader and the "leader has changed" assertion failed. The extra controller.shutdown() added in KAFKA-18771 only addressed a different race (the request being dropped), not this one. Shut the old leader down fully first, then poll describeMetadataQuorum until a surviving controller reports itself as the new leader. Because the old leader is gone, no successful response can name it, so the assertion is now deterministic; polling also lets the admin client retry through the NOT_LEADER_OR_FOLLOWER errors and re-resolve the active controller. The trailing assertions previously re-checked the original quorumInfo/voterIds (silent no-ops); they now validate the post-election quorumInfo2. KafkaRaftClientTest#testCannotResignIfObserver: leaderId and otherNodeId were drawn from two independent randomReplicaId() calls (otherNodeId = randomReplicaId() + 1), so they collided about 0.1% of the time and Set.of(leaderId, otherNodeId) then threw IllegalArgumentException for a duplicate element. Derive otherNodeId from leaderId (leaderId + 1) to guarantee distinct voter ids, matching the sibling testCannotResignIfNotLeader and testCannotResignWithLargerEpochThanCurrentEpoch tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
omkreddy
approved these changes
Aug 27, 2026
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.
What Changed
KRaftClusterTest#testDescribeQuorumRequestToControllers:
the test forces a leader change and asserts the new leader differs, but
it observed the change with a single in-flight
DescribeQuorumrequestthat races with the old leader's resignation.
Shut the old leader down fully first, then poll
describeMetadataQuorumuntil a surviving controller reports itself as the new leader. Because
the old leader is gone, no successful response can name it, so the
assertion is now deterministic; polling also lets the admin client retry
through the
NOT_LEADER_OR_FOLLOWERerrors and re-resolve the activecontroller.
KafkaRaftClientTest#testCannotResignIfObserver:
leaderIdandotherNodeIdwere drawn from tworandomReplicaId()calls, so the test's voter ids can collide and throw a
IllegalArgumentException. Other unit tests in theraftmodule onlycall
randomReplicaId()once so do not run into this.Reviewers: Manikumar Reddy manikumar.reddy@gmail.com