summaryrefslogtreecommitdiff
path: root/test/async-hooks
diff options
context:
space:
mode:
authorAnatoli Papirovski <anatoli.papirovski@postmates.com>2019-12-14 15:02:50 -0500
committerRich Trott <rtrott@gmail.com>2020-01-11 19:20:45 -0800
commit4de31d517f75dd91e64f71df7cc9d2baa3e435c2 (patch)
tree0bb747e49e7e87e994a83dc4dc73abe94c1f78ec /test/async-hooks
parent625a81dea39b6698f3dd7b52978f821929d18073 (diff)
downloadnode-new-4de31d517f75dd91e64f71df7cc9d2baa3e435c2.tar.gz
async_hooks: remove internal only error checking
This error checking is mostly unnecessary and is just a Node core developer nicety, rather than something that is needed for the user-land. It can be safely removed without any practical impact while making nextTick, timers, immediates and AsyncResource substantially faster. PR-URL: https://github.com/nodejs/node/pull/30967 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/async-hooks')
-rw-r--r--test/async-hooks/test-emit-before-after.js48
-rw-r--r--test/async-hooks/test-emit-init.js40
2 files changed, 15 insertions, 73 deletions
diff --git a/test/async-hooks/test-emit-before-after.js b/test/async-hooks/test-emit-before-after.js
index 6a9ceaeefb..2ad98b993e 100644
--- a/test/async-hooks/test-emit-before-after.js
+++ b/test/async-hooks/test-emit-before-after.js
@@ -3,40 +3,9 @@
const common = require('../common');
const assert = require('assert');
-const spawnSync = require('child_process').spawnSync;
const async_hooks = require('internal/async_hooks');
const initHooks = require('./init-hooks');
-if (!common.isMainThread)
- common.skip('Worker bootstrapping works differently -> different async IDs');
-
-switch (process.argv[2]) {
- case 'test_invalid_async_id':
- async_hooks.emitBefore(-2, 1);
- return;
- case 'test_invalid_trigger_id':
- async_hooks.emitBefore(1, -2);
- return;
-}
-assert.ok(!process.argv[2]);
-
-
-const c1 = spawnSync(process.execPath, [
- '--expose-internals', __filename, 'test_invalid_async_id'
-]);
-assert.strictEqual(
- c1.stderr.toString().split(/[\r\n]+/g)[0],
- 'RangeError [ERR_INVALID_ASYNC_ID]: Invalid asyncId value: -2');
-assert.strictEqual(c1.status, 1);
-
-const c2 = spawnSync(process.execPath, [
- '--expose-internals', __filename, 'test_invalid_trigger_id'
-]);
-assert.strictEqual(
- c2.stderr.toString().split(/[\r\n]+/g)[0],
- 'RangeError [ERR_INVALID_ASYNC_ID]: Invalid triggerAsyncId value: -2');
-assert.strictEqual(c2.status, 1);
-
const expectedId = async_hooks.newAsyncId();
const expectedTriggerId = async_hooks.newAsyncId();
const expectedType = 'test_emit_before_after_type';
@@ -45,9 +14,22 @@ const expectedType = 'test_emit_before_after_type';
async_hooks.emitBefore(expectedId, expectedTriggerId);
async_hooks.emitAfter(expectedId);
+const chkBefore = common.mustCall((id) => assert.strictEqual(id, expectedId));
+const chkAfter = common.mustCall((id) => assert.strictEqual(id, expectedId));
+
+const checkOnce = (fn) => {
+ let called = false;
+ return (...args) => {
+ if (called) return;
+
+ called = true;
+ fn(...args);
+ };
+};
+
initHooks({
- onbefore: common.mustCall((id) => assert.strictEqual(id, expectedId)),
- onafter: common.mustCall((id) => assert.strictEqual(id, expectedId)),
+ onbefore: checkOnce(chkBefore),
+ onafter: checkOnce(chkAfter),
allowNoInit: true
}).enable();
diff --git a/test/async-hooks/test-emit-init.js b/test/async-hooks/test-emit-init.js
index f5d5687cb4..bc1cd49cba 100644
--- a/test/async-hooks/test-emit-init.js
+++ b/test/async-hooks/test-emit-init.js
@@ -3,7 +3,6 @@
const common = require('../common');
const assert = require('assert');
-const spawnSync = require('child_process').spawnSync;
const async_hooks = require('internal/async_hooks');
const initHooks = require('./init-hooks');
@@ -23,45 +22,6 @@ const hooks1 = initHooks({
hooks1.enable();
-switch (process.argv[2]) {
- case 'test_invalid_async_id':
- async_hooks.emitInit();
- return;
- case 'test_invalid_trigger_id':
- async_hooks.emitInit(expectedId);
- return;
- case 'test_invalid_trigger_id_negative':
- async_hooks.emitInit(expectedId, expectedType, -2);
- return;
-}
-assert.ok(!process.argv[2]);
-
-
-const c1 = spawnSync(process.execPath, [
- '--expose-internals', __filename, 'test_invalid_async_id'
-]);
-assert.strictEqual(
- c1.stderr.toString().split(/[\r\n]+/g)[0],
- 'RangeError [ERR_INVALID_ASYNC_ID]: Invalid asyncId value: undefined');
-assert.strictEqual(c1.status, 1);
-
-const c2 = spawnSync(process.execPath, [
- '--expose-internals', __filename, 'test_invalid_trigger_id'
-]);
-assert.strictEqual(
- c2.stderr.toString().split(/[\r\n]+/g)[0],
- 'RangeError [ERR_INVALID_ASYNC_ID]: Invalid triggerAsyncId value: undefined');
-assert.strictEqual(c2.status, 1);
-
-const c3 = spawnSync(process.execPath, [
- '--expose-internals', __filename, 'test_invalid_trigger_id_negative'
-]);
-assert.strictEqual(
- c3.stderr.toString().split(/[\r\n]+/g)[0],
- 'RangeError [ERR_INVALID_ASYNC_ID]: Invalid triggerAsyncId value: -2');
-assert.strictEqual(c3.status, 1);
-
-
async_hooks.emitInit(expectedId, expectedType, expectedTriggerId,
expectedResource);