Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: give more time to GC in test-shadow-realm-gc-* #50735

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/common/gc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const wait = require('timers/promises').setTimeout;

// TODO(joyeecheung): merge ongc.js and gcUntil from common/index.js
// into this.

Expand Down Expand Up @@ -65,6 +67,15 @@ async function checkIfCollectable(
createObject();
}

// Repeat an operation and give GC some breathing room at every iteration.
async function runAndBreathe(fn, repeat, waitTime = 20) {
for (let i = 0; i < repeat; i++) {
await fn();
await wait(waitTime);
}
}

module.exports = {
checkIfCollectable,
runAndBreathe,
};
14 changes: 6 additions & 8 deletions test/parallel/test-shadow-realm-gc-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@

const common = require('../common');
const fixtures = require('../common/fixtures');
const { runAndBreathe } = require('../common/gc');

async function main() {
const mod = fixtures.fileURL('es-module-shadow-realm', 'state-counter.mjs');
for (let i = 0; i < 100; i++) {
const realm = new ShadowRealm();
await realm.importValue(mod, 'getCounter');
}
}
const mod = fixtures.fileURL('es-module-shadow-realm', 'state-counter.mjs');

main().then(common.mustCall());
runAndBreathe(async () => {
const realm = new ShadowRealm();
await realm.importValue(mod, 'getCounter');
}, 100).then(common.mustCall());
6 changes: 4 additions & 2 deletions test/parallel/test-shadow-realm-gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
*/

const common = require('../common');
const { runAndBreathe } = require('../common/gc');
const assert = require('assert');
const { isMainThread, Worker } = require('worker_threads');

for (let i = 0; i < 100; i++) {
runAndBreathe(() => {
const realm = new ShadowRealm();
realm.evaluate('new TextEncoder(); 1;');
}
}, 100).then(common.mustCall());

// Test it in worker too.
if (isMainThread) {
const worker = new Worker(__filename);
worker.on('exit', common.mustCall((code) => {
Expand Down