Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
async_hooks,test: enhance initHooks with promiseResolve hook
Add ability to initHooks and to checkInvocations utilities to transmit
promiseResolve hook as well.

Refs: #20516
  • Loading branch information
MayaLekova committed May 11, 2018
commit 35b8fcf568162dfb8e5a393c0d8f10d0c4c70c80
2 changes: 1 addition & 1 deletion test/async-hooks/hook-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.checkInvocations = function checkInvocations(activity, hooks, stage) {
);

// Check that actual invocations for all hooks match the expected invocations
[ 'init', 'before', 'after', 'destroy' ].forEach(checkHook);
[ 'init', 'before', 'after', 'destroy', 'promiseResolve' ].forEach(checkHook);

function checkHook(k) {
const val = hooks[k];
Expand Down
15 changes: 14 additions & 1 deletion test/async-hooks/init-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ActivityCollector {
onbefore,
onafter,
ondestroy,
onpromiseResolve,
logid = null,
logtype = null
} = {}) {
Expand All @@ -39,13 +40,16 @@ class ActivityCollector {
this.onbefore = typeof onbefore === 'function' ? onbefore : noop;
this.onafter = typeof onafter === 'function' ? onafter : noop;
this.ondestroy = typeof ondestroy === 'function' ? ondestroy : noop;
this.onpromiseResolve = typeof onpromiseResolve === 'function' ?
onpromiseResolve : noop;

// Create the hook with which we'll collect activity data
this._asyncHook = async_hooks.createHook({
init: this._init.bind(this),
before: this._before.bind(this),
after: this._after.bind(this),
destroy: this._destroy.bind(this)
destroy: this._destroy.bind(this),
promiseResolve: this._promiseResolve.bind(this)
});
}

Expand Down Expand Up @@ -206,6 +210,13 @@ class ActivityCollector {
this.ondestroy(uid);
}

_promiseResolve(uid) {
const h = this._getActivity(uid, 'promiseResolve');
this._stamp(h, 'promiseResolve');
this._maybeLog(uid, h && h.type, 'promiseResolve');
this.onpromiseResolve(uid);
}

_maybeLog(uid, type, name) {
if (this._logid &&
(type == null || this._logtype == null || this._logtype === type)) {
Expand All @@ -219,6 +230,7 @@ exports = module.exports = function initHooks({
onbefore,
onafter,
ondestroy,
onpromiseResolve,
allowNoInit,
logid,
logtype
Expand All @@ -228,6 +240,7 @@ exports = module.exports = function initHooks({
onbefore,
onafter,
ondestroy,
onpromiseResolve,
allowNoInit,
logid,
logtype
Expand Down