From 7b25cb811a00007c030e28fc5fcbef838b19746a Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 30 Sep 2026 19:49:14 +0200 Subject: [PATCH] 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 PR-URL: https://github.com/nodejs/node/pull/66416 Refs: https://github.com/nodejs/node/pull/65161 Reviewed-By: James M Snell Reviewed-By: Filip Skokan Reviewed-By: Richard Lau --- ...est-perf-hooks-histogram-external-memory.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-perf-hooks-histogram-external-memory.js b/test/parallel/test-perf-hooks-histogram-external-memory.js index 0cca4a7a803..7e98bd206ec 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());