Skip to content

Commit

Permalink
test: deflake test-diagnostics-channel-memory-leak
Browse files Browse the repository at this point in the history
PR-URL: #50572
Refs: v8/v8@0fd478b
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
  • Loading branch information
joyeecheung authored and RafaelGSS committed Dec 15, 2023
1 parent fa25e06 commit ed07075
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
3 changes: 0 additions & 3 deletions test/parallel/parallel.status
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 14 additions & 16 deletions test/parallel/test-diagnostics-channel-memory-leak.js
Original file line number Diff line number Diff line change
@@ -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());

0 comments on commit ed07075

Please sign in to comment.