Permalink
Browse files

test: improve async hooks test error messages

Improve error messages in the async hooks tests, mostly by removing
unhelpful `message` parameters for assertions.

PR-URL: #13243
Reviewed-By: Kunal Pathak <kunal.pathak@microsoft.com>
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information...
addaleax committed May 26, 2017
1 parent 8741e3c commit 1dc3272bb9c2ecd442efd5b978a852a7da31c1e9
Showing with 234 additions and 306 deletions.
  1. +4 −4 test/async-hooks/init-hooks.js
  2. +8 −10 test/async-hooks/test-connection.ssl.js
  3. +4 −4 test/async-hooks/test-crypto-pbkdf2.js
  4. +4 −4 test/async-hooks/test-crypto-randomBytes.js
  5. +5 −3 test/async-hooks/test-embedder.api.async-event.after-on-destroyed.js
  6. +5 −3 test/async-hooks/test-embedder.api.async-event.before-on-destroyed.js
  7. +5 −3 test/async-hooks/test-embedder.api.async-event.improper-order.js
  8. +5 −3 test/async-hooks/test-embedder.api.async-event.improper-unwind.js
  9. +7 −10 test/async-hooks/test-embedder.api.async-event.js
  10. +15 −29 test/async-hooks/test-enable-disable.js
  11. +4 −4 test/async-hooks/test-fseventwrap.js
  12. +3 −3 test/async-hooks/test-fsreqwrap-access.js
  13. +3 −3 test/async-hooks/test-fsreqwrap-readFile.js
  14. +4 −4 test/async-hooks/test-getaddrinforeqwrap.js
  15. +4 −4 test/async-hooks/test-getnameinforeqwrap.js
  16. +3 −6 test/async-hooks/test-httpparser.request.js
  17. +3 −6 test/async-hooks/test-httpparser.response.js
  18. +9 −12 test/async-hooks/test-immediate.js
  19. +14 −25 test/async-hooks/test-pipeconnectwrap.js
  20. +9 −11 test/async-hooks/test-pipewrap.js
  21. +8 −8 test/async-hooks/test-promise.js
  22. +5 −5 test/async-hooks/test-querywrap.js
  23. +7 −15 test/async-hooks/test-shutdownwrap.js
  24. +8 −12 test/async-hooks/test-signalwrap.js
  25. +11 −11 test/async-hooks/test-statwatcher.js
  26. +21 −38 test/async-hooks/test-tcpwrap.js
  27. +5 −5 test/async-hooks/test-timerwrap.setInterval.js
  28. +10 −12 test/async-hooks/test-timerwrap.setTimeout.js
  29. +8 −10 test/async-hooks/test-tlswrap.js
  30. +4 −4 test/async-hooks/test-ttywrap.readstream.js
  31. +5 −5 test/async-hooks/test-ttywrap.writestream.js
  32. +5 −8 test/async-hooks/test-udpsendwrap.js
  33. +4 −5 test/async-hooks/test-udpwrap.js
  34. +8 −11 test/async-hooks/test-writewrap.js
  35. +4 −4 test/async-hooks/test-zlib.zlib-binding.deflate.js
  36. +3 −2 test/async-hooks/verify-graph.js
