Skip to content

Commit 648158d

Browse files
author
pthier
committed
[test] Give more time to GC in test-shadow-realm-gc
Partial cherry-pick of nodejs#50735
1 parent 26a112e commit 648158d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

test/common/gc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const wait = require('timers/promises').setTimeout;
4+
35
// TODO(joyeecheung): merge ongc.js and gcUntil from common/index.js
46
// into this.
57

@@ -65,6 +67,15 @@ async function checkIfCollectable(
6567
createObject();
6668
}
6769

70+
// Repeat an operation and give GC some breathing room at every iteration.
71+
async function runAndBreathe(fn, repeat, waitTime = 20) {
72+
for (let i = 0; i < repeat; i++) {
73+
await fn();
74+
await wait(waitTime);
75+
}
76+
}
77+
6878
module.exports = {
6979
checkIfCollectable,
80+
runAndBreathe,
7081
};

test/parallel/test-shadow-realm-gc.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
*/
77

88
const common = require('../common');
9+
const { runAndBreathe } = require('../common/gc');
910
const assert = require('assert');
1011
const { isMainThread, Worker } = require('worker_threads');
1112

12-
for (let i = 0; i < 100; i++) {
13+
runAndBreathe(() => {
1314
const realm = new ShadowRealm();
1415
realm.evaluate('new TextEncoder(); 1;');
15-
}
16+
}, 100).then(common.mustCall());
1617

18+
//Test it in worker too.
1719
if (isMainThread) {
1820
const worker = new Worker(__filename);
1921
worker.on('exit', common.mustCall((code) => {

0 commit comments

Comments
 (0)