diff options
author | Anna Henningsen <anna@addaleax.net> | 2017-06-09 21:27:02 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-06-16 19:27:29 +0200 |
commit | af1a551965ac990e91fa5924d95e99450a6f0814 (patch) | |
tree | ff9222bece924736f6519e5b8bf19966a6700305 /test/addons/async-hooks-promise | |
parent | 6e2c29bcabb0507262167494a1fd9bc583cae690 (diff) | |
download | android-node-v8-af1a551965ac990e91fa5924d95e99450a6f0814.tar.gz android-node-v8-af1a551965ac990e91fa5924d95e99450a6f0814.tar.bz2 android-node-v8-af1a551965ac990e91fa5924d95e99450a6f0814.zip |
async_hooks: proper id stacking for Promises
Until now, the async_hooks PromiseHook did not register the Promise’s
async id and trigger id on the id stack, so inside the `.then()` handler
those ids would be invalid.
To fix this, add push and pop calls to its `before` and `after` parts,
respectively. Some care needs to be taken for the cases that the
Promise hook is being disabled or enabled during the execution
of a Promise handler; in the former case, actually removing the hook
is delayed by adding another task to the microtask queue, in the latter
case popping the id off the async id stack is skipped if the ids don’t
match.
Fixes: https://github.com/nodejs/node/issues/13583
PR-URL: https://github.com/nodejs/node/pull/13585
Reviewed-By: Trevor Norris <trevnorris@gmail.com>
Diffstat (limited to 'test/addons/async-hooks-promise')
-rw-r--r-- | test/addons/async-hooks-promise/test.js | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/test/addons/async-hooks-promise/test.js b/test/addons/async-hooks-promise/test.js index bbe11dd3c5..b0af8806bd 100644 --- a/test/addons/async-hooks-promise/test.js +++ b/test/addons/async-hooks-promise/test.js @@ -36,8 +36,12 @@ assert.strictEqual( hook1.disable(); -// Check that internal fields are no longer being set. -assert.strictEqual( - binding.getPromiseField(Promise.resolve(1)), - 0, - 'Promise internal field used despite missing enabled AsyncHook'); +// Check that internal fields are no longer being set. This needs to be delayed +// a bit because the `disable()` call only schedules disabling the hook in a +// future microtask. +setImmediate(() => { + assert.strictEqual( + binding.getPromiseField(Promise.resolve(1)), + 0, + 'Promise internal field used despite missing enabled AsyncHook'); +}); |