Skip to content

Commit

Permalink
Release native references in failed tests (#677)
Browse files Browse the repository at this point in the history
Some tests were not cleaning up native references because close() was being called in a failing try block. These calls have been moved to a finally block to insure native references get cleaned up so tests don't time out after failing.
  • Loading branch information
sbSteveK authored Sep 11, 2023
1 parent ee4f6a3 commit 1cc7ecd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/test/java/software/amazon/awssdk/crt/test/CrtTestFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ private void SetPropertyFromEnv(String name){

// Setup System properties from environment variables set by builder for use by unit tests.
private void SetupTestProperties(){
// Indicate that the system properties have been setup
System.setProperty("are.test.properties.setup", "true");

SetPropertyFromEnv("AWS_TEST_IS_CI");
SetPropertyFromEnv("AWS_TEST_MQTT311_ROOT_CA");
SetPropertyFromEnv("ENDPOINT");
Expand Down Expand Up @@ -216,12 +219,16 @@ public void setup() {
}
Log.log(Log.LogLevel.Debug, LogSubject.JavaCrtGeneral, "CrtTestFixture setup begin");

// TODO this CrtTestContext should be removed as we are using System Properties for tests now.
context = new CrtTestContext();
CrtPlatform platform = CRT.getPlatformImpl();
if (platform != null) {
platform.testSetup(context);
} else {
SetupTestProperties();
// System properties for tests only need to be setup once
if (System.getProperty("are.test.properties.setup") != "true"){
CrtPlatform platform = CRT.getPlatformImpl();
if (platform != null) {
platform.testSetup(context);
} else {
SetupTestProperties();
}
}

Log.log(Log.LogLevel.Debug, LogSubject.JavaCrtGeneral, "CrtTestFixture setup end");
Expand All @@ -237,10 +244,6 @@ public void tearDown() {

context = null;

EventLoopGroup.closeStaticDefault();
HostResolver.closeStaticDefault();
ClientBootstrap.closeStaticDefault();

CrtResource.waitForNoResources();
if (CRT.getOSIdentifier() != "android") {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ public void onConnectionClosed(OnConnectionClosedReturn data) {
connected.get();
result = true;
}
client.close();
finally {
client.close();
}

} catch (Exception ex) {
fail("Exception during connect: " + ex.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public void ConnDC_Cred_UC1()
null,
null);
disconnect();
}
finally {
close();
}
}
Expand Down Expand Up @@ -98,6 +100,8 @@ public void ConnDC_Cred_UC2()
null,
null);
disconnect();
}
finally {
close();
}
}
Expand All @@ -122,6 +126,8 @@ public void ConnDC_Cred_UC3()
null,
null);
disconnect();
}
finally {
close();
}
}
Expand Down Expand Up @@ -157,6 +163,8 @@ public void ConnDC_Cred_UC4()
null,
null);
disconnect();
}
finally {
close();
}
}
Expand Down Expand Up @@ -187,6 +195,8 @@ public void ConnWS_Cred_UC1()
CredentialsProvider provider = builder.build();) {
connectWebsocketsWithCredentialsProvider(provider, AWS_TEST_MQTT311_IOT_CORE_HOST, 443, tlsContext, null, null, null);
disconnect();
}
finally {
close();
}
}
Expand All @@ -208,6 +218,8 @@ public void ConnWS_Cred_UC2()
CredentialsProvider provider = builder.build();) {
connectWebsocketsWithCredentialsProvider(provider, AWS_TEST_MQTT311_IOT_CORE_HOST, 443, tlsContext, null, null, null);
disconnect();
}
finally {
close();
}
}
Expand Down Expand Up @@ -237,6 +249,8 @@ public void ConnWS_Cred_UC3()
CredentialsProvider provider = builder.build();) {
connectWebsocketsWithCredentialsProvider(provider, AWS_TEST_MQTT311_IOT_CORE_HOST, 443, tlsContext, null, null, null);
disconnect();
}
finally {
close();
}
}
Expand Down Expand Up @@ -270,6 +284,8 @@ public void ConnWS_Cred_UC4()
CredentialsProvider provider = builder.build();) {
connectWebsocketsWithCredentialsProvider(provider, AWS_TEST_MQTT311_IOT_CORE_HOST, 443, tlsContext, null, null, null);
disconnect();
}
finally {
close();
}
}
Expand Down Expand Up @@ -336,6 +352,8 @@ public void ConnDC_UC3()
null,
null);
disconnect();
}
finally {
close();
}
}
Expand Down Expand Up @@ -369,6 +387,8 @@ public void ConnDC_UC4()
null,
null);
disconnect();
}
finally {
close();
}
}
Expand Down Expand Up @@ -400,6 +420,8 @@ public void ConnDC_UC5()
null,
proxyOptions);
disconnect();
}
finally {
close();
}
}
Expand Down Expand Up @@ -470,6 +492,8 @@ public void ConnWS_UC3()
null,
null);
disconnect();
}
finally {
close();
}
}
Expand Down Expand Up @@ -501,6 +525,8 @@ public void ConnWS_UC4()
null,
proxyOptions);
disconnect();
}
finally {
close();
}
}
Expand Down

0 comments on commit 1cc7ecd

Please sign in to comment.