diff --git a/docker/run-docker-tests.sh b/docker/run-docker-tests.sh old mode 100644 new mode 100755 diff --git a/pom.xml b/pom.xml index 3b8fe6456e..e629132fc6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.hectorvent floci - 1.6.0 + 1.5.28 jar Floci diff --git a/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttLazyStartupIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttLazyStartupIntegrationTest.java index ad639300b4..6d5894bbf4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttLazyStartupIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iot/IotMqttLazyStartupIntegrationTest.java @@ -26,8 +26,28 @@ class IotMqttLazyStartupIntegrationTest { IotMqttBrokerService mqttBrokerService; @BeforeEach - void stopBroker() { + void stopBroker() throws InterruptedException { mqttBrokerService.stop(); + awaitPortClosed(PORT); + } + + /** + * Vert.x's {@code MqttServer.close()} future can resolve a moment before the OS + * releases the listening socket, so a fresh connect immediately after {@link + * IotMqttBrokerService#stop()} may still succeed. Poll until the port actually + * refuses connections before a test asserts the broker is not listening — this + * removes a startup-order race that only surfaced under the full ordered suite. + */ + private static void awaitPortClosed(int port) throws InterruptedException { + long deadline = System.currentTimeMillis() + 5_000; + while (System.currentTimeMillis() < deadline) { + try (Socket socket = new Socket()) { + socket.connect(new InetSocketAddress("127.0.0.1", port), 100); + } catch (Exception refused) { + return; // connection refused — the broker port is closed + } + Thread.sleep(50); // still accepting connections; back off and retry + } } @Test