[ 
https://issues.apache.org/jira/browse/CAMEL-26377?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18137966#comment-18137966
 ] 

Guillaume Nodet commented on CAMEL-26377:
-----------------------------------------

This issue is being investigated by a coding agent (on behalf of gnodet).

Root cause analysis:

The test has two confirmed issues:

1. *Port race condition*: `AvailablePortFinder.find()` probes a free port by 
opening and immediately closing a `ServerSocket`. The returned `Port` object is 
only a logical reservation in a `ConcurrentHashMap` -- no actual OS socket is 
held. Between the probe socket closing and Netty binding (`server.start()` via 
`TuiWebServer.java`), another process or parallel test fork can claim the port. 
The test class lacks `@Isolated`, making it eligible for concurrent execution 
with other test classes on CI (92% failure rate on a busy CI environment is 
consistent with this).

2. *Missing failure propagation*: When `server.start()` fails with 
`BindException`, the exception is stored in the `failure` AtomicReference 
(MonitorStartupTest.java:81), but the Awaitility loop (lines 86-90) keeps 
polling `socket.connect()` for 10 seconds, oblivious to the server thread 
having already died. The test reports a misleading `ConnectException` instead 
of the actual `BindException`.

Fix plan (single PR):
- Add `@Isolated` to `MonitorStartupTest` to prevent concurrent test execution
- Add `failure.get()` null-check inside the Awaitility assertion to fail fast 
on server startup error
- Fix the leaked `TuiWebServer` in `browserOnlyRefusesMcp` (line 63) which 
never calls `stop()`

_Note: This comment was generated by an AI coding agent and requires manual 
verification._


> Fix flaky test MonitorStartupTest
> ---------------------------------
>
>                 Key: CAMEL-26377
>                 URL: https://issues.apache.org/jira/browse/CAMEL-26377
>             Project: Camel
>          Issue Type: Test
>          Components: camel-jbang
>    Affects Versions: 4.24.0
>            Reporter: Aurélien Pupier
>            Assignee: Guillaume Nodet
>            Priority: Major
>
> [it is flaky 92% of the 
> time|https://develocity.apache.org/scans/tests?search.rootProjectNames=camel&search.tags=main&search.timeZoneId=Europe%2FParis&tests.container=*MonitorStartupTest]
> test is recetn and was added few days ago
> {noformat}
> java.net.ConnectException: Connection refused 
>       at sun.nio.ch.Net.pollConnect(Native Method)    
>       at sun.nio.ch.Net.pollConnectNow(Net.java:639)  
>       at sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:543)  
>       at sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:594)     
>       at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:284)   
>       at java.net.Socket.connect(Socket.java:659)     
>       at 
> org.apache.camel.dsl.jbang.core.commands.tui.MonitorStartupTest.lambda$browserOnlyServesUntilTheServerStops$1(MonitorStartupTest.java:88)
>     
> {noformat}



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to