diff options
author | Andreas Madsen <amwebdk@gmail.com> | 2017-07-02 15:59:23 +0200 |
---|---|---|
committer | Andreas Madsen <amwebdk@gmail.com> | 2017-07-06 23:50:08 +0200 |
commit | 4e27aa9603a281caf8241b1bba8e0f6d57554c57 (patch) | |
tree | d9af0bae8c3a7c6acc3bad227328ca5a0386f428 /test/async-hooks | |
parent | 388e552579aff6b5152c67adeda182d2d40e8dfc (diff) | |
download | android-node-v8-4e27aa9603a281caf8241b1bba8e0f6d57554c57.tar.gz android-node-v8-4e27aa9603a281caf8241b1bba8e0f6d57554c57.tar.bz2 android-node-v8-4e27aa9603a281caf8241b1bba8e0f6d57554c57.zip |
async_hooks: use common emitBefore and emitAfter
Timers and nextTick have special emitBefore and emitAfter functions for
historic reasons. These function are not needed any more, thus the
public emitBefore and emitAfter function can be used.
PR-URL: https://github.com/nodejs/node/pull/14050
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test/async-hooks')
-rw-r--r-- | test/async-hooks/test-callback-error.js | 15 | ||||
-rw-r--r-- | test/async-hooks/test-emit-before-after.js | 14 |
2 files changed, 16 insertions, 13 deletions
diff --git a/test/async-hooks/test-callback-error.js b/test/async-hooks/test-callback-error.js index b110e700e6..a4b8a99f33 100644 --- a/test/async-hooks/test-callback-error.js +++ b/test/async-hooks/test-callback-error.js @@ -12,9 +12,9 @@ switch (arg) { oninit: common.mustCall(() => { throw new Error(arg); }) }).enable(); async_hooks.emitInit( - async_hooks.executionAsyncId(), + async_hooks.newUid(), `${arg}_type`, - async_hooks.triggerAsyncId() + async_hooks.executionAsyncId() ); return; @@ -22,12 +22,13 @@ switch (arg) { initHooks({ onbefore: common.mustCall(() => { throw new Error(arg); }) }).enable(); + const newAsyncId = async_hooks.newUid(); async_hooks.emitInit( - async_hooks.executionAsyncId(), + newAsyncId, `${arg}_type`, - async_hooks.triggerAsyncId() + async_hooks.executionAsyncId() ); - async_hooks.emitBefore(async_hooks.executionAsyncId()); + async_hooks.emitBefore(newAsyncId, async_hooks.executionAsyncId()); return; case 'test_callback_abort': @@ -35,9 +36,9 @@ switch (arg) { oninit: common.mustCall(() => { throw new Error(arg); }) }).enable(); async_hooks.emitInit( - async_hooks.executionAsyncId(), + async_hooks.newUid(), `${arg}_type`, - async_hooks.triggerAsyncId() + async_hooks.executionAsyncId() ); return; } diff --git a/test/async-hooks/test-emit-before-after.js b/test/async-hooks/test-emit-before-after.js index f4757a2887..1334767c76 100644 --- a/test/async-hooks/test-emit-before-after.js +++ b/test/async-hooks/test-emit-before-after.js @@ -8,17 +8,19 @@ const initHooks = require('./init-hooks'); switch (process.argv[2]) { case 'test_invalid_async_id': - async_hooks.emitBefore(-1); - break; + async_hooks.emitBefore(-1, 1); + return; case 'test_invalid_trigger_id': async_hooks.emitBefore(1, -1); - break; + return; } +assert.ok(!process.argv[2]); + const c1 = spawnSync(process.execPath, [__filename, 'test_invalid_async_id']); assert.strictEqual(c1.stderr.toString().split(/[\r\n]+/g)[0], 'Error: before(): asyncId or triggerAsyncId is less than ' + - 'zero (asyncId: -1, triggerAsyncId: -1)'); + 'zero (asyncId: -1, triggerAsyncId: 1)'); assert.strictEqual(c1.status, 1); const c2 = spawnSync(process.execPath, [__filename, 'test_invalid_trigger_id']); @@ -32,7 +34,7 @@ const expectedTriggerId = async_hooks.newUid(); const expectedType = 'test_emit_before_after_type'; // Verify that if there is no registered hook, then nothing will happen. -async_hooks.emitBefore(expectedId); +async_hooks.emitBefore(expectedId, expectedTriggerId); async_hooks.emitAfter(expectedId); initHooks({ @@ -42,5 +44,5 @@ initHooks({ }).enable(); async_hooks.emitInit(expectedId, expectedType, expectedTriggerId); -async_hooks.emitBefore(expectedId); +async_hooks.emitBefore(expectedId, expectedTriggerId); async_hooks.emitAfter(expectedId); |