diff --git a/tests/IronPython.Tests/Stress/Engine.cs b/tests/IronPython.Tests/Stress/Engine.cs index db9b2bfb7..cd4c10052 100644 --- a/tests/IronPython.Tests/Stress/Engine.cs +++ b/tests/IronPython.Tests/Stress/Engine.cs @@ -62,9 +62,15 @@ public void ScenarioXGC() { // free up weak data structures held onto by the Python runtime _pe.Execute("import gc\ngc.collect()"); - long finalMemory = GetTotalMemory(); - long memoryUsed = finalMemory - initialMemory; const long memoryThreshold = 100000; + long memoryUsed = GetTotalMemory() - initialMemory; + + // The measurement can include memory that is only released a moment later, so measure again + // before failing. A leak stays over the threshold. + for (int attempt = 0; attempt < 5 && memoryUsed > memoryThreshold; attempt++) { + System.Console.WriteLine("ScenarioGC used {0} bytes of memory, measuring again.", memoryUsed); + memoryUsed = GetTotalMemory() - initialMemory; + } bool emitsUncollectibleCode = Snippets.Shared.SaveSnippets || _env.Setup.DebugMode; if (!emitsUncollectibleCode)