Skip to content

Commit

Permalink
test: improve test-async-hooks-http-parser-destroy
Browse files Browse the repository at this point in the history
Improve reporting in test-async-hooks-http-parser-destroy when failing.

Before, failures looked like this (edited slightly to conform to our
commit message 72-char line length restriction):

    The expression evaluated to a falsy value:
    assert.ok(destroyedIds.indexOf(createdAsyncId) >= 0)

Now, you get a slightly better idea of what's up. (Is it missing one ID?
More than one? All of them?):

    AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
    + actual - expected ... Lines skipped

      [
        156,
    ...
        757,
    -   761,
        765
      ]
  • Loading branch information
Trott committed May 3, 2019
1 parent 8cac945 commit 2bc9310
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions test/parallel/test-async-hooks-http-parser-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ async_hooks.createHook({
if (type === 'HTTPINCOMINGMESSAGE' || type === 'HTTPCLIENTREQUEST') {
createdIds.push(asyncId);
}
}, N),
}),
destroy: (asyncId) => {
destroyedIds.push(asyncId);
if (createdIds.includes(asyncId)) {
destroyedIds.push(asyncId);
}
}
}).enable();

Expand All @@ -35,16 +37,7 @@ const keepAliveAgent = new http.Agent({
});

const countdown = new Countdown(N, () => {
server.close(() => {
// Give the server sockets time to close (which will also free their
// associated parser objects) after the server has been closed.
setTimeout(() => {
assert.strictEqual(createdIds.length, 2 * N);
createdIds.forEach((createdAsyncId) => {
assert.ok(destroyedIds.indexOf(createdAsyncId) >= 0);
});
}, KEEP_ALIVE * 2);
});
server.close();
});

server.listen(0, function() {
Expand All @@ -60,3 +53,12 @@ server.listen(0, function() {
})();
}
});

function checkOnExit() {
assert.deepStrictEqual(destroyedIds.sort(), createdIds.sort());
// There should be at least one ID for each request.
assert.ok(createdIds.length >= N, `${createdIds.length} < ${N}`);
}

// Ordinary exit.
process.on('exit', checkOnExit);

0 comments on commit 2bc9310

Please sign in to comment.