diff --git a/test/parallel/test-perf-hooks-histogram-external-memory.js b/test/parallel/test-perf-hooks-histogram-external-memory.js index 0cca4a7a8036..7e98bd206ec1 100644 --- a/test/parallel/test-perf-hooks-histogram-external-memory.js +++ b/test/parallel/test-perf-hooks-histogram-external-memory.js @@ -9,30 +9,30 @@ const assert = require('assert'); const { setImmediate: setImmediatePromise } = require('timers/promises'); const { PerformanceObserver, - constants: { NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY }, + constants: { NODE_PERFORMANCE_GC_MAJOR }, createHistogram, } = require('perf_hooks'); -let externalMemoryGCs = 0; +let majorGCs = 0; const observer = new PerformanceObserver((list) => { for (const entry of list.getEntries()) { - if (entry.detail.flags & NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY) - externalMemoryGCs++; + if (entry.detail.kind === NODE_PERFORMANCE_GC_MAJOR) majorGCs++; } }); observer.observe({ entryTypes: ['gc'] }); // With the default options, a histogram holds 45,056 64-bit counts, about -// 352 KiB. V8 starts a garbage collection once external memory has grown by -// 64 MiB, so 400 unreferenced snapshots (about 137 MiB) must trigger one. +// 352 KiB, while its JavaScript wrapper is small. It should only +// triggers a major GC if that memory is reported. The GC trigger and finalization +// can vary depending on V8 internals, so only check the occurrence of a major GC here. const histogram = createHistogram(); for (let i = 0; i < 400; i++) histogram.snapshot(); (async () => { // Performance entries for garbage collections are delivered asynchronously. - for (let i = 0; i < 10 && externalMemoryGCs === 0; i++) + for (let i = 0; i < 10 && majorGCs === 0; i++) await setImmediatePromise(); observer.disconnect(); - assert.ok(externalMemoryGCs > 0, - 'Expected a garbage collection caused by external memory'); + assert.ok(majorGCs > 0, + 'Expected a major garbage collection caused by histogram memory'); })().then(common.mustCall());