Enable the memory leak test after allowing to copy with native memory being freed in the background.

This commit is contained in:
Peter Lawrey
2020-06-04 13:21:47 +01:00
parent 28bc77edd6
commit 8082914c44
@@ -99,7 +99,7 @@ public class MemoryLeaksTest {
serializerCount.set(0);
}
@Test(timeout = 60_000)
@Test(timeout = 10_000)
public void testChronicleMapCollectedAndDirectMemoryReleased()
throws IOException, InterruptedException {
assertFalse(OS.isMacOSX());
@@ -110,6 +110,9 @@ public class MemoryLeaksTest {
// This tests is successful always in Windows and successful in Linux and OS X when run
// alone, rather than along all other Chronicle Map's tests.
System.gc();
Jvm.pause(100);
long nativeMemoryUsedBeforeMap = nativeMemoryUsed();
int serializersBeforeMap = serializerCount.get();
// the purpose of the test is to find maps which are not closed properly.
@@ -124,16 +127,20 @@ public class MemoryLeaksTest {
// Wait until Map is collected by GC
// Wait until Cleaner is called and memory is returned to the system
for (int i = 0; i < 6_000; i++) {
for (int i = 1; i <= 10; i++) {
if (ref.get() == null &&
nativeMemoryUsedBeforeMap == nativeMemoryUsed() && // (*)
nativeMemoryUsedBeforeMap >= nativeMemoryUsed() && // (*)
serializerCount.get() == serializersBeforeMap) {
break;
}
System.gc();
Jvm.pause(100);
Jvm.pause(i * 10);
System.out.println("ref.get()=" + (ref.get() == null));
System.out.println(nativeMemoryUsedBeforeMap + " <=> " + nativeMemoryUsed());
System.out.println(serializerCount.get() + " <=> " + serializersBeforeMap);
}
Assert.assertEquals(nativeMemoryUsedBeforeMap, nativeMemoryUsed());
if (nativeMemoryUsedBeforeMap < nativeMemoryUsed())
Assert.assertEquals(nativeMemoryUsedBeforeMap, nativeMemoryUsed());
Assert.assertEquals(serializersBeforeMap, serializerCount.get());
}