Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(iot): deflake MQTT lazy-startup test, align 1.5.28 version, make compat runner executable (#1580)

Hector Ventura68fc4134c401
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 @@
<groupId>io.github.hectorvent</groupId>
<artifactId>floci</artifactId>
- <version>1.6.0</version>
+ <version>1.5.28</version>
<packaging>jar</packaging>
<name>Floci</name>
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