node/test/pummel/test-heapdump-shadow-realm.js
Chengzhong Wu 224f3ae974
test: reduce number of repetition in test-heapdump-shadowrealm.js
ShadowRealm garbage-collection is covered in another test. Reduce the
number of repetition in test-heapdump-shadowrealm.js trying to fix the
flakiness of the test.

PR-URL: https://github.com/nodejs/node/pull/50104
Refs: https://github.com/nodejs/node/issues/49572
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2023-10-12 09:32:42 +00:00

43 lines
999 B
JavaScript

// Flags: --experimental-shadow-realm --expose-internals
'use strict';
require('../common');
const { validateSnapshotNodes } = require('../common/heap');
validateSnapshotNodes('Node / ShadowRealm', []);
let realm;
let counter = 0;
// Create a bunch of un-referenced ShadowRealms to make sure the heap
// snapshot can handle it.
function createRealms() {
// Use setImmediate to give GC some time to kick in to avoid OOM.
if (counter++ < 10) {
realm = new ShadowRealm();
realm.evaluate('undefined');
setImmediate(createRealms);
} else {
validateHeap();
// Keep the realm alive.
realm.evaluate('undefined');
}
}
function validateHeap() {
validateSnapshotNodes('Node / Environment', [
{
children: [
{ node_name: 'Node / shadow_realms', edge_name: 'shadow_realms' },
],
},
]);
validateSnapshotNodes('Node / shadow_realms', [
{
children: [
{ node_name: 'Node / ShadowRealm' },
],
},
]);
}
createRealms();