This is an automated email from the ASF dual-hosted git repository.
apupier 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 6267e9502f2a CAMEL-26489: Fix flaky ThrottlingGroupingTest
6267e9502f2a is described below
commit 6267e9502f2a67718213eb63b1e165b501776c29
Author: Aurélien Pupier <[email protected]>
AuthorDate: Mon Nov 2 11:51:17 2026 +0100
CAMEL-26489: Fix flaky ThrottlingGroupingTest
The test testSendLotsOfMessagesButOnly3GetThroughWithin2Seconds expected
3 messages, but the route throttles 3 per group, with the correlation
expression being the value of the "key" header ("1" or "2"). There are
therefore 2 groups with 3 permits each, and up to 6 of the 9 messages
can pass immediately.
The test only passed when the main thread checked the mock right after
the 3rd message arrived, and before the 4th to 6th reached it:
MockEndpoint.assertIsSatisfied() waits on a latch for the expected
count, then compares it to the received counter without waiting for
further messages. When the seda consumer thread was faster, the count
was 4, 5 or 6, which are the failures observed on CI.
The 1000ms time period could also lapse during the test and let the
remaining messages through in a second window.
The test now expects the 6 first messages in order, and uses an assert
period to verify that no more messages get through afterwards. The time
period of the route is raised to 5000ms so that held messages cannot be
released during the assert period, even on a slow machine. The test is
renamed to reflect the actual behavior.
Co-authored-by: IBM Bob 2.2.1
Signed-off-by: Aurélien Pupier <[email protected]>
---
.../throttle/requests/ThrottlingGroupingTest.java | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/throttle/requests/ThrottlingGroupingTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/throttle/requests/ThrottlingGroupingTest.java
index dd471f77308a..045823962f87 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/throttle/requests/ThrottlingGroupingTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/throttle/requests/ThrottlingGroupingTest.java
@@ -73,11 +73,16 @@ public class ThrottlingGroupingTest extends
ContextTestSupport {
}
@Test
- public void testSendLotsOfMessagesButOnly3GetThroughWithin2Seconds()
throws Exception {
+ public void testSendLotsOfMessagesButOnly3PerGroupGetThroughWithinPeriod()
throws Exception {
MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:gresult",
MockEndpoint.class);
- resultEndpoint.expectedMessageCount(3);
- resultEndpoint.setResultWaitTime(2000);
+ // the correlation is on the value of the "key" header, which is
either "1" or "2" (2 groups), and the throttle
+ // is 3 per group, so the first 6 messages pass immediately (the seda
consumer is single threaded, so in order),
+ // and the remaining ones are held until the time period has elapsed
+ resultEndpoint.expectedBodiesReceived("<message>0</message>",
"<message>1</message>", "<message>2</message>",
+ "<message>3</message>", "<message>4</message>",
"<message>5</message>");
+ // verify that no more messages get through after the expected ones
+ resultEndpoint.setAssertPeriod(500);
Map<String, Object> headers = new HashMap<>();
for (int i = 0; i < 9; i++) {
@@ -89,8 +94,6 @@ public class ThrottlingGroupingTest extends
ContextTestSupport {
template.sendBodyAndHeaders("seda:ga", "<message>" + i +
"</message>", headers);
}
- // lets pause to give the requests time to be processed
- // to check that the throttle really does kick in
resultEndpoint.assertIsSatisfied();
}
@@ -215,7 +218,7 @@ public class ThrottlingGroupingTest extends
ContextTestSupport {
from("seda:b").throttle(header("max"), 2).to("mock:result2");
from("seda:c").throttle(header("max")).correlationExpression(header("key")).to("mock:resultdynamic");
- from("seda:ga").throttle(constant(3),
header("key")).timePeriodMillis(1000).to("log:gresult", "mock:gresult");
+ from("seda:ga").throttle(constant(3),
header("key")).timePeriodMillis(5000).to("log:gresult", "mock:gresult");
from("direct:ga").throttle(constant(5),
header("key")).timePeriodMillis(INTERVAL).to("log:gresult",
"mock:gresult");