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

   ## Summary
   
   Fixes the remaining flakiness in `SedaAsyncProducerTest` after PR #24639 
(CAMEL-24039 batch 7), which increased mock assertion timeouts but did not 
address the root cause.
   
   ## Root Cause
   
   `SedaAsyncProducerTest` used a plain `private String route = ""` field that 
was mutated by two threads via non-atomic read-modify-write (`route = route + 
"token"`):
   
   - **Test thread** appends `"send"` immediately after firing 
`asyncRequestBody()`
   - **Async executor thread** appends `"process"` inside the route processor 
(after a 100ms delay)
   
   The 100ms delay is intended to let the test thread win the race, but on 
heavily loaded CI machines the test thread can be preempted for >100ms after 
`asyncRequestBody()` returns, causing the async thread to run first. 
Additionally, the plain String field has no memory visibility guarantee across 
threads.
   
   ## Fix
   
   Two coordinated changes in `SedaAsyncProducerTest`:
   
   1. **Replace `String` with `AtomicReference<String>`** — each append uses 
`updateAndGet(s -> s + "token")` which is an atomic read-modify-write, 
eliminating the data race on the field itself.
   
   2. **Add a `CountDownLatch sendLatch`** — the route processor `await()`s the 
latch before recording its token. In `testAsyncProducer`, the test thread 
counts down the latch *after* recording `"send"`, establishing a happens-before 
relationship that makes the ordering deterministic regardless of scheduler 
jitter. In `testAsyncProducerWait`, the latch is counted down immediately 
before `template.send()` (which blocks until processing completes anyway, so 
the ordering in that test is already guaranteed by the blocking call semantics).
   
   ## Test Verification
   
   All 8 tests from the batch pass locally:
   ```
   Tests run: 10, Failures: 0, Errors: 0, Skipped: 0
   ```
   (10 = 2 in `SedaAsyncProducerTest` + 2 in `SedaMultipleConsumersTest` + 1 
each in the 6 remaining tests)
   
   The other 7 tests in the batch were reviewed and have no equivalent 
shared-mutable-field races.
   
   ---
   _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
   


-- 
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