From 5ac658102d8f84a4c3e00e3c54e89dc9784c3394 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 3 Nov 2023 22:53:24 +0000 Subject: [PATCH] test: deflake test-diagnostics-channel-memory-leak PR-URL: https://github.com/nodejs/node/pull/50572 Refs: https://github.com/v8/v8/commit/0fd478bcdabd3400d9d74c47c4883c085ef37d18 Reviewed-By: Geoffrey Booth Reviewed-By: Stephen Belanger --- test/parallel/parallel.status | 3 -- .../test-diagnostics-channel-memory-leak.js | 30 +++++++++---------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index 838d465b596f9f..98288c5c1228c2 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -5,9 +5,6 @@ prefix parallel # sample-test : PASS,FLAKY [true] # This section applies to all platforms -# https://github.com/nodejs/node/pull/50327 -# Currently there's no reliable way to test it. -test-diagnostics-channel-memory-leak: SKIP [$system==win32] # https://github.com/nodejs/node/issues/41206 diff --git a/test/parallel/test-diagnostics-channel-memory-leak.js b/test/parallel/test-diagnostics-channel-memory-leak.js index 9e6364d168562f..fe50158070554d 100644 --- a/test/parallel/test-diagnostics-channel-memory-leak.js +++ b/test/parallel/test-diagnostics-channel-memory-leak.js @@ -1,24 +1,22 @@ -// Flags: --expose-gc +// Flags: --expose-internals --max-old-space-size=16 'use strict'; // This test ensures that diagnostic channel references aren't leaked. -require('../common'); -const { ok } = require('assert'); +const common = require('../common'); -const { subscribe, unsubscribe } = require('diagnostics_channel'); +const { subscribe, unsubscribe, Channel } = require('diagnostics_channel'); +const { checkIfCollectableByCounting } = require('../common/gc'); function noop() {} -const heapUsedBefore = process.memoryUsage().heapUsed; - -for (let i = 0; i < 1000; i++) { - subscribe(String(i), noop); - unsubscribe(String(i), noop); -} - -global.gc(); - -const heapUsedAfter = process.memoryUsage().heapUsed; - -ok(heapUsedBefore >= heapUsedAfter); +const outer = 64; +const inner = 256; +checkIfCollectableByCounting((i) => { + for (let j = 0; j < inner; j++) { + const key = String(i * inner + j); + subscribe(key, noop); + unsubscribe(key, noop); + } + return inner; +}, Channel, outer).then(common.mustCall());