@@ -1,11 +1,11 @@
'use strict';
// Flags: --expose-gc
require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');
const util = require('util');
const print = process._rawDebug;
require('../common');
if (typeof global.gc === 'function') {
(function exity(cntr) {
@@ -109,7 +109,7 @@ class ActivityCollector {
}
if (violations.length) {
console.error(violations.join('\n'));
assert.fail(violations.length, 0, 'Failed sanity check');
assert.fail(violations.length, 0, `Failed sanity checks: ${violations}`);
}
}
@@ -151,8 +151,8 @@ class ActivityCollector {
this._activities.set(uid, stub);
return stub;
} else {
const err = new Error('Found a handle who\'s ' + hook +
' hook was invoked but not it\'s init hook');
const err = new Error(`Found a handle whose ${hook}` +
' hook was invoked but not its init hook');
// Don't throw if we see invocations due to an assertion in a test
// failing since we want to list the assertion failure instead
if (/process\._fatalException/.test(err.stack)) return null;
@@ -38,24 +38,22 @@ function createServerConnection(
const sc1 = createServerConnection(common.mustCall(onfirstHandShake));
let as = hooks.activitiesOfTypes('SSLCONNECTION');
assert.strictEqual(as.length, 1,
'one CONNECTION after first connection created');
assert.strictEqual(as.length, 1);
const f1 = as[0];
assert.strictEqual(f1.type, 'SSLCONNECTION', 'connection');
assert.strictEqual(typeof f1.uid, 'number', 'uid is a number');
assert.strictEqual(typeof f1.triggerId, 'number', 'triggerId is a number');
assert.strictEqual(f1.type, 'SSLCONNECTION');
assert.strictEqual(typeof f1.uid, 'number');
assert.strictEqual(typeof f1.triggerId, 'number');
checkInvocations(f1, { init: 1 }, 'first connection, when first created');
// creating second server connection
const sc2 = createServerConnection(common.mustCall(onsecondHandShake));
as = hooks.activitiesOfTypes('SSLCONNECTION');
assert.strictEqual(as.length, 2,
'two SSLCONNECTIONs after second connection created');
assert.strictEqual(as.length, 2);
const f2 = as[1];
assert.strictEqual(f2.type, 'SSLCONNECTION', 'connection');
assert.strictEqual(typeof f2.uid, 'number', 'uid is a number');
assert.strictEqual(typeof f2.triggerId, 'number', 'triggerId is a number');
assert.strictEqual(f2.type, 'SSLCONNECTION');
assert.strictEqual(typeof f2.uid, 'number');
assert.strictEqual(typeof f2.triggerId, 'number');
checkInvocations(f1, { init: 1 }, 'first connection, when second created');
checkInvocations(f2, { init: 1 }, 'second connection, when second created');
@@ -31,12 +31,12 @@ function onexit() {
hooks.sanityCheck('PBKDF2REQUEST');
const as = hooks.activitiesOfTypes('PBKDF2REQUEST');
assert.strictEqual(as.length, 1, 'one activity');
assert.strictEqual(as.length, 1);
const a = as[0];
assert.strictEqual(a.type, 'PBKDF2REQUEST', 'random byte request');
assert.strictEqual(typeof a.uid, 'number', 'uid is a number');
assert.strictEqual(a.triggerId, 1, 'parent uid 1');
assert.strictEqual(a.type, 'PBKDF2REQUEST');
assert.strictEqual(typeof a.uid, 'number');
assert.strictEqual(a.triggerId, 1);
checkInvocations(a, { init: 1, before: 1, after: 1, destroy: 1 },
'when process exits');
}
@@ -32,12 +32,12 @@ function onexit() {
hooks.sanityCheck('RANDOMBYTESREQUEST');
const as = hooks.activitiesOfTypes('RANDOMBYTESREQUEST');
assert.strictEqual(as.length, 1, 'one activity');
assert.strictEqual(as.length, 1);
const a = as[0];
assert.strictEqual(a.type, 'RANDOMBYTESREQUEST', 'random byte request');
assert.strictEqual(typeof a.uid, 'number', 'uid is a number');
assert.strictEqual(a.triggerId, 1, 'parent uid 1');
assert.strictEqual(a.type, 'RANDOMBYTESREQUEST');
assert.strictEqual(typeof a.uid, 'number');
assert.strictEqual(a.triggerId, 1);
checkInvocations(a, { init: 1, before: 1, after: 1, destroy: 1 },
'when process exits');
}
@@ -39,10 +39,12 @@ if (process.argv[2] === 'child') {
child.stdout.on('data', (d) => { outData = Buffer.concat([ outData, d ]); });
child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1, 'exit code 1');
assert.strictEqual(code, 1);
assert.ok(heartbeatMsg.test(outData.toString()),
'did not crash until we reached offending line of code');
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.ok(corruptedMsg.test(errData.toString()),
'printed error contains corrupted message');
'printed error contains corrupted message ' +
`(found ${errData})`);
}));
}
@@ -39,10 +39,12 @@ if (process.argv[2] === 'child') {
child.stdout.on('data', (d) => { outData = Buffer.concat([ outData, d ]); });
child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1, 'exit code 1');
assert.strictEqual(code, 1);
assert.ok(heartbeatMsg.test(outData.toString()),
'did not crash until we reached offending line of code');
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.ok(corruptedMsg.test(errData.toString()),
'printed error contains corrupted message');
'printed error contains corrupted message ' +
`(found ${errData})`);
}));
}
@@ -37,10 +37,12 @@ if (process.argv[2] === 'child') {
child.stdout.on('data', (d) => { outData = Buffer.concat([ outData, d ]); });
child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1, 'exit code 1');
assert.strictEqual(code, 1);
assert.ok(heartbeatMsg.test(outData.toString()),
'did not crash until we reached offending line of code');
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.ok(corruptedMsg.test(errData.toString()),
'printed error contains corrupted message');
'printed error contains corrupted message ' +
`(found ${errData})`);
}));
}
@@ -46,10 +46,12 @@ if (process.argv[2] === 'child') {
child.stdout.on('data', (d) => { outData = Buffer.concat([ outData, d ]); });
child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1, 'exit code 1');
assert.strictEqual(code, 1);
assert.ok(heartbeatMsg.test(outData.toString()),
'did not crash until we reached offending line of code');
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.ok(corruptedMsg.test(errData.toString()),
'printed error contains corrupted message');
'printed error contains corrupted message ' +
`(found ${errData})`);
}));
}
@@ -19,13 +19,11 @@ const alcaEvent = new AsyncResource('alcazares', alcaTriggerId);
const alcazaresActivities = hooks.activitiesOfTypes([ 'alcazares' ]);
// alcazares event was constructed and thus only has an `init` call
assert.strictEqual(alcazaresActivities.length, 1,
'one alcazares activity after one was constructed');
assert.strictEqual(alcazaresActivities.length, 1);
const alcazares = alcazaresActivities[0];
assert.strictEqual(alcazares.type, 'alcazares', 'alcazares');
assert.strictEqual(typeof alcazares.uid, 'number', 'uid is a number');
assert.strictEqual(alcazares.triggerId, alcaTriggerId,
'triggerId is the one supplied');
assert.strictEqual(alcazares.type, 'alcazares');
assert.strictEqual(typeof alcazares.uid, 'number');
assert.strictEqual(alcazares.triggerId, alcaTriggerId);
checkInvocations(alcazares, { init: 1 }, 'alcazares constructed');
alcaEvent.emitBefore();
@@ -52,10 +50,9 @@ function tick1() {
const pobEvent = new AsyncResource('poblado', pobTriggerId);
const pobladoActivities = hooks.activitiesOfTypes([ 'poblado' ]);
const poblado = pobladoActivities[0];
assert.strictEqual(poblado.type, 'poblado', 'poblado');
assert.strictEqual(typeof poblado.uid, 'number', 'uid is a number');
assert.strictEqual(poblado.triggerId, pobTriggerId,
'triggerId is the one supplied');
assert.strictEqual(poblado.type, 'poblado');
assert.strictEqual(typeof poblado.uid, 'number');
assert.strictEqual(poblado.triggerId, pobTriggerId);
checkInvocations(poblado, { init: 1 }, 'poblado constructed');
pobEvent.emitBefore();
checkInvocations(poblado, { init: 1, before: 1 },
@@ -145,22 +145,17 @@ function onfirstImmediate() {
const as1 = hook1.activitiesOfTypes(types);
const as2 = hook2.activitiesOfTypes(types);
const as3 = hook3.activitiesOfTypes(types);
assert.strictEqual(as1.length, 1,
'hook1 captured one immediate on first callback');
assert.strictEqual(as1.length, 1);
// hook2 was not enabled yet .. it is enabled after hook3's "before" completed
assert.strictEqual(as2.length, 0,
'hook2 captured no immediate on first callback');
assert.strictEqual(as3.length, 1,
'hook3 captured one immediate on first callback');
assert.strictEqual(as2.length, 0);
assert.strictEqual(as3.length, 1);
// Check that hook1 and hook3 captured the same Immediate and that it is valid
const firstImmediate = as1[0];
assert.strictEqual(as3[0].uid, as1[0].uid,
'hook1 and hook3 captured same first immediate');
assert.strictEqual(firstImmediate.type, 'Immediate', 'immediate');
assert.strictEqual(typeof firstImmediate.uid, 'number', 'uid is a number');
assert.strictEqual(typeof firstImmediate.triggerId,
'number', 'triggerId is a number');
assert.strictEqual(as3[0].uid, as1[0].uid);
assert.strictEqual(firstImmediate.type, 'Immediate');
assert.strictEqual(typeof firstImmediate.uid, 'number');
assert.strictEqual(typeof firstImmediate.triggerId, 'number');
checkInvocations(as1[0], { init: 1, before: 1 },
'hook1[0]: on first immediate');
checkInvocations(as3[0], { init: 1, before: 1 },
@@ -187,15 +182,9 @@ function onsecondImmediate() {
const as1 = hook1.activitiesOfTypes(types);
const as2 = hook2.activitiesOfTypes(types);
const as3 = hook3.activitiesOfTypes(types);
assert.strictEqual(
as1.length, 2,
'hook1 captured first and second immediate on second callback');
assert.strictEqual(
as2.length, 2,
'hook2 captured first and second immediate on second callback');
assert.strictEqual(
as3.length, 2,
'hook3 captured first and second immediate on second callback');
assert.strictEqual(as1.length, 2);
assert.strictEqual(as2.length, 2);
assert.strictEqual(as3.length, 2);
// Assign the info collected by each hook for each immediate for easier
// reference.
@@ -210,14 +199,11 @@ function onsecondImmediate() {
// Check that all hooks captured the same Immediate and that it is valid
const secondImmediate = hook1Second;
assert.strictEqual(hook2Second.uid, hook3Second.uid,
'hook2 and hook3 captured same second immediate');
assert.strictEqual(hook1Second.uid, hook3Second.uid,
'hook1 and hook3 captured same second immediate');
assert.strictEqual(secondImmediate.type, 'Immediate', 'immediate');
assert.strictEqual(typeof secondImmediate.uid, 'number', 'uid is a number');
assert.strictEqual(typeof secondImmediate.triggerId, 'number',
'triggerId is a number');
assert.strictEqual(hook2Second.uid, hook3Second.uid);
assert.strictEqual(hook1Second.uid, hook3Second.uid);
assert.strictEqual(secondImmediate.type, 'Immediate');
assert.strictEqual(typeof secondImmediate.uid, 'number');
assert.strictEqual(typeof secondImmediate.triggerId, 'number');
checkInvocations(hook1First, { init: 1, before: 1, after: 1, destroy: 1 },
'hook1First: on second immediate');
@@ -23,11 +23,11 @@ function onexit() {
hooks.sanityCheck('FSEVENTWRAP');
const as = hooks.activitiesOfTypes('FSEVENTWRAP');
assert.strictEqual(as.length, 1, 'one activity');
assert.strictEqual(as.length, 1);
const a = as[0];
assert.strictEqual(a.type, 'FSEVENTWRAP', 'fs event wrap');
assert.strictEqual(typeof a.uid, 'number', 'uid is a number');
assert.strictEqual(a.triggerId, 1, 'parent uid 1');
assert.strictEqual(a.type, 'FSEVENTWRAP');
assert.strictEqual(typeof a.uid, 'number');
assert.strictEqual(a.triggerId, 1);
checkInvocations(a, { init: 1, destroy: 1 }, 'when process exits');
}
@@ -27,11 +27,11 @@ function onexit() {
hooks.sanityCheck('FSREQWRAP');
const as = hooks.activitiesOfTypes('FSREQWRAP');
assert.strictEqual(as.length, 1, 'one activity');
assert.strictEqual(as.length, 1);
const a = as[0];
assert.strictEqual(a.type, 'FSREQWRAP', 'fs req wrap');
assert.strictEqual(typeof a.uid, 'number', 'uid is a number');
assert.strictEqual(a.type, 'FSREQWRAP');
assert.strictEqual(typeof a.uid, 'number');
checkInvocations(a, { init: 1, before: 1, after: 1, destroy: 1 },
'when process exits');
}
@@ -17,9 +17,9 @@ function onread() {
let lastParent = 1;
for (let i = 0; i < as.length; i++) {
const a = as[i];
assert.strictEqual(a.type, 'FSREQWRAP', 'fs req wrap');
assert.strictEqual(typeof a.uid, 'number', 'uid is a number');
assert.strictEqual(a.triggerId, lastParent, 'parent uid 1');
assert.strictEqual(a.type, 'FSREQWRAP');
assert.strictEqual(typeof a.uid, 'number');
assert.strictEqual(a.triggerId, lastParent);
lastParent = a.uid;
}
checkInvocations(as[0], { init: 1, before: 1, after: 1, destroy: 1 },
@@ -16,12 +16,12 @@ function onlookup(err_, ip, family) {
// tests to run offline (lookup will fail in that case and the err be set);
const as = hooks.activitiesOfTypes('GETADDRINFOREQWRAP');
assert.strictEqual(as.length, 1, 'one activity');
assert.strictEqual(as.length, 1);
const a = as[0];
assert.strictEqual(a.type, 'GETADDRINFOREQWRAP', 'getaddrinforeq wrap');
assert.strictEqual(typeof a.uid, 'number', 'uid is a number');
assert.strictEqual(a.triggerId, 1, 'parent uid 1');
assert.strictEqual(a.type, 'GETADDRINFOREQWRAP');
assert.strictEqual(typeof a.uid, 'number');
assert.strictEqual(a.triggerId, 1);
checkInvocations(a, { init: 1, before: 1 }, 'while in onlookup callback');
tick(2);
}
@@ -16,12 +16,12 @@ function onlookupService(err_, ip, family) {
// tests to run offline (lookup will fail in that case and the err be set)
const as = hooks.activitiesOfTypes('GETNAMEINFOREQWRAP');
assert.strictEqual(as.length, 1, 'one activity');
assert.strictEqual(as.length, 1);
const a = as[0];
assert.strictEqual(a.type, 'GETNAMEINFOREQWRAP', 'getnameinforeq wrap');
assert.strictEqual(typeof a.uid, 'number', 'uid is a number');
assert.strictEqual(a.triggerId, 1, 'parent uid 1');
assert.strictEqual(a.type, 'GETNAMEINFOREQWRAP');
assert.strictEqual(typeof a.uid, 'number');
assert.strictEqual(a.triggerId, 1);
checkInvocations(a, { init: 1, before: 1 },
'while in onlookupService callback');
tick(2);
@@ -26,12 +26,9 @@ const parser = new HTTPParser(REQUEST);
const as = hooks.activitiesOfTypes('HTTPPARSER');
const httpparser = as[0];
assert.strictEqual(
as.length, 1,
'1 httpparser created synchronously when creating new httpparser');
assert.strictEqual(typeof httpparser.uid, 'number', 'uid is a number');
assert.strictEqual(typeof httpparser.triggerId,
'number', 'triggerId is a number');
assert.strictEqual(as.length, 1);
assert.strictEqual(typeof httpparser.uid, 'number');
assert.strictEqual(typeof httpparser.triggerId, 'number');
checkInvocations(httpparser, { init: 1 }, 'when created new Httphttpparser');
parser[kOnHeadersComplete] = common.mustCall(onheadersComplete);
@@ -30,12 +30,9 @@ const parser = new HTTPParser(RESPONSE);
const as = hooks.activitiesOfTypes('HTTPPARSER');
const httpparser = as[0];
assert.strictEqual(
as.length, 1,
'1 httpparser created synchronously when creating new httpparser');
assert.strictEqual(typeof httpparser.uid, 'number', 'uid is a number');
assert.strictEqual(typeof httpparser.triggerId,
'number', 'triggerId is a number');
assert.strictEqual(as.length, 1);
assert.strictEqual(typeof httpparser.uid, 'number');
assert.strictEqual(typeof httpparser.triggerId, 'number');
checkInvocations(httpparser, { init: 1 }, 'when created new Httphttpparser');
parser[kOnHeadersComplete] = common.mustCall(onheadersComplete);
Oops, something went wrong.

0 comments on commit 1dc3272

Please sign in to comment.