Try to fail less often (never?).

This commit is contained in:
NathanSweet 2018-06-16 03:35:32 +02:00
parent fdd38cafd1
commit 99cda2aa2a

View File

@ -38,6 +38,7 @@ public class ClassLoaderTest extends TestCase {
}
public void testAutoUnloadClassloaders () throws Exception {
reclaimLoaders();
int initialCount = AccessClassLoader.activeAccessClassLoaders();
ClassLoader testClassLoader1 = new TestClassLoader1();
@ -70,6 +71,13 @@ public class ClassLoaderTest extends TestCase {
testObject2 = null;
access2 = null;
reclaimLoaders();
// Yeah, reclaimed!
assertEquals(initialCount, AccessClassLoader.activeAccessClassLoaders());
}
private void reclaimLoaders () throws Exception {
// Force GC to reclaim unreachable (or only weak-reachable) objects
System.gc();
try {
@ -84,9 +92,6 @@ public class ClassLoaderTest extends TestCase {
Thread.sleep(100); // test again
times++;
}
// Yeah, both reclaimed!
assertEquals(Math.min(initialCount, 1), AccessClassLoader.activeAccessClassLoaders());
}
public void testRemoveClassloaders () throws Exception {