diff --git a/Tests/Open.Database.Extensions.Core.Tests/LeakRetentionTests.cs b/Tests/Open.Database.Extensions.Core.Tests/LeakRetentionTests.cs index 8455cf3..0ffaf90 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/LeakRetentionTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/LeakRetentionTests.cs @@ -190,7 +190,7 @@ public static void ProcedureNames_StayBounded_With10000DistinctProcedures() const int Calls = 3000; const int Rounds = 6; - // The growth allowed in each of the last rounds of calls, in bytes. Measured: 0 for nearly every terminal and round, and swings of up to about 13 KB + // The growth allowed in the median of the last rounds of calls, in bytes. Measured: 0 for nearly every terminal and round, and swings of up to about 13 KB // (no trend) for the dataflow block. A call that keeps one object, of at least 24 bytes, adds 72 KB a round. // (A zero bound would be unfair to the garbage collector: a round may happen to end a few KB higher.) const long MaxGrowth = 65_536; @@ -276,8 +276,10 @@ public static async Task ManyCalls_TheHeapDoesNotGrow(string terminal) last = now; } - long worst = growth.Skip(Rounds / 2).Max(); - Assert.True(worst <= MaxGrowth, $"Actual: {terminal}: bytes grown per round of {Calls} calls: {string.Join(", ", growth)}."); + // A leak grows the heap in every round, so judge the median of the last rounds: one noisy round (a loaded machine, Debug code) cannot fail the test, while a leak still does. + long[] tail = [.. growth.Skip(Rounds / 2).Order()]; + long median = tail[tail.Length / 2]; + Assert.True(median <= MaxGrowth, $"Actual: {terminal}: bytes grown per round of {Calls} calls: {string.Join(", ", growth)}."); } static long Settled()