Skip to content

Commit

Permalink
KAFKA-18844: Fix flaky QuorumControllerTest.testBalancePartitionLeade…
Browse files Browse the repository at this point in the history
…rs()

Signed-off-by: PoAn Yang <[email protected]>
  • Loading branch information
FrankYang0529 committed Feb 22, 2025
1 parent 14ebec3 commit 2544030
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public void testElrEnabledByDefault() throws Throwable {
)).
build()
) {
controlEnv.activeController(true);
controlEnv.activeController();
assertTrue(controlEnv.activeController().configurationControl().clusterConfig().containsKey(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ private QuorumControllerTestEnv(
}

QuorumController activeController() throws InterruptedException {
return activeController(false);
}

QuorumController activeController(boolean waitForActivation) throws InterruptedException {
AtomicReference<QuorumController> value = new AtomicReference<>(null);
TestUtils.retryOnExceptionWithTimeout(20000, 3, () -> {
LeaderAndEpoch leader = logEnv.leaderAndEpoch();
Expand All @@ -155,16 +151,14 @@ QuorumController activeController(boolean waitForActivation) throws InterruptedE
}
});

if (waitForActivation) {
try {
// ControllerActivation happens after curClaimEpoch is set, so we need to put something on
// the end of the queue and wait for it to complete before returning the active controller.
value.get()
.appendReadEvent("wait for activation", OptionalLong.empty(), () -> null)
.get(20000, TimeUnit.MILLISECONDS);
} catch (Throwable t) {
throw new RuntimeException("Failed while waiting for controller activation", t);
}
try {
// ControllerActivation happens after curClaimEpoch is set, so we need to put something on
// the end of the queue and wait for it to complete before returning the active controller.
value.get()
.appendReadEvent("wait for activation", OptionalLong.empty(), () -> null)
.get(20000, TimeUnit.MILLISECONDS);
} catch (Throwable t) {
throw new RuntimeException("Failed while waiting for controller activation", t);
}

return value.get();
Expand Down

0 comments on commit 2544030

Please sign in to comment.