From 8eea3172271cbd021ae2f6d5881e4af6480bb3e9 Mon Sep 17 00:00:00 2001 From: Nitzan Uziely Date: Thu, 13 May 2021 02:26:48 +0300 Subject: [PATCH] test: stream.finished detects a destroyed IncomingMessage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a test to verify that stream.finished works correctly on IncomingMessage refs: https://github.com/nodejs/node/issues/38657 PR-URL: https://github.com/nodejs/node/pull/38661 Refs: https://github.com/nodejs/node/issues/38657 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Juan José Arboleda Reviewed-By: Luigi Pinca --- test/parallel/test-stream-finished.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-stream-finished.js b/test/parallel/test-stream-finished.js index d1652396dae25d..43b1e36a547402 100644 --- a/test/parallel/test-stream-finished.js +++ b/test/parallel/test-stream-finished.js @@ -553,14 +553,14 @@ testClosed((opts) => new Writable({ write() {}, ...opts })); } { - const server = http.createServer((req, res) => { - res.on('close', () => { + const server = http.createServer(common.mustCall((req, res) => { + res.on('close', common.mustCall(() => { finished(res, common.mustCall(() => { server.close(); })); - }); + })); res.end(); - }) + })) .listen(0, function() { http.request({ method: 'GET', @@ -570,6 +570,22 @@ testClosed((opts) => new Writable({ write() {}, ...opts })); }); } +{ + const server = http.createServer(common.mustCall((req, res) => { + req.on('close', common.mustCall(() => { + finished(req, common.mustCall(() => { + server.close(); + })); + })); + req.destroy(); + })).listen(0, function() { + http.request({ + method: 'GET', + port: this.address().port + }).end().on('error', common.mustCall()); + }); +} + { const w = new Writable({