Skip to content

Commit

Permalink
test: simplify test-vm-memleak
Browse files Browse the repository at this point in the history
PR-URL: #34881
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
  • Loading branch information
Trott committed Aug 25, 2020
1 parent b93325c commit a8db32a
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions test/pummel/test-vm-memleak.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const assert = require('assert');
const vm = require('vm');

const start = Date.now();
let maxMem = 0;

const interval = setInterval(function() {
try {
Expand All @@ -36,22 +35,20 @@ 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();
}
}, 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);
});

0 comments on commit a8db32a

Please sign in to comment.