GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: give more time to GC in test-shadow-realm-gc-* · nodejs/node@6475cee

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test
    • common
      • gc.js
    • parallel
      • test-shadow-realm-gc-module.js
      • test-shadow-realm-gc.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/common/gc.js‎

Copy file name to clipboardExpand all lines: test/common/gc.js
+11Lines 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
};
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-shadow-realm-gc-module.js
+6-8Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88

99
const common = require('../common');
1010
const fixtures = require('../common/fixtures');
11+
const { runAndBreathe } = require('../common/gc');
1112

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

20-
main().then(common.mustCall());
15+
runAndBreathe(async () => {
16+
const realm = new ShadowRealm();
17+
await realm.importValue(mod, 'getCounter');
18+
}, 100).then(common.mustCall());
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-shadow-realm-gc.js
+4-2Lines 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 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.