GeezerVison is showing github.com — test: use checkIfCollectable in vm leak tests · nodejs/node@355f10d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-vm-compile-function-leak.js +5-8Lines changed: 5 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | // This tests that vm.compileFunction with dynamic import callback does not leak. | 5 | 5 | // See https://github.com/nodejs/node/issues/44211 | 6 | 6 | require('../common'); | | 7 | +const { checkIfCollectable } = require('../common/gc'); | 7 | 8 | const vm = require('vm'); | 8 | | -let count = 0; | 9 | 9 |
| 10 | | -function main() { | 11 | | - // Try to reach the maximum old space size. | 12 | | - vm.compileFunction(`"${Math.random().toString().repeat(512)}"`, [], { | | 10 | +async function createCompiledFunction() { | | 11 | + return vm.compileFunction(`"${Math.random().toString().repeat(512)}"`, [], { | 13 | 12 | async importModuleDynamically() {}, | 14 | 13 | }); | 15 | | - if (count++ < 2048) { | 16 | | - setTimeout(main, 1); | 17 | | - } | 18 | 14 | } | 19 | | -main(); | | 15 | + | | 16 | +checkIfCollectable(createCompiledFunction, 2048); |
Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-vm-contextified-script-leak.js +4-7Lines changed: 4 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | // This tests that vm.Script with dynamic import callback does not leak. | 5 | 5 | // See: https://github.com/nodejs/node/issues/33439 | 6 | 6 | require('../common'); | | 7 | +const { checkIfCollectable } = require('../common/gc'); | 7 | 8 | const vm = require('vm'); | 8 | | -let count = 0; | 9 | 9 |
| 10 | | -function main() { | | 10 | +async function createContextifyScript() { | 11 | 11 | // Try to reach the maximum old space size. | 12 | | - new vm.Script(`"${Math.random().toString().repeat(512)}";`, { | | 12 | + return new vm.Script(`"${Math.random().toString().repeat(512)}";`, { | 13 | 13 | async importModuleDynamically() {}, | 14 | 14 | }); | 15 | | - if (count++ < 2 * 1024) { | 16 | | - setTimeout(main, 1); | 17 | | - } | 18 | 15 | } | 19 | | -main(); | | 16 | +checkIfCollectable(createContextifyScript, 2048); |
Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-vm-source-text-module-leak.js +8-10Lines changed: 8 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | // This tests that vm.SourceTextModule() does not leak. | 5 | 5 | // See: https://github.com/nodejs/node/issues/33439 | 6 | 6 | require('../common'); | 7 | | - | | 7 | +const { checkIfCollectable } = require('../common/gc'); | 8 | 8 | const vm = require('vm'); | 9 | | -let count = 0; | 10 | | -async function createModule() { | | 9 | + | | 10 | +async function createSourceTextModule() { | 11 | 11 | // Try to reach the maximum old space size. | 12 | 12 | const m = new vm.SourceTextModule(` | 13 | | - const bar = new Array(512).fill("----"); | 14 | | - export { bar }; | 15 | | -`); | | 13 | + const bar = new Array(512).fill("----"); | | 14 | + export { bar }; | | 15 | + `); | 16 | 16 | await m.link(() => {}); | 17 | 17 | await m.evaluate(); | 18 | | - if (count++ < 4096) { | 19 | | - setTimeout(createModule, 1); | 20 | | - } | 21 | 18 | return m; | 22 | 19 | } | 23 | | -createModule(); | | 20 | + | | 21 | +checkIfCollectable(createSourceTextModule, 4096, 1024); |
Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-vm-synthetic-module-leak.js +3-8Lines changed: 3 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | // This tests that vm.SyntheticModule does not leak. | 5 | 5 | // See https://github.com/nodejs/node/issues/44211 | 6 | 6 | require('../common'); | | 7 | +const { checkIfCollectable } = require('../common/gc'); | 7 | 8 | const vm = require('vm'); | 8 | 9 |
| 9 | | -let count = 0; | 10 | | -async function createModule() { | 11 | | - // Try to reach the maximum old space size. | | 10 | +async function createSyntheticModule() { | 12 | 11 | const m = new vm.SyntheticModule(['bar'], () => { | 13 | 12 | m.setExport('bar', new Array(512).fill('----')); | 14 | 13 | }); | 15 | 14 | await m.link(() => {}); | 16 | 15 | await m.evaluate(); | 17 | | - if (count++ < 4 * 1024) { | 18 | | - setTimeout(createModule, 1); | 19 | | - } | 20 | 16 | return m; | 21 | 17 | } | 22 | | - | 23 | | -createModule(); | | 18 | +checkIfCollectable(createSyntheticModule, 4096); |
|