Skip to content

Commit 9880e42

Browse files
committed
test: use gcUntil to reduce flakiness in minor-ms gc perf test
Signed-off-by: Attila Szegedi <attila.szegedi@datadoghq.com>
1 parent 816b30f commit 9880e42

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

test/parallel/test-performance-gc-minor-ms.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
const common = require('../common');
99
const assert = require('assert');
10+
const { gcUntil } = require('../common/gc');
1011
const {
1112
PerformanceObserver,
1213
constants
@@ -17,17 +18,17 @@ const {
1718
NODE_PERFORMANCE_GC_FLAGS_FORCED
1819
} = constants;
1920

21+
let observed = false;
2022
const obs = new PerformanceObserver(common.mustCallAtLeast((list) => {
2123
const entry = list.getEntries()[0];
2224
assert(entry);
2325
assert.strictEqual(entry.name, 'gc');
2426
assert.strictEqual(entry.entryType, 'gc');
2527
assert.strictEqual(entry.detail.kind, NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP);
2628
assert.strictEqual(entry.detail.flags, NODE_PERFORMANCE_GC_FLAGS_FORCED);
29+
observed = true;
2730
obs.disconnect();
2831
}));
2932
obs.observe({ entryTypes: ['gc'] });
3033

31-
globalThis.gc({ type: 'minor' });
32-
// Keep the event loop alive to witness the GC async callback happen.
33-
setImmediate(() => setImmediate(() => 0));
34+
gcUntil('minor gc event', () => observed, 10, { type: 'minor' });

0 commit comments

Comments
 (0)