-
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_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: #13548 (comment) PR-URL: #14026 Reviewed-By: Refael Ackermann <refack@gmail.com>
- Loading branch information
1 parent
ebbebef
commit 74329ca
Showing
5 changed files
with
73 additions
and
15 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
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
47 changes: 47 additions & 0 deletions
47
test/async-hooks/test-internal-nexttick-default-trigger.js
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,47 @@ | ||
'use strict'; | ||
// Flags: --expose-internals | ||
const common = require('../common'); | ||
|
||
// This tests ensures that the triggerId of both the internal and external | ||
// nexTick function sets the triggerAsyncId correctly. | ||
|
||
const assert = require('assert'); | ||
const async_hooks = require('async_hooks'); | ||
const initHooks = require('./init-hooks'); | ||
const { checkInvocations } = require('./hook-checks'); | ||
const internal = require('internal/process/next_tick'); | ||
|
||
const hooks = initHooks(); | ||
hooks.enable(); | ||
|
||
const rootAsyncId = async_hooks.executionAsyncId(); | ||
|
||
// public | ||
process.nextTick(common.mustCall(function() { | ||
assert.strictEqual(async_hooks.triggerAsyncId(), rootAsyncId); | ||
})); | ||
|
||
// internal default | ||
internal.nextTick(null, common.mustCall(function() { | ||
assert.strictEqual(async_hooks.triggerAsyncId(), rootAsyncId); | ||
})); | ||
|
||
// internal | ||
internal.nextTick(rootAsyncId + 1, common.mustCall(function() { | ||
assert.strictEqual(async_hooks.triggerAsyncId(), rootAsyncId + 1); | ||
})); | ||
|
||
process.on('exit', function() { | ||
hooks.sanityCheck(); | ||
|
||
const as = hooks.activitiesOfTypes('TickObject'); | ||
checkInvocations(as[0], { | ||
init: 1, before: 1, after: 1, destroy: 1 | ||
}, 'when process exits'); | ||
checkInvocations(as[1], { | ||
init: 1, before: 1, after: 1, destroy: 1 | ||
}, 'when process exits'); | ||
checkInvocations(as[2], { | ||
init: 1, before: 1, after: 1, destroy: 1 | ||
}, 'when process exits'); | ||
}); |