From a8db32a5042782c5426e229f466ba80bf5995c9d Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 22 Aug 2020 15:50:30 -0700 Subject: [PATCH] test: simplify test-vm-memleak PR-URL: https://github.com/nodejs/node/pull/34881 Reviewed-By: James M Snell Reviewed-By: Franziska Hinkelmann --- test/pummel/test-vm-memleak.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/pummel/test-vm-memleak.js b/test/pummel/test-vm-memleak.js index 33f2f3d75905a5..a433ab6565e147 100644 --- a/test/pummel/test-vm-memleak.js +++ b/test/pummel/test-vm-memleak.js @@ -27,7 +27,6 @@ const assert = require('assert'); const vm = require('vm'); const start = Date.now(); -let maxMem = 0; const interval = setInterval(function() { try { @@ -36,10 +35,11 @@ const interval = setInterval(function() { } const rss = process.memoryUsage().rss; - maxMem = Math.max(rss, maxMem); + assert.ok(rss < 64 * 1024 * 1024, + `memory usage: ${Math.round(rss / (1024 * 1024))}Mb`); + // Stop after 5 seconds. if (Date.now() - start > 5 * 1000) { - // wait 10 seconds. clearInterval(interval); testContextLeak(); @@ -47,11 +47,8 @@ const interval = setInterval(function() { }, 1); function testContextLeak() { + // TODO: This needs a comment explaining what it's doing. Will it crash the + // test if there is a memory leak? Or what? for (let i = 0; i < 1000; i++) vm.createContext({}); } - -process.on('exit', function() { - console.error(`max mem: ${Math.round(maxMem / (1024 * 1024))}mb`); - assert.ok(maxMem < 64 * 1024 * 1024); -});