-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #13237 PR-URL: #13242 Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: Matthew Loring <[email protected]>
- Loading branch information
Showing
3 changed files
with
49 additions
and
10 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,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. |