mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 15:30:56 +01:00
9322bcd683
Previously we simply create a lot of the target objects and check if the process crash due to OOM. Due to how we use emphemeron GC to handle memory management, which is inefficient but necessary for correctness, the tests can produce false positives as the GC isn't efficient enough to catch up with a very fast heap growth. This patch uses a new checkIfCollectable() utility to terminate the test early once we detect that any of the target object can actually be garbage collected. This should lower the chance of false positives. As a drive-by this also allows us to use setImmediate() to grow the heap even faster to make the tests run faster. PR-URL: https://github.com/nodejs/node/pull/49671 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
22 lines
615 B
JavaScript
22 lines
615 B
JavaScript
// Flags: --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 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;
|
|
}
|
|
|
|
checkIfCollectable(createSourceTextModule, 4096, 1024);
|