Skip to content

Commit ce9d264

Browse files
committed
test: deflake test-diagnostics-channel-memory-leak
1 parent 23849a8 commit ce9d264

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

test/parallel/parallel.status

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ prefix parallel
55
# sample-test : PASS,FLAKY
66

77
[true] # This section applies to all platforms
8-
# https://github.com/nodejs/node/pull/50327
9-
# Currently there's no reliable way to test it.
10-
test-diagnostics-channel-memory-leak: SKIP
118

129
[$system==win32]
1310
# https://github.com/nodejs/node/issues/41206
Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
1-
// Flags: --expose-gc
1+
// Flags: --expose-internals --expose-internals --max-old-space-size=16
22
'use strict';
33

44
// This test ensures that diagnostic channel references aren't leaked.
55

66
require('../common');
7-
const { ok } = require('assert');
8-
9-
const { subscribe, unsubscribe } = require('diagnostics_channel');
7+
const assert = require('assert');
108

9+
const { subscribe, unsubscribe, Channel } = require('diagnostics_channel');
10+
const { internalBinding } = require('internal/test/binding');
11+
const { countObjectsWithPrototype } = internalBinding('heap_utils');
1112
function noop() {}
1213

13-
const heapUsedBefore = process.memoryUsage().heapUsed;
14-
15-
for (let i = 0; i < 1000; i++) {
16-
subscribe(String(i), noop);
17-
unsubscribe(String(i), noop);
14+
const initialCount = countObjectsWithPrototype(Channel.prototype);
15+
console.log('Initial count of diagnostics channels', initialCount);
16+
const outer = 1024;
17+
const inner = 16;
18+
let finished = 0;
19+
20+
for (let i = 0; i < outer; i++) {
21+
setImmediate(() => {
22+
for (let j = 0; j < inner; j++) {
23+
const key = String(i * inner + j);
24+
subscribe(key, noop);
25+
unsubscribe(key, noop);
26+
}
27+
if (++finished === outer) {
28+
setImmediate(check);
29+
}
30+
});
1831
}
1932

20-
global.gc();
21-
22-
const heapUsedAfter = process.memoryUsage().heapUsed;
23-
24-
ok(heapUsedBefore >= heapUsedAfter);
33+
function check() {
34+
const afterCount = countObjectsWithPrototype(Channel.prototype);
35+
console.log('Ending count of diagnostics channels', afterCount);
36+
const remaining = afterCount - initialCount;
37+
console.log('Remaining count of diagnostics channels', remaining);
38+
console.log('Number of channels created', inner * outer);
39+
assert(remaining < inner * outer);
40+
}

0 commit comments

Comments
 (0)