Skip to content

Commit

Permalink
fix test leak for MQTT (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
TingDaoK committed May 30, 2024
1 parent 1bbacc9 commit 5f6f2d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,13 @@ public void testExtraCompleteHappy() {
null,
null,
null);
disconnect();
close();
}
catch (Exception ex) {
fail("Exception during connect: " + ex.toString());
} finally {
disconnect();
close();
}
disconnect();
close();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ public void testHttpConnection() throws Exception {
testConnectionWithAllCiphers(new URI("https://kms-fips.us-east-1.amazonaws.com:443"), true, null);
testConnectionWithAllCiphers(new URI("https://kms.us-west-2.amazonaws.com:443"), true, null);
testConnectionWithAllCiphers(new URI("https://kms-fips.us-west-2.amazonaws.com:443"), true, null);

// BadSSL
testConnectionWithAllCiphers(new URI("https://rsa2048.badssl.com/"), true, null);
testConnectionWithAllCiphers(new URI("http://http.badssl.com/"), true, null);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import org.junit.After;

class MissingCredentialsException extends RuntimeException {
MissingCredentialsException(String message) {
Expand Down Expand Up @@ -142,6 +143,13 @@ protected void setConnectionMessageTransformer(Consumer<MqttMessage> connectionM
this.connectionMessageTransfomer = connectionMessageTransfomer;
}

@After
@Override
public void tearDown() {
close();
super.tearDown();
}

MqttClientConnectionFixture() {
}

Expand Down Expand Up @@ -386,7 +394,10 @@ void disconnect() {
}

void close() {
connection.close();
if(connection!=null) {
connection.close();
connection = null;
}
}

CompletableFuture<Integer> publish(String topic, byte[] payload, QualityOfService qos) {
Expand Down Expand Up @@ -444,4 +455,3 @@ OnConnectionClosedReturn waitForConnectClose() throws Exception {
return onConnectionClosedFuture.get(60, TimeUnit.SECONDS);
}
}

0 comments on commit 5f6f2d2

Please sign in to comment.