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
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: test/common/gc.js +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | 'use strict'; |
2 | 2 |
|
| 3 | +const wait = require('timers/promises').setTimeout; |
| 4 | + |
3 | 5 | // TODO(joyeecheung): merge ongc.js and gcUntil from common/index.js |
4 | 6 | // into this. |
5 | 7 |
|
@@ -65,6 +67,15 @@ async function checkIfCollectable( |
65 | 67 | createObject(); |
66 | 68 | } |
67 | 69 |
|
| 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 | + |
68 | 78 | module.exports = { |
69 | 79 | checkIfCollectable, |
| 80 | + runAndBreathe, |
70 | 81 | }; |
Collapse file
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 number | Diff line number | Diff line change |
|---|
|
8 | 8 |
|
9 | 9 | const common = require('../common'); |
10 | 10 | const fixtures = require('../common/fixtures'); |
| 11 | +const { runAndBreathe } = require('../common/gc'); |
11 | 12 |
|
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'); |
19 | 14 |
|
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
Copy file name to clipboardExpand all lines: test/parallel/test-shadow-realm-gc.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
6 | 6 | */ |
7 | 7 |
|
8 | 8 | const common = require('../common'); |
| 9 | +const { runAndBreathe } = require('../common/gc'); |
9 | 10 | const assert = require('assert'); |
10 | 11 | const { isMainThread, Worker } = require('worker_threads'); |
11 | 12 |
|
12 | | -for (let i = 0; i < 100; i++) { |
| 13 | +runAndBreathe(() => { |
13 | 14 | const realm = new ShadowRealm(); |
14 | 15 | realm.evaluate('new TextEncoder(); 1;'); |
15 | | -} |
| 16 | +}, 100).then(common.mustCall()); |
16 | 17 |
|
| 18 | +// Test it in worker too. |
17 | 19 | if (isMainThread) { |
18 | 20 | const worker = new Worker(__filename); |
19 | 21 | worker.on('exit', common.mustCall((code) => { |
|