node/test/parallel/test-v8-serialize-leak.js
Joyee Cheung 1f2ad05600
test: use gcUntil() in test-v8-serialize-leak
Previously this can be flaky because the there could be a delay
of the deallocation after gc() is invoked. Use gcUntil() to run
the GC multiple times to make the test more robust.

PR-URL: https://github.com/nodejs/node/pull/49168
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-08-18 11:17:24 +00:00

34 lines
881 B
JavaScript

'use strict';
// Flags: --expose-gc
const common = require('../common');
// On IBMi, the rss memory always returns zero
if (common.isIBMi)
common.skip('On IBMi, the rss memory always returns zero');
const v8 = require('v8');
const before = process.memoryUsage.rss();
for (let i = 0; i < 1000000; i++) {
v8.serialize('');
}
async function main() {
await common.gcUntil('RSS should go down', () => {
const after = process.memoryUsage.rss();
if (process.config.variables.asan) {
console.log(`asan: before=${before} after=${after}`);
return after < before * 10;
} else if (process.config.variables.node_builtin_modules_path) {
console.log(`node_builtin_modules_path: before=${before} after=${after}`);
return after < before * 10;
}
console.log(`before=${before} after=${after}`);
return after < before * 10;
});
}
main();