mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: use setImmediate() in test-heapdump-shadowrealm.js
With a tight loop the GC may not have enough time to kick in. Try setImmediate() instead. PR-URL: https://github.com/nodejs/node/pull/49573 Refs: https://github.com/nodejs/node/issues/49572 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
parent
17a9bfbe79
commit
dca4d84349
@ -4,29 +4,39 @@ require('../common');
|
|||||||
const { validateSnapshotNodes } = require('../common/heap');
|
const { validateSnapshotNodes } = require('../common/heap');
|
||||||
|
|
||||||
validateSnapshotNodes('Node / ShadowRealm', []);
|
validateSnapshotNodes('Node / ShadowRealm', []);
|
||||||
const realm = new ShadowRealm();
|
|
||||||
{
|
let realm;
|
||||||
// Create a bunch of un-referenced ShadowRealms to make sure the heap
|
let counter = 0;
|
||||||
// snapshot can handle it.
|
// Create a bunch of un-referenced ShadowRealms to make sure the heap
|
||||||
for (let i = 0; i < 100; i++) {
|
// snapshot can handle it.
|
||||||
const realm = new ShadowRealm();
|
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');
|
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.
|
function validateHeap() {
|
||||||
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' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
createRealms();
|
||||||
|
Loading…
Reference in New Issue
Block a user