From 312b7953be2f09b99a89d8f4239df90276d9d54d Mon Sep 17 00:00:00 2001 From: Mathieu Dupuy Date: Thu, 3 Dec 2026 09:17:59 +0100 Subject: [PATCH] Measure memory again before failing ScenarioXGC Co-Authored-By: Claude Sonnet 5.5 --- tests/IronPython.Tests/Stress/Engine.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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)