Skip to content

Commit b3641f0

Browse files
authored
[fix][test]Fix flaky test testTopicUnloadAfterSessionRebuild (#23852)
1 parent 492a869 commit b3641f0

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Optional;
2727
import java.util.concurrent.CompletableFuture;
2828
import java.util.concurrent.TimeUnit;
29+
import java.util.stream.Collectors;
2930
import lombok.extern.slf4j.Slf4j;
3031
import org.apache.pulsar.broker.BrokerTestUtil;
3132
import org.apache.pulsar.broker.ServiceConfiguration;
@@ -39,7 +40,7 @@
3940
import org.testng.annotations.Test;
4041

4142
@Slf4j
42-
@Test(groups = "flaky")
43+
@Test(groups = "broker")
4344
public class ZkSessionExpireTest extends NetworkErrorTestBase {
4445

4546
private java.util.function.Consumer<ServiceConfiguration> settings;
@@ -94,7 +95,7 @@ public void testTopicUnloadAfterSessionRebuild(boolean enableSystemTopic, Class
9495
admin2.namespaces().unload(defaultNamespace);
9596

9697
// Confirm all brokers registered.
97-
Awaitility.await().untilAsserted(() -> {
98+
Awaitility.await().atMost(Duration.ofSeconds(20)).untilAsserted(() -> {
9899
assertEquals(getAvailableBrokers(pulsar1).size(), 2);
99100
assertEquals(getAvailableBrokers(pulsar2).size(), 2);
100101
});
@@ -160,7 +161,21 @@ public void testTopicUnloadAfterSessionRebuild(boolean enableSystemTopic, Class
160161
// Verify: the topic on broker-2 is fine.
161162
Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> {
162163
CompletableFuture<Optional<Topic>> future = pulsar1.getBrokerService().getTopic(topicName, false);
163-
assertTrue(future == null || future.isCompletedExceptionally());
164+
log.info("broker 1 topics {}", pulsar1.getBrokerService().getTopics().keySet());
165+
log.info("broker 2 topics {}", pulsar2.getBrokerService().getTopics().keySet());
166+
log.info("broker 1 bundles {}", pulsar1.getNamespaceService().getOwnershipCache().getOwnedBundles()
167+
.keySet().stream().map(k -> k.getNamespaceObject().toString() + "/" + k.getBundleRange())
168+
.filter(s -> s.contains(defaultNamespace)).collect(Collectors.toList()));
169+
log.info("broker 2 bundles {}", pulsar2.getNamespaceService().getOwnershipCache().getOwnedBundles()
170+
.keySet().stream().map(k -> k.getNamespaceObject().toString() + "/" + k.getBundleRange())
171+
.filter(s -> s.contains(defaultNamespace)).collect(Collectors.toList()));
172+
log.info("future: {}, isDone: {}, isCompletedExceptionally: {}",
173+
future, future == null ? "null" : future.isDone(),
174+
future, future == null ? "null" : future.isCompletedExceptionally());
175+
assertTrue(future == null
176+
|| !pulsar1.getBrokerService().getTopics().containsKey(topicName)
177+
|| (future.isDone() && !future.isCompletedExceptionally() && future.get().isEmpty())
178+
|| future.isCompletedExceptionally());
164179
});
165180
Topic broker2Topic3 = pulsar2.getBrokerService().getTopic(topicName, false).join().get();
166181
assertNotNull(broker2Topic3);

0 commit comments

Comments
 (0)