Skip to content

Commit 0417705

Browse files
authored
[fix][test] Fix flaky LeaderElectionServiceTest and PersistentDispatcherFailoverConsumerTest (#25498)
1 parent 381fa13 commit 0417705

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LeaderElectionServiceTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@ public void anErrorShouldBeThrowBeforeLeaderElected() throws PulsarServerExcepti
8080
config.setMetadataStoreUrl("zk:127.0.0.1:" + bkEnsemble.getZookeeperPort());
8181
@Cleanup
8282
PulsarService pulsar = spyWithClassAndConstructorArgs(MockPulsarService.class, config);
83-
pulsar.start();
8483

8584
// mock pulsar.getLeaderElectionService() in a thread safe way
85+
// This must be set up before start() to avoid UnfinishedStubbingException
86+
// caused by background threads interacting with the spy during stubbing setup.
8687
AtomicReference<LeaderElectionService> leaderElectionServiceReference = new AtomicReference<>();
8788
Mockito.doAnswer(invocation -> leaderElectionServiceReference.get())
8889
.when(pulsar).getLeaderElectionService();
8990

91+
pulsar.start();
92+
9093
// broker and webService is started, but leaderElectionService not ready
9194
final String tenant = "elect";
9295
final String namespace = "ns";

pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentDispatcherFailoverConsumerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public void setup() throws Exception {
112112
svcConfig.setClusterName("pulsar-cluster");
113113
svcConfig.setSystemTopicEnabled(false);
114114
svcConfig.setTopicLevelPoliciesEnabled(false);
115+
svcConfig.setActiveConsumerFailoverDelayTimeMillis(0);
115116
pulsarTestContext = PulsarTestContext.builderForNonStartableContext()
116117
.config(svcConfig)
117118
.spyByDefault()

0 commit comments

Comments
 (0)