node/test/es-module/test-vm-contextified-script-leak.js
Joyee Cheung 017998971b
test: deflake test-vm-contextified-script-leak
Similar to the test-vm-source-text-module-leak fix, use a snapshot
to force a thorough GC in order to prevent false positives.

PR-URL: https://github.com/nodejs/node/pull/49710
Refs: https://github.com/nodejs/reliability/issues/669
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2023-09-23 03:46:22 +00:00

17 lines
552 B
JavaScript

// Flags: --max-old-space-size=16 --trace-gc
'use strict';
// This tests that vm.Script with dynamic import callback does not leak.
// See: https://github.com/nodejs/node/issues/33439
require('../common');
const { checkIfCollectable } = require('../common/gc');
const vm = require('vm');
async function createContextifyScript() {
// Try to reach the maximum old space size.
return new vm.Script(`"${Math.random().toString().repeat(512)}";`, {
async importModuleDynamically() {},
});
}
checkIfCollectable(createContextifyScript, 2048, 512);