diff options
author | David Cai <davidcai1993@yahoo.com> | 2017-06-05 15:35:06 +0800 |
---|---|---|
committer | David Cai <davidcai1993@yahoo.com> | 2017-06-07 11:02:47 +0800 |
commit | 35353a45fcc28b68c9d6c0695a8209d47dfeff56 (patch) | |
tree | 2263a352be1d87a6ed035034c6f25e00b5cff218 /test/async-hooks/test-callback-error.js | |
parent | 2791b360c11324f7c9ed83350f264c500ade4fe8 (diff) | |
download | android-node-v8-35353a45fcc28b68c9d6c0695a8209d47dfeff56.tar.gz android-node-v8-35353a45fcc28b68c9d6c0695a8209d47dfeff56.tar.bz2 android-node-v8-35353a45fcc28b68c9d6c0695a8209d47dfeff56.zip |
test: increase coverage of async_hooks
PR-URL: https://github.com/nodejs/node/pull/13336
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'test/async-hooks/test-callback-error.js')
-rw-r--r-- | test/async-hooks/test-callback-error.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/async-hooks/test-callback-error.js b/test/async-hooks/test-callback-error.js new file mode 100644 index 0000000000..8fe0177449 --- /dev/null +++ b/test/async-hooks/test-callback-error.js @@ -0,0 +1,56 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const spawnSync = require('child_process').spawnSync; +const async_hooks = require('async_hooks'); +const initHooks = require('./init-hooks'); + +switch (process.argv[2]) { + case 'test_init_callback': + initHooks({ + oninit: common.mustCall(() => { throw new Error('test_init_callback'); }) + }).enable(); + + async_hooks.emitInit(async_hooks.currentId(), 'test_init_callback_type', + async_hooks.triggerId()); + break; + case 'test_callback': + initHooks({ + onbefore: common.mustCall(() => { throw new Error('test_callback'); }) + }).enable(); + + async_hooks.emitInit(async_hooks.currentId(), 'test_callback_type', + async_hooks.triggerId()); + async_hooks.emitBefore(async_hooks.currentId()); + break; +} + +if (process.execArgv.includes('--abort-on-uncaught-exception')) { + initHooks({ + oninit: common.mustCall(() => { throw new Error('test_callback_abort'); }) + }).enable(); + + async_hooks.emitInit(async_hooks.currentId(), 'test_callback_abort', + async_hooks.triggerId()); +} + +const c1 = spawnSync(`${process.execPath}`, [__filename, 'test_init_callback']); +assert.strictEqual(c1.stderr.toString().split('\n')[0], + 'Error: test_init_callback'); +assert.strictEqual(c1.status, 1); + +const c2 = spawnSync(`${process.execPath}`, [__filename, 'test_callback']); +assert.strictEqual(c2.stderr.toString().split('\n')[0], 'Error: test_callback'); +assert.strictEqual(c2.status, 1); + +const c3 = spawnSync(`${process.execPath}`, ['--abort-on-uncaught-exception', + __filename, + 'test_callback_abort']); +assert.strictEqual(c3.stdout.toString(), ''); + +const stderrOutput = c3.stderr.toString() + .trim() + .split('\n') + .map((s) => s.trim()); +assert.strictEqual(stderrOutput[0], 'Error: test_callback_abort'); |