Skip to content

Commit 1d8e65a

Browse files
joyeecheungrichardlau
authored andcommitted
test: use checkIfCollectableByCounting in SourceTextModule leak test
...which may be more reliable than than checkIfCollectable(). PR-URL: #51512 Refs: #51362 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 1c47da1 commit 1d8e65a

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
// Flags: --experimental-vm-modules --max-old-space-size=16 --trace-gc
1+
// Flags: --expose-internals --experimental-vm-modules --max-old-space-size=16 --trace-gc
22
'use strict';
33

44
// This tests that vm.SourceTextModule() does not leak.
55
// See: https://github.com/nodejs/node/issues/33439
6-
require('../common');
7-
const { checkIfCollectable } = require('../common/gc');
6+
const common = require('../common');
7+
const { checkIfCollectableByCounting } = require('../common/gc');
88
const vm = require('vm');
99

10-
async function createSourceTextModule() {
11-
// Try to reach the maximum old space size.
12-
const m = new vm.SourceTextModule(`
13-
const bar = new Array(512).fill("----");
14-
export { bar };
15-
`);
16-
await m.link(() => {});
17-
await m.evaluate();
18-
return m;
19-
}
10+
const outer = 32;
11+
const inner = 128;
2012

21-
checkIfCollectable(createSourceTextModule, 4096, 1024);
13+
checkIfCollectableByCounting(async (i) => {
14+
for (let j = 0; j < inner; j++) {
15+
// Try to reach the maximum old space size.
16+
const m = new vm.SourceTextModule(`
17+
const bar = new Array(512).fill("----");
18+
export { bar };
19+
`);
20+
await m.link(() => {});
21+
await m.evaluate();
22+
}
23+
return inner;
24+
}, vm.SourceTextModule, outer).then(common.mustCall());

0 commit comments

Comments
 (0)