From 1d8e65a23097ee99cfe581176fc8a91b0a8752d5 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 22 Jan 2024 19:53:11 +0800 Subject: [PATCH] test: use checkIfCollectableByCounting in SourceTextModule leak test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...which may be more reliable than than checkIfCollectable(). PR-URL: https://github.com/nodejs/node/pull/51512 Refs: https://github.com/nodejs/node/pull/51362 Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca Reviewed-By: Michaƫl Zasso --- .../test-vm-source-text-module-leak.js | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/test/es-module/test-vm-source-text-module-leak.js b/test/es-module/test-vm-source-text-module-leak.js index d05e812ac32c95..6e770f897528b4 100644 --- a/test/es-module/test-vm-source-text-module-leak.js +++ b/test/es-module/test-vm-source-text-module-leak.js @@ -1,21 +1,24 @@ -// Flags: --experimental-vm-modules --max-old-space-size=16 --trace-gc +// Flags: --expose-internals --experimental-vm-modules --max-old-space-size=16 --trace-gc 'use strict'; // This tests that vm.SourceTextModule() does not leak. // See: https://github.com/nodejs/node/issues/33439 -require('../common'); -const { checkIfCollectable } = require('../common/gc'); +const common = require('../common'); +const { checkIfCollectableByCounting } = require('../common/gc'); const vm = require('vm'); -async function createSourceTextModule() { - // Try to reach the maximum old space size. - const m = new vm.SourceTextModule(` - const bar = new Array(512).fill("----"); - export { bar }; - `); - await m.link(() => {}); - await m.evaluate(); - return m; -} +const outer = 32; +const inner = 128; -checkIfCollectable(createSourceTextModule, 4096, 1024); +checkIfCollectableByCounting(async (i) => { + for (let j = 0; j < inner; j++) { + // Try to reach the maximum old space size. + const m = new vm.SourceTextModule(` + const bar = new Array(512).fill("----"); + export { bar }; + `); + await m.link(() => {}); + await m.evaluate(); + } + return inner; +}, vm.SourceTextModule, outer).then(common.mustCall());