From e961615c57d448cb6017109a0a65673b00c6b4a6 Mon Sep 17 00:00:00 2001 From: Sergey Chernyshev Date: Thu, 25 Apr 2024 04:20:28 +0200 Subject: [PATCH] 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 Reviewed-By: Luigi Pinca --- .../test/parallel/test-v8-serialize-leak.js | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/graal-nodejs/test/parallel/test-v8-serialize-leak.js b/graal-nodejs/test/parallel/test-v8-serialize-leak.js index 696dbfea65b..89b36c4a248 100644 --- a/graal-nodejs/test/parallel/test-v8-serialize-leak.js +++ b/graal-nodejs/test/parallel/test-v8-serialize-leak.js @@ -8,7 +8,6 @@ if (common.isIBMi) common.skip('On IBMi, the rss memory always returns zero'); const v8 = require('v8'); -const assert = require('assert'); const before = process.memoryUsage.rss(); @@ -16,14 +15,19 @@ for (let i = 0; i < 1000000; i++) { v8.serialize(''); } -global.gc(); - -const after = process.memoryUsage.rss(); - -if (process.config.variables.asan) { - assert(after < before * 10, `asan: before=${before} after=${after}`); -} else if (process.config.variables.node_builtin_modules_path) { - assert(after < before * 4, `node_builtin_modules_path: before=${before} after=${after}`); -} else { - assert(after < before * 2, `before=${before} after=${after}`); +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();