From: Jim Procter Date: Tue, 14 Apr 2020 12:50:54 +0000 (+0100) Subject: JAL-3597 improved Memory test suite by detecting base memory usage rather than assumi... X-Git-Tag: Develop-2_11_2_0-d20201215~36 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=69f67d45544fc63d5fd60ae71cd21f7138a3e9e4;p=jalview.git JAL-3597 improved Memory test suite by detecting base memory usage rather than assuming it is constant for each release. --- diff --git a/test/jalview/gui/FreeUpMemoryTest.java b/test/jalview/gui/FreeUpMemoryTest.java index 9b21274..24697c0 100644 --- a/test/jalview/gui/FreeUpMemoryTest.java +++ b/test/jalview/gui/FreeUpMemoryTest.java @@ -68,13 +68,27 @@ public class FreeUpMemoryTest File f = generateAlignment(); f.deleteOnExit(); + long expectedMin = 35L; + long usedMemoryAtStart=getUsedMemory(); + if (usedMemoryAtStart>expectedMin) + { + System.err.println("used memory before test is "+usedMemoryAtStart+" > "+expectedMin+"MB .. adjusting minimum."); + expectedMin = usedMemoryAtStart; + } doStuffInJalview(f); Desktop.instance.closeAll_actionPerformed(null); - checkUsedMemory(35L); + checkUsedMemory(expectedMin); } + private static long getUsedMemory() + { + long availableMemory = Runtime.getRuntime().totalMemory() / ONE_MB; + long freeMemory = Runtime.getRuntime().freeMemory() / ONE_MB; + long usedMemory = availableMemory - freeMemory; + return usedMemory; + } /** * Requests garbage collection and then checks whether remaining memory in use * is less than the expected value (in Megabytes) @@ -101,10 +115,7 @@ public class FreeUpMemoryTest /* * check used memory is 'reasonably low' */ - long availableMemory = Runtime.getRuntime().totalMemory() / ONE_MB; - long freeMemory = Runtime.getRuntime().freeMemory() / ONE_MB; - long usedMemory = availableMemory - freeMemory; - + long usedMemory = getUsedMemory(); /* * sanity check - fails if any frame was added after * closeAll_actionPerformed