Skip to content

Commit 818c935

Browse files
dszakallasjasnell
authored andcommitted
test: test async-hook triggerId properties
Add tests for checking the behavior of async_hooks.triggerId. It should return different ids when called in callbacks having different ancestry paths. It should return the same id when called in callbacks having the same ancestry path. PR-URL: #13328 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Andreas Madsen <[email protected]>
1 parent 52c0c47 commit 818c935

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
require('../common');
3+
4+
const assert = require('assert');
5+
const async_hooks = require('async_hooks');
6+
const triggerId = async_hooks.triggerId;
7+
8+
const triggerId0 = triggerId();
9+
let triggerId1;
10+
11+
process.nextTick(() => {
12+
process.nextTick(() => {
13+
triggerId1 = triggerId();
14+
assert.notStrictEqual(
15+
triggerId0,
16+
triggerId1,
17+
'Async resources having different causal ancestry ' +
18+
'should have different triggerIds');
19+
});
20+
process.nextTick(() => {
21+
const triggerId2 = triggerId();
22+
assert.strictEqual(
23+
triggerId1,
24+
triggerId2,
25+
'Async resources having the same causal ancestry ' +
26+
'should have the same triggerId');
27+
});
28+
});

0 commit comments

Comments
 (0)