Skip to content

Commit 9fd018a

Browse files
authored
test: ignore MQTT 5 exception when closing connection in test (#1403)
1 parent dbd7284 commit 9fd018a

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

src/integrationtests/java/com/aws/greengrass/integrationtests/e2e/BaseE2ETestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ void beforeEach(ExtensionContext context) {
191191
ignoreExceptionUltimateCauseWithMessageSubstring(context, "The connection was closed unexpectedly");
192192
ignoreExceptionUltimateCauseWithMessageSubstring(context,
193193
"Old requests from the previous session are cancelled");
194+
ignoreExceptionUltimateCauseWithMessageSubstring(context,
195+
"client connection interrupted by user request");
194196
}
195197

196198
@BeforeAll

src/integrationtests/java/com/aws/greengrass/integrationtests/e2e/deployment/MultipleDeploymentsTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.junit.jupiter.api.Test;
1919
import org.junit.jupiter.api.Timeout;
2020
import org.junit.jupiter.api.extension.ExtendWith;
21+
import org.junit.jupiter.api.extension.ExtensionContext;
2122
import software.amazon.awssdk.services.greengrassv2.model.ComponentDeploymentSpecification;
2223
import software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentRequest;
2324
import software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse;
@@ -37,6 +38,7 @@
3738
import static com.aws.greengrass.deployment.DeploymentStatusKeeper.PROCESSED_DEPLOYMENTS_TOPICS;
3839
import static com.aws.greengrass.lifecyclemanager.GreengrassService.RUNTIME_STORE_NAMESPACE_TOPIC;
3940
import static com.aws.greengrass.lifecyclemanager.GreengrassService.SERVICES_NAMESPACE_TOPIC;
41+
import static com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionUltimateCauseWithMessageSubstring;
4042
import static org.junit.jupiter.api.Assertions.assertTrue;
4143

4244
@ExtendWith(GGExtension.class)
@@ -48,7 +50,10 @@ protected MultipleDeploymentsTest() throws Exception {
4850
}
4951

5052
@BeforeEach
51-
void beforeEach() throws Exception {
53+
void beforeEach2(ExtensionContext context) throws Exception {
54+
// Depending on the order that we receive the jobs, we expect that the job may already be canceled, so this
55+
// exception is fine and we want the test to continue.
56+
ignoreExceptionUltimateCauseWithMessageSubstring(context, "finished with status CANCELED");
5257
initKernel();
5358
}
5459

src/main/java/com/aws/greengrass/mqttclient/AwsIotMqtt5Client.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ public synchronized CompletableFuture<SubscribeResponse> subscribe(Subscribe sub
242242
.thenApply(SubscribeResponse::fromCrtSubAck)
243243
.whenComplete((r, error) -> {
244244
synchronized (this) {
245-
if (error == null && (r.getReasonCodes() == null || r.getReasonCodes().stream()
245+
if (error == null && r != null
246+
&& (r.getReasonCodes() == null || r.getReasonCodes().stream()
246247
// reason codes less than or equal to 2 are positive responses
247248
.allMatch(i -> i <= 2))) {
248249
subscriptionTopics.add(subscribe);
@@ -254,11 +255,13 @@ public synchronized CompletableFuture<SubscribeResponse> subscribe(Subscribe sub
254255
if (error != null) {
255256
l.cause(error);
256257
}
257-
if (r.getReasonCodes() != null) {
258-
l.kv("reasonCodes", r.getReasonCodes());
259-
}
260-
if (Utils.isNotEmpty(r.getReasonString())) {
261-
l.kv("reason", r.getReasonString());
258+
if (r != null) {
259+
if (r.getReasonCodes() != null) {
260+
l.kv("reasonCodes", r.getReasonCodes());
261+
}
262+
if (Utils.isNotEmpty(r.getReasonString())) {
263+
l.kv("reason", r.getReasonString());
264+
}
262265
}
263266
l.log("Error subscribing to topic");
264267
}

0 commit comments

Comments
 (0)