From 12d0e7c693c27460d1f87aabfa40da1429d1bb4d Mon Sep 17 00:00:00 2001 From: dshvaika Date: Mon, 29 Jun 2026 18:01:01 +0300 Subject: [PATCH] test(attributes): read response-topic event in gateway all-shared test Saving the shared attribute also triggers an attribute-update push on v1/gateway/attributes (gateways auto-receive updates for connected devices). That push can reach the listener queue before the request response, so the blind poll occasionally parsed the update message (no 'shared' field) instead of the response, failing on CI. Poll until an event arrives on v1/gateway/attributes/response. --- .../msa/connectivity/MqttGatewayClientTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/connectivity/MqttGatewayClientTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/connectivity/MqttGatewayClientTest.java index 3e638c6ca6..588f01aa75 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/connectivity/MqttGatewayClientTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/connectivity/MqttGatewayClientTest.java @@ -251,7 +251,10 @@ public class MqttGatewayClientTest extends AbstractContainerTest { requestData.addProperty("sharedKeys", ""); mqttClient.publish("v1/gateway/attributes/request", Unpooled.wrappedBuffer(requestData.toString().getBytes())).get(); - MqttEvent event = listener.getEvents().poll(10 * timeoutMultiplier, TimeUnit.SECONDS); + // Saving the shared attribute above also triggers an attribute-update push on + // v1/gateway/attributes, which can land in the queue before the request response. + // Skip those and read the event from the response topic. + MqttEvent event = pollEventForTopic("v1/gateway/attributes/response"); JsonObject responseData = JsonParser.parseString(Objects.requireNonNull(event).getMessage()).getAsJsonObject(); assertThat(responseData.has("shared")).isTrue(); assertThat(responseData.has("value")).isFalse(); @@ -396,6 +399,16 @@ public class MqttGatewayClientTest extends AbstractContainerTest { this.createdDevice = createDeviceThroughGateway(mqttClient, gatewayDevice); } + private MqttEvent pollEventForTopic(String topic) throws InterruptedException { + MqttEvent event; + while ((event = listener.getEvents().poll(10 * timeoutMultiplier, TimeUnit.SECONDS)) != null) { + if (topic.equals(event.getTopic())) { + return event; + } + } + return null; + } + private void checkAttribute(boolean client, String expectedValue) throws Exception { JsonObject gatewayAttributesRequest = new JsonObject(); int messageId = new Random().nextInt(100);