-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: deflake test-diagnostics-channel-memory-leak
- Loading branch information
1 parent
1890d72
commit 0f4391f
Showing
2 changed files
with
14 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |