diff --git a/tests/gc/gcleak2.nim b/tests/gc/gcleak2.nim index 6fdadee895fe2..12578fcdd8e38 100644 --- a/tests/gc/gcleak2.nim +++ b/tests/gc/gcleak2.nim @@ -19,6 +19,7 @@ proc makeObj(): TTestObj = result.s = @[1,2,3] const collectAlways = defined(gcMarkAndSweep) or defined(boehmgc) +const isDeterministic = collectAlways or defined(gcArc) or defined(gcOrc) var memMax = 0 # peak @@ -29,7 +30,7 @@ else: var memMin = -1 # right after a peak var numCollections = 0 -let numIter = when collectAlways: 1_000 else: 1_000_000 +let numIter = when isDeterministic: 1_000 else: 1_000_000 ## full collection is expensive, and the memory doesn't change after ## each iteration so there's no point in a large `numIter` (this was taking ## 350s for `nim c -r -d:release --gc:boehm` + `nim c -r --gc:boehm`, 50% @@ -41,7 +42,7 @@ proc inProc() = var obj: TTestObj obj = makeObj() let mem = getOccupiedMem() - when collectAlways: + when isDeterministic: if i <= 2: memMax = mem doAssert memMax <= 50_000 # adjust as needed @@ -69,10 +70,12 @@ proc inProc() = memPrevious = mem inProc() -when collectAlways: - let msg = getOccupiedMem() +let mem = getOccupiedMem() +var msg = "no leak: " +when isDeterministic: + msg.add $(mem, memMax) + echo msg else: - when not defined(gcOrc): # getOccupiedMem() is always 0, wich seems like a bug - doAssert numCollections > 1000 # 3999 on local OSX; leaving some slack - let msg = $(getOccupiedMem(), memMin, memMax, numCollections, numIter) -echo "no leak: ", msg + msg.add $(mem, memMin, memMax, numCollections, numIter) + echo msg + doAssert numCollections > 1000 # 3999 on local OSX; leaving some slack