Skip to content

Commit

Permalink
test: ignore MQTT 5 exception when closing connection in test (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDombo authored Feb 9, 2023
1 parent dbd7284 commit 9fd018a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ void beforeEach(ExtensionContext context) {
ignoreExceptionUltimateCauseWithMessageSubstring(context, "The connection was closed unexpectedly");
ignoreExceptionUltimateCauseWithMessageSubstring(context,
"Old requests from the previous session are cancelled");
ignoreExceptionUltimateCauseWithMessageSubstring(context,
"client connection interrupted by user request");
}

@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import software.amazon.awssdk.services.greengrassv2.model.ComponentDeploymentSpecification;
import software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentRequest;
import software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse;
Expand All @@ -37,6 +38,7 @@
import static com.aws.greengrass.deployment.DeploymentStatusKeeper.PROCESSED_DEPLOYMENTS_TOPICS;
import static com.aws.greengrass.lifecyclemanager.GreengrassService.RUNTIME_STORE_NAMESPACE_TOPIC;
import static com.aws.greengrass.lifecyclemanager.GreengrassService.SERVICES_NAMESPACE_TOPIC;
import static com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionUltimateCauseWithMessageSubstring;
import static org.junit.jupiter.api.Assertions.assertTrue;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ public synchronized CompletableFuture<SubscribeResponse> subscribe(Subscribe sub
.thenApply(SubscribeResponse::fromCrtSubAck)
.whenComplete((r, error) -> {
synchronized (this) {
if (error == null && (r.getReasonCodes() == null || r.getReasonCodes().stream()
if (error == null && r != null
&& (r.getReasonCodes() == null || r.getReasonCodes().stream()
// reason codes less than or equal to 2 are positive responses
.allMatch(i -> i <= 2))) {
subscriptionTopics.add(subscribe);
Expand All @@ -254,11 +255,13 @@ public synchronized CompletableFuture<SubscribeResponse> subscribe(Subscribe sub
if (error != null) {
l.cause(error);
}
if (r.getReasonCodes() != null) {
l.kv("reasonCodes", r.getReasonCodes());
}
if (Utils.isNotEmpty(r.getReasonString())) {
l.kv("reason", r.getReasonString());
if (r != null) {
if (r.getReasonCodes() != null) {
l.kv("reasonCodes", r.getReasonCodes());
}
if (Utils.isNotEmpty(r.getReasonString())) {
l.kv("reason", r.getReasonString());
}
}
l.log("Error subscribing to topic");
}
Expand Down

0 comments on commit 9fd018a

Please sign in to comment.