node/test/parallel/test-shadow-realm-gc.js
Joyee Cheung c5eb2c4190
test: give more time to GC in test-shadow-realm-gc-*
When --node-builtin-modules-path is used, we read and create
new strings for builtins in each realm which increases the memory
usage. As a result GC may not be able to keep up with the
allocation done in the loop in the test.

As a workaround, give GC a bit more time by waiting for a timer
in the loop.

PR-URL: https://github.com/nodejs/node/pull/50735
Refs: https://github.com/nodejs/node/issues/50726
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2023-11-17 16:09:30 +01:00

25 lines
651 B
JavaScript

// Flags: --experimental-shadow-realm --max-old-space-size=20
'use strict';
/**
* Verifying ShadowRealm instances can be correctly garbage collected.
*/
const common = require('../common');
const { runAndBreathe } = require('../common/gc');
const assert = require('assert');
const { isMainThread, Worker } = require('worker_threads');
runAndBreathe(() => {
const realm = new ShadowRealm();
realm.evaluate('new TextEncoder(); 1;');
}, 100).then(common.mustCall());
// Test it in worker too.
if (isMainThread) {
const worker = new Worker(__filename);
worker.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}));
}