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 f7b3055e2257 CAMEL-23317: Isolate mailboxes and fix POP3 race in 
remaining flaky mail tests
f7b3055e2257 is described below

commit f7b3055e225742c10bf0a17d30d62f541e43eb7f
Author: AurĂ©lien Pupier <[email protected]>
AuthorDate: Tue Oct 13 14:30:03 2026 +0200

    CAMEL-23317: Isolate mailboxes and fix POP3 race in remaining flaky mail 
tests
    
    - MimeMultipartAlternativeWithLongerFilenameTest: POP3 with
      closeFolder=false takes a folder snapshot at open time, so if the
      consumer opens the folder before the mail is delivered the snapshot is
      empty and the message is never picked up. Give each test method its
      own mailbox user, route and mock endpoint, and set autoStartup=false
      so the POP3 route only starts polling after the mail is already in the
      inbox.
    - MailDisconnectTest: the 2.5s latch timeout was too tight for 5 mails
      polled every 500ms with a disconnect and reconnect between polls on a
      loaded CI machine. Keep the latch (it verifies messages are received
      across disconnect/reconnect cycles) but raise the timeout to 15s.
      Also use a dedicated mock endpoint name.
    
    Co-authored-by: IBM Bob 2.2.1
    Signed-off-by: AurĂ©lien Pupier <[email protected]>
---
 .../camel/component/mail/MailDisconnectTest.java   |  8 ++---
 ...MultipartAlternativeWithLongerFilenameTest.java | 39 ++++++++++++++--------
 2 files changed, 29 insertions(+), 18 deletions(-)

diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailDisconnectTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailDisconnectTest.java
index b213108e6cf2..575d4d7684f3 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailDisconnectTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailDisconnectTest.java
@@ -34,7 +34,7 @@ import org.junit.jupiter.api.Test;
  */
 public class MailDisconnectTest extends CamelTestSupport {
     private static final MailboxUser jones = 
Mailbox.getOrCreateUser("MailDisconnectTest-jones", "secret");
-
+    private static final String MOCK_RESULT = "mock:disconnectResult";
     private int expectedCount = 5;
     private CountDownLatch latch = new CountDownLatch(expectedCount);
 
@@ -46,7 +46,7 @@ public class MailDisconnectTest extends CamelTestSupport {
     void setup() {
         Mailbox.clearAll(jones);
 
-        MockEndpoint mock = getMockEndpoint("mock:result");
+        MockEndpoint mock = getMockEndpoint(MOCK_RESULT);
         mock.expectedMessageCount(expectedCount);
 
         // send 5 mails with some delay so we do multiple polls with 
disconnect between
@@ -61,7 +61,7 @@ public class MailDisconnectTest extends CamelTestSupport {
 
     @Test
     public void testDisconnect() throws Exception {
-        if (!latch.await(2500, TimeUnit.MILLISECONDS)) {
+        if (!latch.await(15, TimeUnit.SECONDS)) {
             Assertions.fail("Not all messages were received as expected: " + 
(expectedCount - latch.getCount())
                             + " message(s) missing");
         }
@@ -76,7 +76,7 @@ public class MailDisconnectTest extends CamelTestSupport {
                 from(jones.uriPrefix(Protocol.imap) + 
"&disconnect=true&initialDelay=100&delay=500")
                         .routeId("mail-disconnect")
                         .process(e -> latch.countDown())
-                        .to("mock:result");
+                        .to(MOCK_RESULT);
             }
         };
     }
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeWithLongerFilenameTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeWithLongerFilenameTest.java
index 5c1b191b2b4b..43efba675242 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeWithLongerFilenameTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeWithLongerFilenameTest.java
@@ -40,17 +40,20 @@ import static 
org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class MimeMultipartAlternativeWithLongerFilenameTest extends 
CamelTestSupport {
-    private static final MailboxUser ryanWithLongerFilename
-            = 
Mailbox.getOrCreateUser("MimeMultipartAlternativeWithLongerFilenameTest-ryanWithLongerFilename",
 "secret");
+    private static final MailboxUser ryanInline
+            = 
Mailbox.getOrCreateUser("MimeMultipartAlternativeWithLongerFilenameTest-ryanInline",
 "secret");
+    private static final MailboxUser ryanRegular
+            = 
Mailbox.getOrCreateUser("MimeMultipartAlternativeWithLongerFilenameTest-ryanRegular",
 "secret");
     private Logger log = LoggerFactory.getLogger(getClass());
     private String alternativeBody = "hello world! (plain text)";
     private String htmlBody = "<html><body><h1>Hello</h1>World<img 
src=\"cid:myCoolLogo.jpeg\"></body></html>";
 
-    private void sendMultipartEmail(boolean useInlineattachments) {
-        Mailbox.clearAll(ryanWithLongerFilename);
+    private void sendMultipartEmail(MailboxUser user, boolean 
useInlineattachments, String mockUri, String routeId)
+            throws Exception {
+        Mailbox.clearAll(user);
 
         // create an exchange with a normal body and attachment to be produced 
as email
-        MailEndpoint endpoint = 
context.getEndpoint(ryanWithLongerFilename.uriPrefix(Protocol.smtp), 
MailEndpoint.class);
+        MailEndpoint endpoint = 
context.getEndpoint(user.uriPrefix(Protocol.smtp), MailEndpoint.class);
         
endpoint.getConfiguration().setUseInlineAttachments(useInlineattachments);
         
endpoint.getConfiguration().setAlternativeBodyHeader(MailConstants.MAIL_ALTERNATIVE_BODY);
 
@@ -62,15 +65,19 @@ public class MimeMultipartAlternativeWithLongerFilenameTest 
extends CamelTestSup
         in.addAttachment("cid:myCoolLogo.jpeg", new DataHandler(new 
FileDataSource("src/test/data/logo.jpeg")));
 
         // create a producer that can produce the exchange (= send the mail)
-        MockEndpoint mock = getMockEndpoint("mock:result");
+        MockEndpoint mock = getMockEndpoint(mockUri);
         mock.expectedMessageCount(1);
         mock.message(0).header(MailConstants.MAIL_ALTERNATIVE_BODY).isNull();
 
         context.createProducerTemplate().send(endpoint, exchange);
+
+        // a POP3 folder is a snapshot taken when it is opened 
(closeFolder=false keeps it open), so the
+        // consumer must only start polling once the mail is in the mailbox
+        context.getRouteController().startRoute(routeId);
     }
 
-    private void verifyTheRecivedEmail(String expectString) throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
+    private void verifyTheRecivedEmail(String mockUri, String expectString) 
throws Exception {
+        MockEndpoint mock = getMockEndpoint(mockUri);
         mock.assertIsSatisfied();
 
         Exchange out = mock.assertExchangeReceived(0);
@@ -92,22 +99,26 @@ public class MimeMultipartAlternativeWithLongerFilenameTest 
extends CamelTestSup
 
     @Test
     public void testMultipartEmailWithInlineAttachments() throws Exception {
-        sendMultipartEmail(true);
-        verifyTheRecivedEmail("Content-Disposition: inline; 
filename=myCoolLogo.jpeg");
+        sendMultipartEmail(ryanInline, true, "mock:resultInline", 
"routeInline");
+        verifyTheRecivedEmail("mock:resultInline", "Content-Disposition: 
inline; filename=myCoolLogo.jpeg");
     }
 
     @Test
     public void testMultipartEmailWithRegularAttachments() throws Exception {
-        sendMultipartEmail(false);
-        verifyTheRecivedEmail("Content-Disposition: attachment; 
filename=myCoolLogo.jpeg");
+        sendMultipartEmail(ryanRegular, false, "mock:resultRegular", 
"routeRegular");
+        verifyTheRecivedEmail("mock:resultRegular", "Content-Disposition: 
attachment; filename=myCoolLogo.jpeg");
     }
 
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from(ryanWithLongerFilename.uriPrefix(Protocol.pop3) + 
"&initialDelay=100&delay=100&closeFolder=false")
-                        .to("mock:result");
+                from(ryanInline.uriPrefix(Protocol.pop3) + 
"&initialDelay=100&delay=100&closeFolder=false")
+                        .routeId("routeInline").autoStartup(false)
+                        .to("mock:resultInline");
+                from(ryanRegular.uriPrefix(Protocol.pop3) + 
"&initialDelay=100&delay=100&closeFolder=false")
+                        .routeId("routeRegular").autoStartup(false)
+                        .to("mock:resultRegular");
             }
         };
     }

Reply via email to