Skip to content

Commit

Permalink
test: use setImmediate() in test-heapdump-shadowrealm.js
Browse files Browse the repository at this point in the history
With a tight loop the GC may not have enough time to kick in.
Try setImmediate() instead.

PR-URL: #49573
Refs: #49572
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
joyeecheung authored and ruyadorno committed Sep 28, 2023
1 parent fb21062 commit c079c73
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions test/pummel/test-heapdump-shadow-realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,39 @@ require('../common');
const { validateSnapshotNodes } = require('../common/heap');

validateSnapshotNodes('Node / ShadowRealm', []);
const realm = new ShadowRealm();
{
// Create a bunch of un-referenced ShadowRealms to make sure the heap
// snapshot can handle it.
for (let i = 0; i < 100; i++) {
const realm = new 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++ < 100) {
realm = new ShadowRealm();
realm.evaluate('undefined');
setImmediate(createRealms);
} else {
validateHeap();
// Keep the realm alive.
realm.evaluate('undefined');
}
}
validateSnapshotNodes('Node / Environment', [
{
children: [
{ node_name: 'Node / shadow_realms', edge_name: 'shadow_realms' },
],
},
]);
validateSnapshotNodes('Node / shadow_realms', [
{
children: [
{ node_name: 'Node / ShadowRealm' },
],
},
]);

// 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();

0 comments on commit c079c73

Please sign in to comment.