Skip to content

Commit 98fc665

Browse files
trevnorrisMylesBorins
authored andcommitted
test: print resource stack on error
When running tests with NODE_TEST_WITH_ASYNC_HOOKS and the same asyncId is detected twice print the stack traces of both init() calls. Also print if the resource is the same instance. PR-URL: #14208 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 81515c7 commit 98fc665

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/common/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,21 @@ if (process.env.NODE_TEST_WITH_ASYNC_HOOKS) {
7979
if (destroyListList[id] !== undefined) {
8080
process._rawDebug(destroyListList[id]);
8181
process._rawDebug();
82-
throw new Error(`same id added twice (${id})`);
82+
throw new Error(`same id added to destroy list twice (${id})`);
8383
}
8484
destroyListList[id] = new Error().stack;
8585
_queueDestroyAsyncId(id);
8686
};
8787

8888
require('async_hooks').createHook({
89-
init(id, ty, tr, h) {
89+
init(id, ty, tr, r) {
9090
if (initHandles[id]) {
91+
process._rawDebug(
92+
`Is same resource: ${r === initHandles[id].resource}`);
93+
process._rawDebug(`Previous stack:\n${initHandles[id].stack}\n`);
9194
throw new Error(`init called twice for same id (${id})`);
9295
}
93-
initHandles[id] = h;
96+
initHandles[id] = { resource: r, stack: new Error().stack.substr(6) };
9497
},
9598
before() { },
9699
after() { },

0 commit comments

Comments
 (0)