Skip to content

Commit

Permalink
Fixed flaky test AdminApiTest2.testBacklogNoDelayed (apache#7562)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlimat authored Jul 16, 2020
1 parent eb2ca72 commit 19d27ec
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.core.Response.Status;

Expand Down Expand Up @@ -982,6 +983,7 @@ public void testConsumerStatsLastTimestamp() throws PulsarClientException, Pulsa
Consumer<byte[]> consumer = client.newConsumer().topic(topic)
.subscriptionName(subscribeName)
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
.acknowledgmentGroupTime(0, TimeUnit.SECONDS)
.subscribe();
Message<byte[]> message = consumer.receive();

Expand Down Expand Up @@ -1077,6 +1079,7 @@ public void testPreciseBacklog() throws PulsarClientException, PulsarAdminExcept
Consumer<byte[]> consumer = client.newConsumer()
.topic(topic)
.subscriptionName(subName)
.acknowledgmentGroupTime(0, TimeUnit.SECONDS)
.subscribe();

@Cleanup
Expand Down Expand Up @@ -1114,7 +1117,7 @@ public void testPreciseBacklog() throws PulsarClientException, PulsarAdminExcept

@Test(timeOut = 30000)
public void testBacklogNoDelayed() throws PulsarClientException, PulsarAdminException, InterruptedException {
final String topic = "persistent://prop-xyz/ns1/precise-back-log-no-delayed";
final String topic = "persistent://prop-xyz/ns1/precise-back-log-no-delayed-" + UUID.randomUUID().toString();
final String subName = "sub-name";

@Cleanup
Expand All @@ -1125,6 +1128,7 @@ public void testBacklogNoDelayed() throws PulsarClientException, PulsarAdminExce
.topic(topic)
.subscriptionName(subName)
.subscriptionType(SubscriptionType.Shared)
.acknowledgmentGroupTime(0, TimeUnit.SECONDS)
.subscribe();

@Cleanup
Expand All @@ -1144,6 +1148,11 @@ public void testBacklogNoDelayed() throws PulsarClientException, PulsarAdminExce
}
}

// Wait for messages to be tracked for delayed delivery. This happens
// on the consumer dispatch side, so when the send() is complete we're
// not yet guaranteed to see the stats updated.
Thread.sleep(500);

TopicStats topicStats = admin.topics().getStats(topic, true);
assertEquals(topicStats.subscriptions.get(subName).msgBacklog, 10);
assertEquals(topicStats.subscriptions.get(subName).msgBacklogNoDelayed, 5);
Expand Down Expand Up @@ -1171,6 +1180,7 @@ public void testPreciseBacklogForPartitionedTopic() throws PulsarClientException
Consumer<byte[]> consumer = client.newConsumer()
.topic(topic)
.subscriptionName(subName)
.acknowledgmentGroupTime(0, TimeUnit.SECONDS)
.subscribe();

@Cleanup
Expand Down Expand Up @@ -1212,6 +1222,7 @@ public void testBacklogNoDelayedForPartitionedTopic() throws PulsarClientExcepti
.topic(topic)
.subscriptionName(subName)
.subscriptionType(SubscriptionType.Shared)
.acknowledgmentGroupTime(0, TimeUnit.SECONDS)
.subscribe();

@Cleanup
Expand Down

0 comments on commit 19d27ec

Please sign in to comment.