Skip to content

Commit 2bc9310

Browse files
committed
test: improve test-async-hooks-http-parser-destroy
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 ]
1 parent 8cac945 commit 2bc9310

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

test/parallel/test-async-hooks-http-parser-destroy.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ async_hooks.createHook({
1919
if (type === 'HTTPINCOMINGMESSAGE' || type === 'HTTPCLIENTREQUEST') {
2020
createdIds.push(asyncId);
2121
}
22-
}, N),
22+
}),
2323
destroy: (asyncId) => {
24-
destroyedIds.push(asyncId);
24+
if (createdIds.includes(asyncId)) {
25+
destroyedIds.push(asyncId);
26+
}
2527
}
2628
}).enable();
2729

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

3739
const countdown = new Countdown(N, () => {
38-
server.close(() => {
39-
// Give the server sockets time to close (which will also free their
40-
// associated parser objects) after the server has been closed.
41-
setTimeout(() => {
42-
assert.strictEqual(createdIds.length, 2 * N);
43-
createdIds.forEach((createdAsyncId) => {
44-
assert.ok(destroyedIds.indexOf(createdAsyncId) >= 0);
45-
});
46-
}, KEEP_ALIVE * 2);
47-
});
40+
server.close();
4841
});
4942

5043
server.listen(0, function() {
@@ -60,3 +53,12 @@ server.listen(0, function() {
6053
})();
6154
}
6255
});
56+
57+
function checkOnExit() {
58+
assert.deepStrictEqual(destroyedIds.sort(), createdIds.sort());
59+
// There should be at least one ID for each request.
60+
assert.ok(createdIds.length >= N, `${createdIds.length} < ${N}`);
61+
}
62+
63+
// Ordinary exit.
64+
process.on('exit', checkOnExit);

0 commit comments

Comments
 (0)