diff --git a/uat/mqtt-client-control/src/main/java/com/aws/greengrass/testing/mqtt/client/control/implementation/EngineControlImpl.java b/uat/mqtt-client-control/src/main/java/com/aws/greengrass/testing/mqtt/client/control/implementation/EngineControlImpl.java index 67e40e5fe..2bcefbfa3 100644 --- a/uat/mqtt-client-control/src/main/java/com/aws/greengrass/testing/mqtt/client/control/implementation/EngineControlImpl.java +++ b/uat/mqtt-client-control/src/main/java/com/aws/greengrass/testing/mqtt/client/control/implementation/EngineControlImpl.java @@ -178,9 +178,10 @@ public void onDiscoveryAgent(@NonNull String agentId, @NonNull String address, i } else { logger.atInfo().log("Agent {} relocated to {}:{}", agentId, address, port); agents.remove(agentId); - stopAgent(agentId, agentControl, false); - // recursion + // recursion just to add new relocated agent onDiscoveryAgent(agentId, address, port); + // stop can take long time (about 2 seconds) + stopAgent(agentId, agentControl, false); } } } diff --git a/uat/testing-features/src/main/java/com/aws/greengrass/steps/MqttControlSteps.java b/uat/testing-features/src/main/java/com/aws/greengrass/steps/MqttControlSteps.java index 485327776..aca931c59 100644 --- a/uat/testing-features/src/main/java/com/aws/greengrass/steps/MqttControlSteps.java +++ b/uat/testing-features/src/main/java/com/aws/greengrass/steps/MqttControlSteps.java @@ -759,9 +759,6 @@ public void connect(String clientDeviceId, String componentId, String brokerId, } - // get agent control by componentId - AgentControl agentControl = getAgentControl(componentId); - // request for new MQTT connection final String clientDeviceThingName = getClientDeviceThingName(clientDeviceId); @@ -777,6 +774,9 @@ public void connect(String clientDeviceId, String componentId, String brokerId, brokerId, host, port, clientDeviceThingName, componentId, mqttVersion); MqttConnectRequest request = buildMqttConnectRequest( clientDeviceThingName, caList, host, port, version); + // get agent control by componentId as late as possible to reduce race probability + AgentControl agentControl = getAgentControl(componentId); + try { ConnectionControl connectionControl = agentControl.createMqttConnection(request, connectionEvents);