Skip to content

Commit d7ea02d

Browse files
authored
test: make histogram external memory test less overfitting
The test assumes too much about V8 GC's internal mechanisms and thresholds that is no longer true on newer V8 versions and break future V8 updates. Update it to only detect the occurence of major GC to make it more future-proof and unblock V8 updates. Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com> PR-URL: #66416 Refs: #65161 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com>
1 parent a3219b6 commit d7ea02d

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

‎test/parallel/test-perf-hooks-histogram-external-memory.js‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,30 @@ const assert = require('assert');
99
const { setImmediate: setImmediatePromise } = require('timers/promises');
1010
const {
1111
PerformanceObserver,
12-
constants: { NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY },
12+
constants: { NODE_PERFORMANCE_GC_MAJOR },
1313
createHistogram,
1414
} = require('perf_hooks');
1515

16-
let externalMemoryGCs = 0;
16+
let majorGCs = 0;
1717
const observer = new PerformanceObserver((list) => {
1818
for (const entry of list.getEntries()) {
19-
if (entry.detail.flags & NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY)
20-
externalMemoryGCs++;
19+
if (entry.detail.kind === NODE_PERFORMANCE_GC_MAJOR) majorGCs++;
2120
}
2221
});
2322
observer.observe({ entryTypes: ['gc'] });
2423

2524
// With the default options, a histogram holds 45,056 64-bit counts, about
26-
// 352 KiB. V8 starts a garbage collection once external memory has grown by
27-
// 64 MiB, so 400 unreferenced snapshots (about 137 MiB) must trigger one.
25+
// 352 KiB, while its JavaScript wrapper is small. It should only
26+
// triggers a major GC if that memory is reported. The GC trigger and finalization
27+
// can vary depending on V8 internals, so only check the occurrence of a major GC here.
2828
const histogram = createHistogram();
2929
for (let i = 0; i < 400; i++) histogram.snapshot();
3030

3131
(async () => {
3232
// Performance entries for garbage collections are delivered asynchronously.
33-
for (let i = 0; i < 10 && externalMemoryGCs === 0; i++)
33+
for (let i = 0; i < 10 && majorGCs === 0; i++)
3434
await setImmediatePromise();
3535
observer.disconnect();
36-
assert.ok(externalMemoryGCs > 0,
37-
'Expected a garbage collection caused by external memory');
36+
assert.ok(majorGCs > 0,
37+
'Expected a major garbage collection caused by histogram memory');
3838
})().then(common.mustCall());

0 commit comments

Comments
 (0)