Copilot commented on code in PR #24393:
URL: https://github.com/apache/camel/pull/24393#discussion_r3521841783
##########
components/camel-vertx/camel-vertx-websocket/src/test/java/org/apache/camel/component/vertx/websocket/VertxWebsocketConsumerAsClientMaxReconnectTest.java:
##########
@@ -42,26 +45,35 @@ void testMaxReconnect() throws Exception {
context.getRouteController().stopRoute("server");
- // Verify that we cannot send messages
- Exchange exchange = template.send(uri, new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getMessage().setBody("Hello World Again");
- }
- });
- Exception exception = exchange.getException();
- Assertions.assertNotNull(exception);
- Assertions.assertInstanceOf(ConnectException.class,
exception.getCause());
+ // Verify that the server is fully down by waiting until sends fail.
+ // The producer endpoint's cached WebSocket may still appear open
briefly
+ // after stopRoute returns, until the Vert.x event loop processes the
+ // TCP close frame and isClosed() starts returning true.
+ await().atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(() -> {
+ Exchange exchange = template.send(uri, new Processor() {
+ @Override
+ public void process(Exchange exchange) throws
Exception {
+ exchange.getMessage().setBody("Hello World Again");
+ }
+ });
+ Assertions.assertNotNull(exchange.getException());
+ Assertions.assertInstanceOf(ConnectException.class,
exchange.getException().getCause());
+ });
// Wait for client consumer reconnect max attempts to be exhausted
- Thread.sleep(300);
+ // (maxReconnectAttempts=1, reconnectInterval=10ms).
+ // Use pollDelay to give reconnect attempts time to complete before
checking.
+ await().atMost(10, TimeUnit.SECONDS)
+ .pollDelay(2, TimeUnit.SECONDS)
+ .untilAsserted(() -> mockEndpoint.assertIsSatisfied());
// Restart server
context.getRouteController().startRoute("server");
// Verify that the client consumer gave up reconnecting
template.sendBody(uri, "Hello World Again");
- mockEndpoint.assertIsSatisfied();
+ mockEndpoint.assertIsSatisfied(1000);
Review Comment:
`mockEndpoint.assertIsSatisfied(1000)` does not reliably verify that *no*
messages arrive after restarting the server, because `expectedMessageCount(0)`
is already satisfied and the assertion may return immediately without waiting.
This can still allow late deliveries to slip through (the same reason other
tests use `setAssertPeriod(...)` when asserting 0 messages).
--
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]