You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/07/20 20:35:11 UTC

[camel] branch main updated: Fix flaky test on github ci (#10761)

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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 5df5b4719ac Fix flaky test on github ci (#10761)
5df5b4719ac is described below

commit 5df5b4719ac1eff16bd32a8bb9bdee39883c6280
Author: Federico Mariani <34...@users.noreply.github.com>
AuthorDate: Thu Jul 20 22:35:04 2023 +0200

    Fix flaky test on github ci (#10761)
---
 .../component/fhir/AbstractFhirTestSupport.java    |  4 ----
 .../component/jms/tx/JmsToJmsTransactedTest.java   |  7 +++++++
 .../lumberjack/LumberjackDisconnectionTest.java    |  2 +-
 .../camel/component/lumberjack/LumberjackUtil.java | 12 +++++++++--
 .../PulsarConsumerAcknowledgementIT.java           | 21 ++++---------------
 .../pulsar/integration/PulsarConsumerInIT.java     |  2 +-
 .../integration/PulsarConsumerInURIClientIT.java   |  2 +-
 .../integration/PulsarConsumerPatternInIT.java     |  6 +++---
 .../integration/PulsarCustomMessageReceiptIT.java  |  2 +-
 .../pulsar/integration/PulsarITSupport.java        |  2 +-
 .../smpp/integration/SmppTRXProducerIT.java        |  6 +++++-
 .../StompConsumerHeaderFilterStrategyTest.java     |  2 ++
 .../pulsar/services/PulsarServiceFactory.java      | 24 ++++++++++++++++++++++
 13 files changed, 60 insertions(+), 32 deletions(-)

diff --git a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/AbstractFhirTestSupport.java b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/AbstractFhirTestSupport.java
index 70800bd9c9b..fdfa2ecd2f7 100644
--- a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/AbstractFhirTestSupport.java
+++ b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/AbstractFhirTestSupport.java
@@ -50,10 +50,6 @@ public abstract class AbstractFhirTestSupport extends CamelTestSupport {
 
     @BeforeEach
     public void cleanFhirServerState() {
-        if (patientExists()) {
-            deletePatient();
-            Assumptions.assumeFalse(patientExists(), "The test cannot proceed: a patient should not exist");
-        }
         createPatient();
         Assumptions.assumeTrue(patientExists(), "The test cannot proceed: a patient was just created and it should exist");
     }
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.java
index 93c2729136f..2e460e9de27 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.jms.tx;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.jms.AbstractSpringJMSTestSupport;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.TestInstance;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -28,6 +29,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 @TestInstance(TestInstance.Lifecycle.PER_METHOD)
 public class JmsToJmsTransactedTest extends AbstractSpringJMSTestSupport {
 
+    @BeforeEach
+    public void beforeEach() {
+        service.shutdown();
+        service.initialize();
+    }
+
     @Override
     protected ClassPathXmlApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext("/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml");
diff --git a/components/camel-lumberjack/src/test/java/org/apache/camel/component/lumberjack/LumberjackDisconnectionTest.java b/components/camel-lumberjack/src/test/java/org/apache/camel/component/lumberjack/LumberjackDisconnectionTest.java
index d32d5985cfc..079599f94b0 100644
--- a/components/camel-lumberjack/src/test/java/org/apache/camel/component/lumberjack/LumberjackDisconnectionTest.java
+++ b/components/camel-lumberjack/src/test/java/org/apache/camel/component/lumberjack/LumberjackDisconnectionTest.java
@@ -61,7 +61,7 @@ public class LumberjackDisconnectionTest extends CamelTestSupport {
         List<Integer> windows = Arrays.asList(15, 10);
 
         // When sending messages
-        List<Integer> responses = LumberjackUtil.sendMessages(port, null, windows);
+        List<Integer> responses = LumberjackUtil.sendMessages(port, null, windows, false);
 
         // Then we should have the messages we're expecting
         mock.assertIsSatisfied();
diff --git a/components/camel-lumberjack/src/test/java/org/apache/camel/component/lumberjack/LumberjackUtil.java b/components/camel-lumberjack/src/test/java/org/apache/camel/component/lumberjack/LumberjackUtil.java
index b8363d5d159..32e14079b0c 100644
--- a/components/camel-lumberjack/src/test/java/org/apache/camel/component/lumberjack/LumberjackUtil.java
+++ b/components/camel-lumberjack/src/test/java/org/apache/camel/component/lumberjack/LumberjackUtil.java
@@ -21,7 +21,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.TimeUnit;
 
 import javax.net.ssl.SSLEngine;
 
@@ -37,6 +36,7 @@ import io.netty.channel.socket.nio.NioSocketChannel;
 import io.netty.handler.ssl.SslHandler;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.support.jsse.SSLContextParameters;
+import org.awaitility.Awaitility;
 
 import static io.netty.buffer.Unpooled.wrappedBuffer;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -47,6 +47,12 @@ final class LumberjackUtil {
 
     static List<Integer> sendMessages(int port, SSLContextParameters sslContextParameters, List<Integer> windows)
             throws InterruptedException {
+        return sendMessages(port, sslContextParameters, windows, true);
+    }
+
+    static List<Integer> sendMessages(
+            int port, SSLContextParameters sslContextParameters, List<Integer> windows, boolean waitForResult)
+            throws InterruptedException {
         NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup();
         try {
             // This list will hold the acknowledgment response sequence numbers
@@ -87,7 +93,9 @@ final class LumberjackUtil {
 
             // send 5 frame windows, without pausing
             windows.stream().forEach(window -> channel.writeAndFlush(readSample(String.format("io/window%s.bin", window))));
-            TimeUnit.MILLISECONDS.sleep(500);
+            if (waitForResult) {
+                Awaitility.await().until(() -> windows.size() == responses.size());
+            }
 
             channel.close();
 
diff --git a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerAcknowledgementIT.java b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerAcknowledgementIT.java
similarity index 94%
rename from components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerAcknowledgementIT.java
rename to components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerAcknowledgementIT.java
index 46ece0530f2..43489d21a66 100644
--- a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerAcknowledgementIT.java
+++ b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerAcknowledgementIT.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.pulsar;
+package org.apache.camel.component.pulsar.integration;
 
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
@@ -23,14 +23,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.camel.Endpoint;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.pulsar.PulsarComponent;
+import org.apache.camel.component.pulsar.PulsarMessageReceipt;
 import org.apache.camel.component.pulsar.utils.AutoConfiguration;
 import org.apache.camel.component.pulsar.utils.message.PulsarMessageHeaders;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.support.SimpleRegistry;
 import org.apache.camel.test.infra.common.TestUtils;
-import org.apache.camel.test.infra.pulsar.services.PulsarService;
-import org.apache.camel.test.infra.pulsar.services.PulsarServiceFactory;
-import org.apache.camel.test.junit5.CamelTestSupport;
 import org.apache.pulsar.client.api.Producer;
 import org.apache.pulsar.client.api.PulsarClient;
 import org.apache.pulsar.client.api.PulsarClientException;
@@ -39,14 +38,10 @@ import org.apache.pulsar.client.impl.ClientBuilderImpl;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class PulsarConsumerAcknowledgementIT extends CamelTestSupport {
-
-    @RegisterExtension
-    static PulsarService service = PulsarServiceFactory.createService();
+public class PulsarConsumerAcknowledgementIT extends PulsarITSupport {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(PulsarConsumerAcknowledgementIT.class);
     private static final String TOPIC_URI = "persistent://public/default/camel-topic-";
@@ -58,14 +53,6 @@ public class PulsarConsumerAcknowledgementIT extends CamelTestSupport {
 
     private Producer<String> producer;
 
-    public String getPulsarBrokerUrl() {
-        return service.getPulsarBrokerUrl();
-    }
-
-    public String getPulsarAdminUrl() {
-        return service.getPulsarAdminUrl();
-    }
-
     @BeforeEach
     public void setup() throws Exception {
         context.removeRoute("myRoute");
diff --git a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerInIT.java b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerInIT.java
index 5f826684109..9233d98c994 100644
--- a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerInIT.java
+++ b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerInIT.java
@@ -41,7 +41,7 @@ public class PulsarConsumerInIT extends PulsarITSupport {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(PulsarConsumerInIT.class);
 
-    private static final String TOPIC_URI = "persistent://public/default/camel-topic";
+    private static final String TOPIC_URI = "persistent://public/default/camel-topic/PulsarConsumerInIT";
     private static final String PRODUCER = "camel-producer-1";
 
     @EndpointInject("pulsar:" + TOPIC_URI + "?numberOfConsumers=1&subscriptionType=Exclusive"
diff --git a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerInURIClientIT.java b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerInURIClientIT.java
index a776b7f7307..175e90a03bf 100644
--- a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerInURIClientIT.java
+++ b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerInURIClientIT.java
@@ -36,7 +36,7 @@ public class PulsarConsumerInURIClientIT extends PulsarITSupport {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(PulsarConsumerInURIClientIT.class);
 
-    private static final String TOPIC_URI = "persistent://public/default/camel-topic";
+    private static final String TOPIC_URI = "persistent://public/default/camel-topic/PulsarConsumerInURIClientIT";
     private static final String PRODUCER = "camel-producer-1";
     private static final String URI_ENDPOINT = "pulsar:" + TOPIC_URI + "?numberOfConsumers=1&subscriptionType=Exclusive"
                                                + "&subscriptionName=camel-subscription&consumerQueueSize=1&consumerName=camel-consumer&serviceUrl="
diff --git a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerPatternInIT.java b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerPatternInIT.java
index d6d9441b154..9f298cd2835 100644
--- a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerPatternInIT.java
+++ b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerPatternInIT.java
@@ -41,9 +41,9 @@ public class PulsarConsumerPatternInIT extends PulsarITSupport {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(PulsarConsumerPatternInIT.class);
 
-    private static final String TOPIC_URI = "persistent://public/default/camel-foo";
-    private static final String TOPIC_TWO_URI = "persistent://public/default/camel-bar";
-    private static final String TOPIC_PATTERN_URI = "persistent://public/default/camel-.*";
+    private static final String TOPIC_URI = "persistent://public/default/PulsarConsumerPatternInIT/camel-foo";
+    private static final String TOPIC_TWO_URI = "persistent://public/default/PulsarConsumerPatternInIT/camel-bar";
+    private static final String TOPIC_PATTERN_URI = "persistent://public/default/PulsarConsumerPatternInIT/camel-.*";
     private static final String PRODUCER = "camel-producer-1";
 
     @EndpointInject("pulsar:" + TOPIC_PATTERN_URI + "?topicsPattern=true"
diff --git a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarCustomMessageReceiptIT.java b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarCustomMessageReceiptIT.java
index 67834825da9..410a1c62300 100644
--- a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarCustomMessageReceiptIT.java
+++ b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarCustomMessageReceiptIT.java
@@ -50,7 +50,7 @@ public class PulsarCustomMessageReceiptIT extends PulsarITSupport {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(PulsarCustomMessageReceiptIT.class);
 
-    private static final String TOPIC_URI = "persistent://public/default/camel-topic";
+    private static final String TOPIC_URI = "persistent://public/default/camel-topic/PulsarCustomMessageReceiptIT";
     private static final String PRODUCER = "camel-producer-1";
 
     public PulsarMessageReceiptFactory mockPulsarMessageReceiptFactory = mock(PulsarMessageReceiptFactory.class);
diff --git a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarITSupport.java b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarITSupport.java
index d5b4d8fcd97..1187d1a83cb 100644
--- a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarITSupport.java
+++ b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarITSupport.java
@@ -23,7 +23,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 
 public class PulsarITSupport extends CamelTestSupport {
     @RegisterExtension
-    static PulsarService service = PulsarServiceFactory.createService();
+    static PulsarService service = PulsarServiceFactory.createSingletonService();
 
     public String getPulsarBrokerUrl() {
         return service.getPulsarBrokerUrl();
diff --git a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppTRXProducerIT.java b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppTRXProducerIT.java
index b2662b8659a..fbe5a1e39f0 100644
--- a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppTRXProducerIT.java
+++ b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppTRXProducerIT.java
@@ -138,7 +138,11 @@ class SmppTRXProducerIT extends CamelTestSupport {
                             "&messageReceiverRouteId=testMessageReceiverRouteId");
 
                 from("direct:messageReceiver").id("testMessageReceiverRouteId")
-                        .to("mock:result");
+                        .choice()
+                            .when(simple("${header.CamelSmppSourceAddr} == '555'"))
+                                .to("mock:garbage") // SMPPServerSimulator.run send a test message, ignore it
+                        .otherwise()
+                            .to("mock:result");
 
                 from("direct:messageReceiver2").id("testMessageReceiverRouteId2")
                         .to("mock:result2");
diff --git a/components/camel-stomp/src/test/java/org/apache/camel/component/stomp/StompConsumerHeaderFilterStrategyTest.java b/components/camel-stomp/src/test/java/org/apache/camel/component/stomp/StompConsumerHeaderFilterStrategyTest.java
index 614997e2126..313aebb9f24 100644
--- a/components/camel-stomp/src/test/java/org/apache/camel/component/stomp/StompConsumerHeaderFilterStrategyTest.java
+++ b/components/camel-stomp/src/test/java/org/apache/camel/component/stomp/StompConsumerHeaderFilterStrategyTest.java
@@ -26,6 +26,7 @@ import org.fusesource.stomp.client.BlockingConnection;
 import org.fusesource.stomp.client.Stomp;
 import org.fusesource.stomp.codec.StompFrame;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
 import org.testcontainers.shaded.org.awaitility.Awaitility;
 
 import static org.fusesource.hawtbuf.UTF8Buffer.utf8;
@@ -33,6 +34,7 @@ import static org.fusesource.stomp.client.Constants.DESTINATION;
 import static org.fusesource.stomp.client.Constants.MESSAGE_ID;
 import static org.fusesource.stomp.client.Constants.SEND;
 
+@DisabledIfSystemProperty(named = "ci.env.name", matches = "github.com", disabledReason = "Flaky on Github CI")
 public class StompConsumerHeaderFilterStrategyTest extends StompBaseTest {
 
     @BindToRegistry("customHeaderFilterStrategy")
diff --git a/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarServiceFactory.java b/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarServiceFactory.java
index a4b49a42352..1f548b0d2a6 100644
--- a/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarServiceFactory.java
+++ b/test-infra/camel-test-infra-pulsar/src/test/java/org/apache/camel/test/infra/pulsar/services/PulsarServiceFactory.java
@@ -17,12 +17,30 @@
 package org.apache.camel.test.infra.pulsar.services;
 
 import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
+import org.apache.camel.test.infra.common.services.SingletonService;
 
 public final class PulsarServiceFactory {
     private PulsarServiceFactory() {
 
     }
 
+    public static class SingletonPulsarService extends SingletonService<PulsarService> implements PulsarService {
+
+        public SingletonPulsarService(PulsarService service, String name) {
+            super(service, name);
+        }
+
+        @Override
+        public String getPulsarAdminUrl() {
+            return getService().getPulsarAdminUrl();
+        }
+
+        @Override
+        public String getPulsarBrokerUrl() {
+            return getService().getPulsarBrokerUrl();
+        }
+    }
+
     public static SimpleTestServiceBuilder<PulsarService> builder() {
         return new SimpleTestServiceBuilder<>("pulsar");
     }
@@ -33,4 +51,10 @@ public final class PulsarServiceFactory {
                 .addRemoteMapping(PulsarRemoteService::new)
                 .build();
     }
+
+    public static PulsarService createSingletonService() {
+        return builder()
+                .addLocalMapping(() -> new SingletonPulsarService(new PulsarLocalContainerService(), "pulsar"))
+                .build();
+    }
 }