Skip to content

Commit

Permalink
[fix][test] Fix flaky test ReplicatorTest.testDoNotReplicateSystemTop…
Browse files Browse the repository at this point in the history
…ic (apache#19319)
  • Loading branch information
lhotari authored Jan 24, 2023
1 parent b880b1d commit 689a33f
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,7 @@ public void testDoNotReplicateSystemTopic() throws Exception {
admin1.namespaces().createNamespace(namespace, Sets.newHashSet("r1", "r2", "r3"));
String topic = TopicName.get("persistent", NamespaceName.get(namespace),
"testDoesNotReplicateSystemTopic").toString();
admin1.topics().createNonPartitionedTopic(topic);
String systemTopic = TopicName.get("persistent", NamespaceName.get(namespace),
SystemTopicNames.TRANSACTION_BUFFER_SNAPSHOT).toString();

Expand All @@ -1496,7 +1497,6 @@ public void testDoNotReplicateSystemTopic() throws Exception {
.subscriptionName("sub-rep")
.subscribe();

admin1.topics().createNonPartitionedTopic(topic);
// Replicator will not replicate System Topic other than topic policies
initTransaction(2, admin1, pulsar1.getBrokerServiceUrl(), pulsar1);
@Cleanup
Expand All @@ -1520,13 +1520,16 @@ public void testDoNotReplicateSystemTopic() throws Exception {
assertNull(consumerFromR2.receive(5, TimeUnit.SECONDS));
transaction.commit();

Awaitility.await().untilAsserted(() -> {
Assert.assertEquals(admin1.topics().getStats(systemTopic).getReplication().size(), 0);
Assert.assertEquals(admin2.topics().getStats(systemTopic).getReplication().size(), 0);
Assert.assertEquals(admin3.topics().getStats(systemTopic).getReplication().size(), 0);
});
Assert.assertEquals(consumerFromR2.receive(5, TimeUnit.SECONDS).getValue(),
"1".getBytes(StandardCharsets.UTF_8));

// wait extra 500ms before evaluating stats for the system topics
Thread.sleep(500L);

Assert.assertEquals(admin1.topics().getStats(systemTopic).getReplication().size(), 0);
Assert.assertEquals(admin2.topics().getStats(systemTopic).getReplication().size(), 0);
Assert.assertEquals(admin3.topics().getStats(systemTopic).getReplication().size(), 0);

cleanup();
setup();
}
Expand Down

0 comments on commit 689a33f

Please sign in to comment.