Skip to content

Commit 77f3c1f

Browse files
apapirovskijasnell
authored andcommitted
test: fix http-agent-destroyed-socket cb not firing
A whole part of the test-http-agent-destroyed-socket test was not running as the semantics of http events changed slightly and were no longer triggering the expected event. Instead listen to the same event on the socket to verify that the code being tested is still working as expected. PR-URL: #20006 Fixes: #8613 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent ed45a8b commit 77f3c1f

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

test/parallel/test-http-agent-destroyed-socket.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,11 @@ const server = http.createServer(common.mustCall((req, res) => {
4444
// assert request2 is queued in the agent
4545
const key = agent.getName(requestOptions);
4646
assert.strictEqual(agent.requests[key].length, 1);
47-
request1.socket.on('close', common.mustCall());
4847
response.resume();
4948
response.on('end', common.mustCall(() => {
50-
//
51-
// THE IMPORTANT PART
52-
//
53-
// It is possible for the socket to get destroyed and other work
54-
// to run before the 'close' event fires because it happens on
55-
// nextTick. This example is contrived because it destroys the
56-
// socket manually at just the right time, but at Voxer we have
57-
// seen cases where the socket is destroyed by non-user code
58-
// then handed out again by an agent *before* the 'close' event
59-
// is triggered.
6049
request1.socket.destroy();
6150

62-
// TODO(jasnell): This close event does not appear to be triggered.
63-
// is it necessary?
64-
response.once('close', () => {
51+
response.socket.once('close', common.mustCall(() => {
6552
// assert request2 was removed from the queue
6653
assert(!agent.requests[key]);
6754
process.nextTick(() => {
@@ -70,7 +57,7 @@ const server = http.createServer(common.mustCall((req, res) => {
7057
assert.notStrictEqual(request1.socket, request2.socket);
7158
assert(!request2.socket.destroyed, 'the socket is destroyed');
7259
});
73-
});
60+
}));
7461
}));
7562
}));
7663

0 commit comments

Comments
 (0)