Skip to content

Commit bac10cc

Browse files
committed
JNI Tests: add static WolfSSL reference to WolfSSLTestSuite to prevent premature garbage collection during test runs
1 parent e2fd638 commit bac10cc

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/test/com/wolfssl/test/WolfSSLTestSuite.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121

2222
package com.wolfssl.test;
2323

24+
import org.junit.BeforeClass;
2425
import org.junit.runner.RunWith;
2526
import org.junit.runners.Suite;
2627

28+
import com.wolfssl.WolfSSL;
29+
import com.wolfssl.WolfSSLException;
30+
2731
@RunWith(Suite.class)
2832
@Suite.SuiteClasses({
2933
WolfSSLTest.class,
@@ -38,8 +42,25 @@
3842

3943

4044
public class WolfSSLTestSuite {
41-
/* this class remains empty,
42-
* only used as a holder for the above
43-
* annotations */
45+
46+
/* Static WolfSSL reference to keep library initialized for the duration
47+
* of the entire test suite. Without this, a WolfSSL object created by
48+
* an individual test class could be garbage collected after that test
49+
* class finishes, triggering wolfSSL_Cleanup() in the finalizer and
50+
* freeing session cache locks (and other items) while subsequent test
51+
* classes are still running. This caused crashes on Windows when the
52+
* garbage collector ran between test classes.
53+
*
54+
* We intentionally do not call cleanup() in @AfterClass because on
55+
* Android all tests run in a single process and multiple test suites
56+
* may be active. Cleanup will happen via the finalizer when the
57+
* process exits. */
58+
private static WolfSSL sslLib = null;
59+
60+
@BeforeClass
61+
public static void initializeLibrary() throws WolfSSLException {
62+
WolfSSL.loadLibrary();
63+
sslLib = new WolfSSL();
64+
}
4465
}
4566

0 commit comments

Comments
 (0)