From 69f67d45544fc63d5fd60ae71cd21f7138a3e9e4 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Tue, 14 Apr 2020 13:50:54 +0100 Subject: [PATCH] JAL-3597 improved Memory test suite by detecting base memory usage rather than assuming it is constant for each release. --- test/jalview/gui/FreeUpMemoryTest.java | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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 -- 1.7.10.2