diff options
author | Anna Henningsen <anna@addaleax.net> | 2017-05-26 17:00:43 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-05-28 17:13:01 +0200 |
commit | 90877003c177368792f38284561d3b4299bfae88 (patch) | |
tree | 29caf8df2b8e1dfc5d0c8ca1974d343d50ee456c /test/parallel/test-async-wrap-promise-after-enabled.js | |
parent | 849f22309a3e612dd4b9483db32713f7e759215b (diff) | |
download | android-node-v8-90877003c177368792f38284561d3b4299bfae88.tar.gz android-node-v8-90877003c177368792f38284561d3b4299bfae88.tar.bz2 android-node-v8-90877003c177368792f38284561d3b4299bfae88.zip |
async_wrap: fix Promises with later enabled hooks
Assign a `PromiseWrap` instance to Promises that do not have one
yet when the PromiseHook is being called.
Fixes: https://github.com/nodejs/node/issues/13237
PR-URL: https://github.com/nodejs/node/pull/13242
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Reviewed-By: Matthew Loring <mattloring@google.com>
Diffstat (limited to 'test/parallel/test-async-wrap-promise-after-enabled.js')
-rw-r--r-- | test/parallel/test-async-wrap-promise-after-enabled.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/parallel/test-async-wrap-promise-after-enabled.js b/test/parallel/test-async-wrap-promise-after-enabled.js new file mode 100644 index 0000000000..475411a3da --- /dev/null +++ b/test/parallel/test-async-wrap-promise-after-enabled.js @@ -0,0 +1,34 @@ +'use strict'; + +// Regression test for https://github.com/nodejs/node/issues/13237 + +const common = require('../common'); +const assert = require('assert'); + +const async_hooks = require('async_hooks'); + +const seenEvents = []; + +const p = new Promise((resolve) => resolve(1)); +p.then(() => seenEvents.push('then')); + +const hooks = async_hooks.createHook({ + init: common.mustNotCall(), + + before: common.mustCall((id) => { + assert.ok(id > 1); + seenEvents.push('before'); + }), + + after: common.mustCall((id) => { + assert.ok(id > 1); + seenEvents.push('after'); + hooks.disable(); + }) +}); + +setImmediate(() => { + assert.deepStrictEqual(seenEvents, ['before', 'then', 'after']); +}); + +hooks.enable(); // After `setImmediate` in order to not catch its init event. |