Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][flaky-test] PersistentFailoverE2ETest.testSimpleConsumerEventsWithPartition #16493

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.pulsar.common.api.proto.CommandSubscribe.SubType;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.util.FutureUtil;
import org.awaitility.Awaitility;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
Expand Down Expand Up @@ -184,8 +185,9 @@ public void testSimpleConsumerEventsWithoutPartition() throws Exception {

rolloverPerIntervalStats();

assertEquals(subRef.getNumberOfEntriesInBacklog(false), numMsgs);
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
Awaitility.await().untilAsserted(() -> {
assertEquals(subRef.getNumberOfEntriesInBacklog(false), numMsgs);
});

// 3. consumer1 should have all the messages while consumer2 should have no messages
Message<byte[]> msg = null;
Expand All @@ -200,8 +202,9 @@ public void testSimpleConsumerEventsWithoutPartition() throws Exception {
rolloverPerIntervalStats();

// 4. messages deleted on individual acks
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
assertEquals(subRef.getNumberOfEntriesInBacklog(false), 0);
Awaitility.await().untilAsserted(() -> {
assertEquals(subRef.getNumberOfEntriesInBacklog(false), 0);
});

for (int i = 0; i < numMsgs; i++) {
String message = "my-message-" + i;
Expand All @@ -224,10 +227,12 @@ public void testSimpleConsumerEventsWithoutPartition() throws Exception {
// do not ack
}
consumer1.close();
Thread.sleep(CONSUMER_ADD_OR_REMOVE_WAIT_TIME);

verifyConsumerActive(listener2, -1);
verifyConsumerNotReceiveAnyStateChanges(listener1);
Awaitility.await().untilAsserted(() -> {
verifyConsumerActive(listener2, -1);
verifyConsumerNotReceiveAnyStateChanges(listener1);
});

for (int i = 5; i < numMsgs; i++) {
msg = consumer2.receive(1, TimeUnit.SECONDS);
Assert.assertNotNull(msg);
Expand All @@ -237,8 +242,10 @@ public void testSimpleConsumerEventsWithoutPartition() throws Exception {
Assert.assertNull(consumer2.receive(100, TimeUnit.MILLISECONDS));

rolloverPerIntervalStats();
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
assertEquals(subRef.getNumberOfEntriesInBacklog(false), 0);
Awaitility.await().untilAsserted(() -> {
assertEquals(subRef.getNumberOfEntriesInBacklog(false), 0);

});

// 8. unsubscribe not allowed if multiple consumers connected
try {
Expand All @@ -257,9 +264,9 @@ public void testSimpleConsumerEventsWithoutPartition() throws Exception {
fail("Should not fail", e);
}

Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
subRef = topicRef.getSubscription(subName);
assertNull(subRef);
Awaitility.await().untilAsserted(() -> {
assertNull(topicRef.getSubscription(subName));
});

producer.close();
consumer2.close();
Expand Down