From 9c23757e4f24f61c0152e6fc82c5dccf8e8c4b8d Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Sun, 20 Sep 2026 22:11:24 -0400 Subject: [PATCH] test(iot): run the MQTT WebSocket churn cycles concurrently (#4029) --- .../iot/IotMqttWebSocketIntegrationTest.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttWebSocketIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttWebSocketIntegrationTest.java index bfe0cbb47d..300b92569b 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttWebSocketIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttWebSocketIntegrationTest.java @@ -40,6 +40,9 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; @@ -66,6 +69,7 @@ public class IotMqttWebSocketIntegrationTest { static final int TLS_PORT = 18837; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final short CLOSE_UNSUPPORTED_DATA = 1003; + private static final int CHURN_THREADS = 10; @ConfigProperty(name = "quarkus.http.test-ssl-port", defaultValue = "0") int testSslPort; @@ -274,14 +278,29 @@ public class IotMqttWebSocketIntegrationTest { @Test void connectDisconnectChurnLeavesNoBrokerSessionBehind() throws Exception { + // Each connect costs a fixed ~300ms inside the Paho client (its sender, receiver and callback + // threads each sleep 100ms while starting), so the cycles run concurrently to keep the + // churn from being 30 of those in a row. List clientIds = new ArrayList<>(); - for (int i = 0; i < 30; i++) { - String clientId = "churn-" + i + "-" + System.nanoTime(); - clientIds.add(clientId); - String url = i % 2 == 0 ? ws("/mqtt") : wss("/mqtt"); - try (WsClient client = WsClient.connect(url, clientId, null, null)) { - assertTrue(client.isConnected()); + ExecutorService pool = Executors.newFixedThreadPool(CHURN_THREADS); + try { + List> cycles = new ArrayList<>(); + for (int i = 0; i < 30; i++) { + String clientId = "churn-" + i + "-" + System.nanoTime(); + clientIds.add(clientId); + String url = i % 2 == 0 ? ws("/mqtt") : wss("/mqtt"); + cycles.add(pool.submit(() -> { + try (WsClient client = WsClient.connect(url, clientId, null, null)) { + assertTrue(client.isConnected()); + } + return null; + })); } + for (Future cycle : cycles) { + cycle.get(30, TimeUnit.SECONDS); + } + } finally { + pool.shutdownNow(); } long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(10); for (String clientId : clientIds) {