apupier opened a new pull request, #31161:
URL: https://github.com/apache/camel/pull/31161

   # Description
   
   Fixes the flaky `MailConvertersTest` (CAMEL-27879): all five tests failed 
intermittently with `mock://result Received message count. Expected: <1> but 
was: <0>`.
   
   ## Cause
   
   The POP3 consumer of the test uses `closeFolder=false` and polls every 100 
ms from the moment the context starts. A POP3 folder only lists the mails that 
were in the mailbox when it was opened (RFC 1939: the session works on a 
snapshot of the maildrop), and with `closeFolder=false` the folder is never 
reopened. When the first poll ran before the test had sent its mail, the 
consumer kept the folder open on an empty snapshot and never saw the mail. With 
the default `closeFolder=true` each poll reopens the folder and the mail is 
found.
   
   I checked this with a throwaway test (not committed): after several empty 
polls, a POP3 consumer with `closeFolder=false` received 0 mails, a consumer 
with the default received it.
   
   ## Changes
   
   - `MailConvertersTest`: the POP3 route is `autoStartup(false)` and each test 
starts it once the mail is in the mailbox (Awaitility, explicit 10 s limit), so 
the first and only open of the folder sees the mail.
   - `MailConfiguration#setCloseFolder`: the option description now states that 
a POP3 consumer that keeps the folder open does not see the mails that arrive 
after the folder was opened. Generated JSON files of the component and of the 
catalog are updated accordingly.
   
   ## Why this approach
   
   - **The test keeps `closeFolder=false`**, which it needs, so the test 
controls when the folder is opened instead.
   - **Not the fix of CAMEL-27771 (`MailMimeDecodeHeadersTest`)**: that one was 
caused by mails left over from a previous test method (count too high), solved 
with dedicated mailboxes, `delete=true` and clearing in `setupResources()`. 
Here the mailbox is already cleared and the count is too low, so dedicated 
mailboxes would not change anything.
   - **The consumer is not changed**: reopening a POP3 folder on every poll 
even with `closeFolder=false` would change runtime behaviour and the lazy 
loading of the message content that the option allows. This looks like the 
protocol behaviour rather than a bug, and a change would be a decision for the 
maintainers, out of scope for a flaky test fix. The documentation change makes 
the behaviour visible to users instead of silently losing mail.
   
   ## Notes for reviewers
   
   - Other camel-mail tests also combine POP3 with `closeFolder=false` (for 
example `MimeMultipartAlternativeTest`) and may have the same race. I did not 
change them as they are not reported flaky.
   - I could not reproduce the failure of the unmodified test locally; the 
cause is established from the code, the stack traces and the experiment above.
   - The files of `catalog/camel-catalog` were updated by hand for the six 
`description` lines only, as regenerating the catalog module locally produced 
unrelated changes.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [x] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   ---
   _AI-generated by IBM Bob on behalf of apupier._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to