Skip to content

Commit c079c73

Browse files
joyeecheungruyadorno
authored andcommitted
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: #49573 Refs: #49572 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent fb21062 commit c079c73

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

‎test/pummel/test-heapdump-shadow-realm.js‎

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,39 @@ require('../common');
44
const{ validateSnapshotNodes }=require('../common/heap');
55

66
validateSnapshotNodes('Node / ShadowRealm',[]);
7-
constrealm=newShadowRealm();
8-
{
9-
// Create a bunch of un-referenced ShadowRealms to make sure the heap
10-
// snapshot can handle it.
11-
for(leti=0;i<100;i++){
12-
constrealm=newShadowRealm();
7+
8+
letrealm;
9+
letcounter=0;
10+
// Create a bunch of un-referenced ShadowRealms to make sure the heap
11+
// snapshot can handle it.
12+
functioncreateRealms(){
13+
// Use setImmediate to give GC some time to kick in to avoid OOM.
14+
if(counter++<100){
15+
realm=newShadowRealm();
16+
realm.evaluate('undefined');
17+
setImmediate(createRealms);
18+
}else{
19+
validateHeap();
20+
// Keep the realm alive.
1321
realm.evaluate('undefined');
1422
}
1523
}
16-
validateSnapshotNodes('Node / Environment',[
17-
{
18-
children: [
19-
{node_name: 'Node / shadow_realms',edge_name: 'shadow_realms'},
20-
],
21-
},
22-
]);
23-
validateSnapshotNodes('Node / shadow_realms',[
24-
{
25-
children: [
26-
{node_name: 'Node / ShadowRealm'},
27-
],
28-
},
29-
]);
3024

31-
// Keep the realm alive.
32-
realm.evaluate('undefined');
25+
functionvalidateHeap(){
26+
validateSnapshotNodes('Node / Environment',[
27+
{
28+
children: [
29+
{node_name: 'Node / shadow_realms',edge_name: 'shadow_realms'},
30+
],
31+
},
32+
]);
33+
validateSnapshotNodes('Node / shadow_realms',[
34+
{
35+
children: [
36+
{node_name: 'Node / ShadowRealm'},
37+
],
38+
},
39+
]);
40+
}
41+
42+
createRealms();

0 commit comments

Comments
(0)