You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by si...@apache.org on 2018/09/26 17:41:44 UTC

[pulsar] branch master updated: Fixed flaky test BatchMessageTest.testBatchAndNonBatchCumulativeAcks (#2661)

This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 3f8ad30  Fixed flaky test BatchMessageTest.testBatchAndNonBatchCumulativeAcks (#2661)
3f8ad30 is described below

commit 3f8ad30b873429ed5feafecd728b73730725430a
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Wed Sep 26 13:41:38 2018 -0400

    Fixed flaky test BatchMessageTest.testBatchAndNonBatchCumulativeAcks (#2661)
    
    ### Motivation
    
    Fixed flaky test :
    
    ```
    Skip Message
    
    expected [0] but found [4]
    
    Standard Output
    
    Created annotation listener
    13:24:36.970 [main:org.apache.pulsar.broker.PulsarService@319] INFO  org.apache.pulsar.broker.PulsarService - Starting Pulsar Broker service; version: '2.2.0.0-SNAPSHOT'
    13:24:36.982 [main:org.apache.pulsar.broker.PulsarService@320] INFO  org.apache.pulsar.broker.PulsarService - Git Revision b4b348da6dade88fbf08bc8f49e28f280455d985
    13:24:36.984 [main:org.apache.pulsar.broker.PulsarService@321] INFO  org.apache.pulsar.broker.PulsarService - Built by  <> on asf902.gq1.y
    ...[truncated 42534 chars]...
     position3:28:-1:4 data [B@6507f56b
    13:24:43.543 [TestNG-method=testBatchAndNonBatchCumulativeAcks-1:org.apache.pulsar.broker.service.BatchMessageTest@563] INFO  org.apache.pulsar.broker.service.BatchMessageTest - [bnb-sub-1] got message position3:29:-1 data [B@4ebac723
    13:24:43.543 [TestNG-method=testBatchAndNonBatchCumulativeAcks-1:org.apache.pulsar.broker.service.BatchMessageTest@569] INFO  org.apache.pulsar.broker.service.BatchMessageTest - [bnb-sub-1] did cumulative ack on position3:29:-1
    ```
    
    Core issue is that the acks are by default grouped with 100ms delay. The `Thread.sleep(100)` was not enough to cover for that.
    
    ### Modifications
    
    Removed ack grouping for this test.
---
 .../org/apache/pulsar/broker/service/BatchMessageTest.java   | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageTest.java
index 1db8ed8..516197d 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageTest.java
@@ -22,6 +22,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
+import static org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.retryStrategically;
 
 import com.google.common.collect.Lists;
 
@@ -554,7 +555,11 @@ public class BatchMessageTest extends BrokerTestBase {
         assertTrue(topic.getProducers().values().iterator().next().getStats().msgRateIn > 0.0);
         assertEquals(topic.getSubscription(subscriptionName).getNumberOfEntriesInBacklog(),
                 (numMsgs / 2) / numMsgsInBatch + numMsgs / 2);
-        consumer = pulsarClient.newConsumer().topic(topicName).subscriptionName(subscriptionName).subscribe();
+        consumer = pulsarClient.newConsumer()
+                    .topic(topicName)
+                    .subscriptionName(subscriptionName)
+                    .acknowledgmentGroupTime(0, TimeUnit.SECONDS)
+                    .subscribe();
 
         Message<byte[]> lastunackedMsg = null;
         for (int i = 0; i < numMsgs; i++) {
@@ -572,8 +577,9 @@ public class BatchMessageTest extends BrokerTestBase {
         if (lastunackedMsg != null) {
             consumer.acknowledgeCumulative(lastunackedMsg);
         }
-        Thread.sleep(100);
-        assertEquals(topic.getSubscription(subscriptionName).getNumberOfEntriesInBacklog(), 0);
+
+        retryStrategically(t -> topic.getSubscription(subscriptionName).getNumberOfEntriesInBacklog() == 0, 100, 100);
+
         consumer.close();
         producer.close();
         noBatchProducer.close();