From 9273bc5e379970e5af8c7be6caadd2115ace5ba2 Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Fri, 13 Apr 2018 12:20:47 +0200 Subject: [PATCH 1/2] 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. --- .../parallel/test-http-agent-destroyed-socket.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/test/parallel/test-http-agent-destroyed-socket.js b/test/parallel/test-http-agent-destroyed-socket.js index 137292cce66916..4e25b38c56c3cc 100644 --- a/test/parallel/test-http-agent-destroyed-socket.js +++ b/test/parallel/test-http-agent-destroyed-socket.js @@ -47,21 +47,9 @@ const server = http.createServer(common.mustCall((req, res) => { request1.socket.on('close', common.mustCall()); response.resume(); response.on('end', common.mustCall(() => { - // - // THE IMPORTANT PART - // - // It is possible for the socket to get destroyed and other work - // to run before the 'close' event fires because it happens on - // nextTick. This example is contrived because it destroys the - // socket manually at just the right time, but at Voxer we have - // seen cases where the socket is destroyed by non-user code - // then handed out again by an agent *before* the 'close' event - // is triggered. request1.socket.destroy(); - // TODO(jasnell): This close event does not appear to be triggered. - // is it necessary? - response.once('close', () => { + response.socket.once('close', common.mustCall(() => { // assert request2 was removed from the queue assert(!agent.requests[key]); process.nextTick(() => { @@ -70,7 +58,7 @@ const server = http.createServer(common.mustCall((req, res) => { assert.notStrictEqual(request1.socket, request2.socket); assert(!request2.socket.destroyed, 'the socket is destroyed'); }); - }); + })); })); })); From bec6a348fad9bb81d58e8bd9878ceef0b9cbf1f7 Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Sat, 14 Apr 2018 12:10:18 +0200 Subject: [PATCH 2/2] fixup: remove unnecessary duplicate event handler --- test/parallel/test-http-agent-destroyed-socket.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-http-agent-destroyed-socket.js b/test/parallel/test-http-agent-destroyed-socket.js index 4e25b38c56c3cc..af63a676f62fd9 100644 --- a/test/parallel/test-http-agent-destroyed-socket.js +++ b/test/parallel/test-http-agent-destroyed-socket.js @@ -44,7 +44,6 @@ const server = http.createServer(common.mustCall((req, res) => { // assert request2 is queued in the agent const key = agent.getName(requestOptions); assert.strictEqual(agent.requests[key].length, 1); - request1.socket.on('close', common.mustCall()); response.resume(); response.on('end', common.mustCall(() => { request1.socket.destroy();