Browse Source

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.
pull/15865/head
dshvaika 4 weeks ago
parent
commit
12d0e7c693
  1. 15
      msa/black-box-tests/src/test/java/org/thingsboard/server/msa/connectivity/MqttGatewayClientTest.java

15
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);

Loading…
Cancel
Save