Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Oct 6, 2021
1 parent dc94048 commit 98683ac
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1095,33 +1095,19 @@ public function setRegisterMockObjectsFromTestArgumentsRecursively(bool $flag):
public function runBare(): void
{
gc_collect_cycles(); gc_collect_cycles(); gc_collect_cycles();
$memDiffs = array_fill(0, 32, -1);
$memDiffs = array_fill(0, 16 /* 64 for CI */, 0);
$mem0 = memory_get_usage();
for ($i = -1; $i < count($memDiffs); ++$i) {
$this->_runBare(); gc_collect_cycles(); gc_collect_cycles(); gc_collect_cycles();
$mem = memory_get_usage();
if ($i === -1) {
$mem1 = $mem;
} else {
if ($i !== -1) {
$memDiffs[$i] = $mem - $memPrev;
}
$memPrev = $mem;




rsort($memDiffs);
$memDiff = $memDiffs[2];


if (($mem1 - $mem0) >= 4096 * 1024 || $memDiff > 0) { // should be put inside the loop everywhere!



$memDiffs=array_filter($memDiffs);if(count($memDiffs)>1){var_dump($this->toString());print_r(array_slice($memDiffs, 0, 50));echo "\n";}

if (array_sum($memDiffs) >= 4096 * 1024 || $memDiffs[2] > 0) {
$this->onNotSuccessfulTest(new AssertionFailedError(
"Memory leak detected! (" . round($mem0 / (1024 * 1024), 3) . " MB + " . round(($mem1 - $mem0) / (1024 * 1024), 3) . " MB + " . number_format($memDiff, 0, '.', '_') . " B, " . ($i + 2) . " iterations)"
"Memory leak detected! (" . round($mem0 / 1024 / 1024, 3) . " MB + " . implode(' + ', array_map(fn ($v) => number_format($v / 1024, 3, '.', ' ') . " KB", array_filter($memDiffs))) . ", " . ($i + 2) . " iterations)"
));
}

Expand Down

0 comments on commit 98683ac

Please sign in to comment.