-
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: move common.onGC to individual module
Incrementally making `require('../common')` less of a monolith. Move the `common.onGC()` utility to a separate standalone module that is only imported when it's actually needed. PR-URL: #22446 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
- Loading branch information
Showing
11 changed files
with
81 additions
and
57 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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const gcTrackerMap = new WeakMap(); | ||
const gcTrackerTag = 'NODE_TEST_COMMON_GC_TRACKER'; | ||
|
||
function onGC(obj, gcListener) { | ||
const async_hooks = require('async_hooks'); | ||
|
||
const onGcAsyncHook = async_hooks.createHook({ | ||
init: common.mustCallAtLeast(function(id, type) { | ||
if (this.trackedId === undefined) { | ||
assert.strictEqual(type, gcTrackerTag); | ||
this.trackedId = id; | ||
} | ||
}), | ||
destroy(id) { | ||
assert.notStrictEqual(this.trackedId, -1); | ||
if (id === this.trackedId) { | ||
this.gcListener.ongc(); | ||
onGcAsyncHook.disable(); | ||
} | ||
} | ||
}).enable(); | ||
onGcAsyncHook.gcListener = gcListener; | ||
|
||
gcTrackerMap.set(obj, new async_hooks.AsyncResource(gcTrackerTag)); | ||
obj = null; | ||
} | ||
|
||
module.exports = onGC; |
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,15 +1,14 @@ | ||
'use strict'; | ||
// Flags: --expose-gc | ||
const common = require('../common'); | ||
const onGC = require('../common/ongc'); | ||
|
||
{ | ||
const gcListener = { ongc: common.mustCall() }; | ||
common.onGC({}, gcListener); | ||
onGC({}, { ongc: common.mustCall() }); | ||
global.gc(); | ||
} | ||
|
||
{ | ||
const gcListener = { ongc: common.mustNotCall() }; | ||
common.onGC(process, gcListener); | ||
onGC(process, { ongc: common.mustNotCall() }); | ||
global.gc(); | ||
} |
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
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
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
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