You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2024/03/18 19:25:54 UTC

(camel) 01/08: CAMEL-20477: try to fix flakiness on AsyncJmsProducerTest

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

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

commit d4065543906245eef1c9a9aad2f0ac2dc588f4ea
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Mar 18 09:37:42 2024 +0100

    CAMEL-20477: try to fix flakiness on AsyncJmsProducerTest
    
    - Setup mocks in advance
    - Use a transient extension to allow repeating the test and ensure a clean test context
    - Repeat the test more often
---
 .../component/jms/async/AsyncJmsProducerTest.java  | 31 +++++++++++++++-------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/async/AsyncJmsProducerTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/async/AsyncJmsProducerTest.java
index 7ff9c58d824..50ad07105b4 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/async/AsyncJmsProducerTest.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/async/AsyncJmsProducerTest.java
@@ -23,10 +23,10 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.jms.AbstractJMSTest;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.infra.core.CamelContextExtension;
-import org.apache.camel.test.infra.core.DefaultCamelContextExtension;
+import org.apache.camel.test.infra.core.TransientCamelContextExtension;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Order;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.RepeatedTest;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -36,23 +36,36 @@ public class AsyncJmsProducerTest extends AbstractJMSTest {
 
     @Order(2)
     @RegisterExtension
-    public static CamelContextExtension camelContextExtension = new DefaultCamelContextExtension();
+    public static CamelContextExtension camelContextExtension = new TransientCamelContextExtension();
     private static String beforeThreadName;
     private static String afterThreadName;
     protected CamelContext context;
     protected ProducerTemplate template;
     protected ConsumerTemplate consumer;
 
-    @Test
-    public void testAsyncEndpoint() throws Exception {
-        getMockEndpoint("mock:before").expectedBodiesReceived("Hello Camel");
-        getMockEndpoint("mock:after").expectedBodiesReceived("Bye Camel");
-        getMockEndpoint("mock:result").expectedBodiesReceived("Bye Camel");
+    private MockEndpoint mockBefore;
+    private MockEndpoint mockAfter;
+    private MockEndpoint mockResult;
+
+    @BeforeEach
+    void setupMocks() {
+        mockBefore = getMockEndpoint("mock:before");
+        mockAfter = getMockEndpoint("mock:after");
+        mockResult = getMockEndpoint("mock:result");
 
+        mockBefore.expectedBodiesReceived("Hello Camel");
+        mockAfter.expectedBodiesReceived("Bye Camel");
+        mockResult.expectedBodiesReceived("Bye Camel");
+    }
+
+    @RepeatedTest(5)
+    public void testAsyncEndpoint() throws Exception {
         String reply = template.requestBody("direct:start", "Hello Camel", String.class);
         assertEquals("Bye Camel", reply);
 
-        MockEndpoint.assertIsSatisfied(context);
+        mockBefore.assertIsSatisfied();
+        mockAfter.assertIsSatisfied();
+        mockResult.assertIsSatisfied();
 
         assertFalse(beforeThreadName.equalsIgnoreCase(afterThreadName), "Should use different threads");
     }