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 47214ce2b421cf6fff6b0622158fc53c38bf5785
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Fri Jul 14 09:16:05 2023 +0200

    (chores) camel-core: multicast test fixes and cleanups
    
    - adjust timeouts for less flakiness on slower hosts
    - send the test kick-off message earlier
    - skip running the test on very slow hosts than take too long to start the 
context
    - run in isolation for more stability in hosts with smaller core counts
    - improve coordination between different routes and the assertion time
---
 .../MulticastParallelLastTimeoutTest.java          | 25 ++++++++++++++++++----
 .../processor/MulticastParallelTimeout2Test.java   | 25 ++++++++++++++++++----
 .../processor/MulticastParallelTimeout3Test.java   | 25 ++++++++++++++++++----
 3 files changed, 63 insertions(+), 12 deletions(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelLastTimeoutTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelLastTimeoutTest.java
index 2dfec034cb9..7d150bf9a3e 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelLastTimeoutTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelLastTimeoutTest.java
@@ -16,22 +16,39 @@
  */
 package org.apache.camel.processor;
 
+import java.util.concurrent.Phaser;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.AggregationStrategy;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.parallel.Isolated;
 
+@Isolated
+@Timeout(60)
 public class MulticastParallelLastTimeoutTest extends ContextTestSupport {
 
+    private final Phaser phaser = new Phaser(3);
+
+    @BeforeEach
+    void sendEarly() {
+        Assumptions.assumeTrue(context.isStarted(), "The test cannot be run 
because the context is not started");
+        template.sendBody("direct:start", "Hello");
+    }
+
     @Test
     public void testMulticastParallelLastTimeout() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         // C will timeout so we only get A and B
         mock.expectedBodiesReceived("AB");
 
-        template.sendBody("direct:start", "Hello");
+        phaser.awaitAdvanceInterruptibly(0, 5000, TimeUnit.SECONDS);
 
         assertMockEndpointsSatisfied();
     }
@@ -55,11 +72,11 @@ public class MulticastParallelLastTimeoutTest extends 
ContextTestSupport {
                         // use end to indicate end of multicast route
                         .end().to("mock:result");
 
-                from("direct:a").delay(500).setBody(constant("A"));
+                from("direct:a").process(e -> 
phaser.arriveAndAwaitAdvance()).delay(500).setBody(constant("A"));
 
-                from("direct:b").setBody(constant("B"));
+                from("direct:b").process(e -> 
phaser.arriveAndAwaitAdvance()).setBody(constant("B"));
 
-                from("direct:c").delay(3000).setBody(constant("C"));
+                from("direct:c").process(e -> 
phaser.arriveAndAwaitAdvance()).delay(3000).setBody(constant("C"));
             }
         };
     }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout2Test.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout2Test.java
index dcfc132288f..501a601aae1 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout2Test.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout2Test.java
@@ -16,15 +16,32 @@
  */
 package org.apache.camel.processor;
 
+import java.util.concurrent.Phaser;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.AggregationStrategy;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.parallel.Isolated;
 
+@Isolated
+@Timeout(60)
 public class MulticastParallelTimeout2Test extends ContextTestSupport {
 
+    private final Phaser phaser = new Phaser(3);
+
+    @BeforeEach
+    void sendEarly() {
+        Assumptions.assumeTrue(context.isStarted(), "The test cannot be run 
because the context is not started");
+        template.sendBody("direct:start", "Hello");
+    }
+
     @Test
     public void testMulticastParallelTimeout() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
@@ -35,7 +52,7 @@ public class MulticastParallelTimeout2Test extends 
ContextTestSupport {
         getMockEndpoint("mock:B").expectedMessageCount(0);
         getMockEndpoint("mock:C").expectedMessageCount(1);
 
-        template.sendBody("direct:start", "Hello");
+        phaser.awaitAdvanceInterruptibly(0, 5000, TimeUnit.SECONDS);
 
         assertMockEndpointsSatisfied();
     }
@@ -60,11 +77,11 @@ public class MulticastParallelTimeout2Test extends 
ContextTestSupport {
                         // use end to indicate end of multicast route
                         .end().to("mock:result");
 
-                from("direct:a").to("mock:A").setBody(constant("A"));
+                from("direct:a").process(e -> 
phaser.arriveAndAwaitAdvance()).to("mock:A").setBody(constant("A"));
 
-                
from("direct:b").delay(1000).to("mock:B").setBody(constant("B"));
+                from("direct:b").process(e -> 
phaser.arriveAndAwaitAdvance()).delay(1000).to("mock:B").setBody(constant("B"));
 
-                from("direct:c").to("mock:C").setBody(constant("C"));
+                from("direct:c").process(e -> 
phaser.arriveAndAwaitAdvance()).to("mock:C").setBody(constant("C"));
                 // END SNIPPET: e1
             }
         };
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout3Test.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout3Test.java
index 53c6dfaeb82..768deb1826a 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout3Test.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelTimeout3Test.java
@@ -16,15 +16,32 @@
  */
 package org.apache.camel.processor;
 
+import java.util.concurrent.Phaser;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.AggregationStrategy;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.parallel.Isolated;
 
+@Isolated
+@Timeout(60)
 public class MulticastParallelTimeout3Test extends ContextTestSupport {
 
+    private final Phaser phaser = new Phaser(3);
+
+    @BeforeEach
+    void sendEarly() {
+        Assumptions.assumeTrue(context.isStarted(), "The test cannot be run 
because the context is not started");
+        template.sendBody("direct:start", "Hello");
+    }
+
     @Test
     public void testMulticastParallelTimeout() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
@@ -35,7 +52,7 @@ public class MulticastParallelTimeout3Test extends 
ContextTestSupport {
         getMockEndpoint("mock:B").expectedMessageCount(1);
         getMockEndpoint("mock:C").expectedMessageCount(0);
 
-        template.sendBody("direct:start", "Hello");
+        phaser.awaitAdvanceInterruptibly(0, 5000, TimeUnit.SECONDS);
 
         assertMockEndpointsSatisfied();
     }
@@ -60,11 +77,11 @@ public class MulticastParallelTimeout3Test extends 
ContextTestSupport {
                         // use end to indicate end of multicast route
                         .end().to("mock:result");
 
-                from("direct:a").to("mock:A").setBody(constant("A"));
+                from("direct:a").process(e -> 
phaser.arriveAndAwaitAdvance()).to("mock:A").setBody(constant("A"));
 
-                from("direct:b").to("mock:B").setBody(constant("B"));
+                from("direct:b").process(e -> 
phaser.arriveAndAwaitAdvance()).to("mock:B").setBody(constant("B"));
 
-                
from("direct:c").delay(1000).to("mock:C").setBody(constant("C"));
+                from("direct:c").process(e -> 
phaser.arriveAndAwaitAdvance()).delay(1000).to("mock:C").setBody(constant("C"));
                 // END SNIPPET: e1
             }
         };

Reply via email to