From 44dc449effdd607065f2bd112f16f4b795ea067c Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Fri, 16 Jun 2017 16:25:02 -0600 Subject: [PATCH] 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 Reviewed-By: Refael Ackermann --- test/common/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/common/index.js b/test/common/index.js index c4f899c9ec..278f9f6a78 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -79,18 +79,21 @@ if (process.env.NODE_TEST_WITH_ASYNC_HOOKS) { if (destroyListList[id] !== undefined) { process._rawDebug(destroyListList[id]); 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; _queueDestroyAsyncId(id); }; require('async_hooks').createHook({ - init(id, ty, tr, h) { + init(id, ty, tr, r) { 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})`); } - initHandles[id] = h; + initHandles[id] = { resource: r, stack: new Error().stack.substr(6) }; }, before() { }, after() { },