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: https://github.com/nodejs/node/pull/14208 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
parent
4321206c5b
commit
44dc449eff
@ -79,18 +79,21 @@ if (process.env.NODE_TEST_WITH_ASYNC_HOOKS) {
|
|||||||
if (destroyListList[id] !== undefined) {
|
if (destroyListList[id] !== undefined) {
|
||||||
process._rawDebug(destroyListList[id]);
|
process._rawDebug(destroyListList[id]);
|
||||||
process._rawDebug();
|
process._rawDebug();
|
||||||
throw new Error(`same id added twice (${id})`);
|
throw new Error(`same id added to destroy list twice (${id})`);
|
||||||
}
|
}
|
||||||
destroyListList[id] = new Error().stack;
|
destroyListList[id] = new Error().stack;
|
||||||
_queueDestroyAsyncId(id);
|
_queueDestroyAsyncId(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
require('async_hooks').createHook({
|
require('async_hooks').createHook({
|
||||||
init(id, ty, tr, h) {
|
init(id, ty, tr, r) {
|
||||||
if (initHandles[id]) {
|
if (initHandles[id]) {
|
||||||
|
process._rawDebug(
|
||||||
|
`Is same resource: ${r === initHandles[id].resource}`);
|
||||||
|
process._rawDebug(`Previous stack:\n${initHandles[id].stack}\n`);
|
||||||
throw new Error(`init called twice for same id (${id})`);
|
throw new Error(`init called twice for same id (${id})`);
|
||||||
}
|
}
|
||||||
initHandles[id] = h;
|
initHandles[id] = { resource: r, stack: new Error().stack.substr(6) };
|
||||||
},
|
},
|
||||||
before() { },
|
before() { },
|
||||||
after() { },
|
after() { },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user