Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});