Skip to content

test(node): Add memory leak test for LocalVariables #10080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* eslint-disable no-unused-vars */
const Sentry = require('@sentry/node');

Sentry.init({
dsn: 'https://[email protected]/1337',
includeLocalVariables: true,
beforeSend: _ => {
return null;
},
// Stop the rate limiting from kicking in
integrations: [new Sentry.Integrations.LocalVariables({ maxExceptionsPerSecond: 10000000 })],
});

class Some {
two(name) {
throw new Error('Enough!');
}
}

function one(name) {
const arr = [1, '2', null];
const obj = {
name,
num: 5,
};

const ty = new Some();

ty.two(name);
}

// Every millisecond cause a caught exception
setInterval(() => {
try {
one('some name');
} catch (e) {
//
}
}, 1);

// Every second send a memory usage update to parent process
setInterval(() => {
process.send({ memUsage: process.memoryUsage() });
}, 1000);
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,29 @@ conditionalTest({ min: 18 })('LocalVariables integration', () => {
done();
});
});

test('Should not leak memory', done => {
const testScriptPath = path.resolve(__dirname, 'local-variables-memory-test.js');

const child = childProcess.spawn('node', [testScriptPath], {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
});

let reportedCount = 0;

child.on('message', msg => {
reportedCount++;
const rssMb = msg.memUsage.rss / 1024 / 1024;
// We shouldn't use more than 100MB of memory
expect(rssMb).toBeLessThan(100);
});

// Wait for 20 seconds
setTimeout(() => {
// Ensure we've had memory usage reported at least 15 times
expect(reportedCount).toBeGreaterThan(15);
child.kill();
done();
}, 20000);
});
});