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 <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
  • Loading branch information
Trott authored and addaleax committed Sep 22, 2020
1 parent 9b53b4d commit 76d991c
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 76d991c

Please sign in to comment.