Skip to content

Commit 4a6995c

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 4a6995c

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,30 @@
77

88
const common = require('../common');
99
const assert = require('assert');
10+
const { gcUntil } = require('../common/gc');
1011
const {
1112
PerformanceObserver,
1213
constants
1314
} = require('perf_hooks');
1415

1516
const {
16-
NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP,
17-
NODE_PERFORMANCE_GC_FLAGS_FORCED
17+
NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP
1818
} = constants;
1919

20+
let observed = false;
2021
const obs = new PerformanceObserver(common.mustCallAtLeast((list) => {
21-
const entry = list.getEntries()[0];
22-
assert(entry);
23-
assert.strictEqual(entry.name, 'gc');
24-
assert.strictEqual(entry.entryType, 'gc');
25-
assert.strictEqual(entry.detail.kind, NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP);
26-
assert.strictEqual(entry.detail.flags, NODE_PERFORMANCE_GC_FLAGS_FORCED);
27-
obs.disconnect();
22+
for (const entry of list.getEntries()) {
23+
// Other GC kinds (e.g. a scheduled or incremental GC) may be observed in
24+
// between; only the minor mark-sweep entry is relevant here.
25+
if (entry.detail.kind === NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP) {
26+
assert.strictEqual(entry.name, 'gc');
27+
assert.strictEqual(entry.entryType, 'gc');
28+
observed = true;
29+
obs.disconnect();
30+
return;
31+
}
32+
}
2833
}));
2934
obs.observe({ entryTypes: ['gc'] });
3035

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

0 commit comments

Comments
 (0)