From 14c9585baa472183bc4f71ba4d062da212b6549e Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Thu, 21 Sep 2017 08:57:25 +0200 Subject: [PATCH] test: fix http-writable-true-after-close flakyness Ref: https://github.com/nodejs/node/pull/15404 Fixes: https://github.com/nodejs/node/issues/15505 PR-URL: https://github.com/nodejs/node/pull/15520 Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- .../test-http-writable-true-after-close.js | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/test/parallel/test-http-writable-true-after-close.js b/test/parallel/test-http-writable-true-after-close.js index 3cac10bdde..49688a00ef 100644 --- a/test/parallel/test-http-writable-true-after-close.js +++ b/test/parallel/test-http-writable-true-after-close.js @@ -7,29 +7,36 @@ const { get, createServer } = require('http'); // res.writable should not be set to false after it has finished sending // Ref: https://github.com/nodejs/node/issues/15029 +let internal; let external; -// Http server -const internal = createServer((req, res) => { - res.writeHead(200); - setImmediate(common.mustCall(() => { - external.abort(); - res.end('Hello World\n'); - })); -}).listen(0); - // Proxy server const server = createServer(common.mustCall((req, res) => { get(`http://127.0.0.1:${internal.address().port}`, common.mustCall((inner) => { - res.on('close', common.mustCall(() => { + const listener = common.mustCall(() => { assert.strictEqual(res.writable, true); - })); + }); + + // on CentOS 5, 'finish' is emitted + res.on('finish', listener); + // everywhere else, 'close' is emitted + res.on('close', listener); + inner.pipe(res); })); })).listen(0, () => { - external = get(`http://127.0.0.1:${server.address().port}`); - external.on('error', common.mustCall((err) => { - server.close(); - internal.close(); - })); + // Http server + internal = createServer((req, res) => { + res.writeHead(200); + setImmediate(common.mustCall(() => { + external.abort(); + res.end('Hello World\n'); + })); + }).listen(0, () => { + external = get(`http://127.0.0.1:${server.address().port}`); + external.on('error', common.mustCall((err) => { + server.close(); + internal.close(); + })); + }); });