diff options
author | Andreas Madsen <amwebdk@gmail.com> | 2017-07-05 15:01:18 +0200 |
---|---|---|
committer | Andreas Madsen <amwebdk@gmail.com> | 2017-07-05 15:51:16 +0200 |
commit | 0fd4c73e5cda23dfb5b8e54dc11e07e547e9d576 (patch) | |
tree | fa70318bab0f9d13227fe0c68ae94ce2b7a06eee /test/async-hooks/init-hooks.js | |
parent | aa8655a0da2f5ca7937e5d73ee0c83afa464e8f3 (diff) | |
download | android-node-v8-0fd4c73e5cda23dfb5b8e54dc11e07e547e9d576.tar.gz android-node-v8-0fd4c73e5cda23dfb5b8e54dc11e07e547e9d576.tar.bz2 android-node-v8-0fd4c73e5cda23dfb5b8e54dc11e07e547e9d576.zip |
async_hooks: fix default nextTick triggerAsyncId
In the case where triggerAsyncId is null it should default to the
current executionAsyncId. This worked but as a side-effect the resource
object was changed too.
This fix also makes the null check more strict. EmitInitS is not a
documented API, thus there is no reason to be flexible in its input.
Ref: https://github.com/nodejs/node/issues/13548#issuecomment-310985270
PR-URL: https://github.com/nodejs/node/pull/14026
Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'test/async-hooks/init-hooks.js')
-rw-r--r-- | test/async-hooks/init-hooks.js | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/test/async-hooks/init-hooks.js b/test/async-hooks/init-hooks.js index 69656fdb2c..045639945c 100644 --- a/test/async-hooks/init-hooks.js +++ b/test/async-hooks/init-hooks.js @@ -34,13 +34,13 @@ class ActivityCollector { this._logid = logid; this._logtype = logtype; - // register event handlers if provided + // Register event handlers if provided this.oninit = typeof oninit === 'function' ? oninit : noop; this.onbefore = typeof onbefore === 'function' ? onbefore : noop; this.onafter = typeof onafter === 'function' ? onafter : noop; this.ondestroy = typeof ondestroy === 'function' ? ondestroy : noop; - // create the hook with which we'll collect activity data + // 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), @@ -106,10 +106,15 @@ class ActivityCollector { '\nExpected "destroy" to be called after "after"'); } } + if (!a.handleIsObject) { + v('No resource object\n' + activityString(a) + + '\nExpected "init" to be called with a resource object'); + } } if (violations.length) { - console.error(violations.join('\n')); - assert.fail(violations.length, 0, `Failed sanity checks: ${violations}`); + console.error(violations.join('\n\n') + '\n'); + assert.fail(violations.length, 0, + `${violations.length} failed sanity checks`); } } @@ -143,11 +148,11 @@ class ActivityCollector { _getActivity(uid, hook) { const h = this._activities.get(uid); if (!h) { - // if we allowed handles without init we ignore any further life time + // If we allowed handles without init we ignore any further life time // events this makes sense for a few tests in which we enable some hooks // later if (this._allowNoInit) { - const stub = { uid, type: 'Unknown' }; + const stub = { uid, type: 'Unknown', handleIsObject: true }; this._activities.set(uid, stub); return stub; } else { @@ -163,7 +168,14 @@ class ActivityCollector { } _init(uid, type, triggerAsyncId, handle) { - const activity = { uid, type, triggerAsyncId }; + const activity = { + uid, + type, + triggerAsyncId, + // In some cases (e.g. Timeout) the handle is a function, thus the usual + // `typeof handle === 'object' && handle !== null` check can't be used. + handleIsObject: handle instanceof Object + }; this._stamp(activity, 'init'); this._activities.set(uid, activity); this._maybeLog(uid, type, 'init'); |