Skip to content

MINOR: Fix flaky testDescribeQuorumRequestToControllers and testCannotResignIfObserver - #23283

Merged
omkreddy merged 2 commits into
apache:trunkfrom
kevin-wu24:fix-flaky-tests
Aug 27, 2026
Merged

MINOR: Fix flaky testDescribeQuorumRequestToControllers and testCannotResignIfObserver#23283
omkreddy merged 2 commits into
apache:trunkfrom
kevin-wu24:fix-flaky-tests

Conversation

@kevin-wu24

@kevin-wu24 kevin-wu24 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

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 DescribeQuorum request
that races with the old leader's resignation.

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.

KafkaRaftClientTest#testCannotResignIfObserver:

leaderId and otherNodeId were drawn from two randomReplicaId()
calls, so the test's voter ids can collide and throw a
IllegalArgumentException. Other unit tests in the raft module only
call randomReplicaId() once so do not run into this.

Reviewers: Manikumar Reddy manikumar.reddy@gmail.com

…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>
@github-actions github-actions Bot added core Kafka Broker tests Test fixes (including flaky tests) kraft small Small PRs triage PRs from the community labels Aug 26, 2026
@omkreddy
omkreddy merged commit db8a092 into apache:trunk Aug 27, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-approved core Kafka Broker kraft small Small PRs tests Test fixes (including flaky tests) triage PRs from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants