diff --git a/test/parallel/test-http-server-connection-list-when-close-deferred.js b/test/parallel/test-http-server-connection-list-when-close-deferred.js new file mode 100644 index 00000000000..af87e356161 --- /dev/null +++ b/test/parallel/test-http-server-connection-list-when-close-deferred.js @@ -0,0 +1,35 @@ +'use strict'; + +const common = require('../common'); +const http = require('http'); + +// Keep this case in a separate process from the immediate-close case so +// their modified parsers cannot be reused across cases. + +function request(server) { + http.get({ + agent: false, + port: server.address().port, + path: '/', + }, (res) => { + res.resume(); + }); +} + +const server = http.createServer(common.mustCallAtLeast((req, res) => { + // See `freeParser` in _http_common.js + const { parser } = req.socket; + parser.free = common.mustCall(() => { + setImmediate(common.mustCall(() => { + parser.close(); + })); + }); + req.socket.on('close', common.mustCall(() => { + setImmediate(common.mustCall(() => { + server.close(); + })); + })); + res.end('ok'); +})).listen(0, common.mustCall(() => { + request(server); +})); diff --git a/test/parallel/test-http-server-connection-list-when-close.js b/test/parallel/test-http-server-connection-list-when-close.js index 0c8308b63c5..305755b14eb 100644 --- a/test/parallel/test-http-server-connection-list-when-close.js +++ b/test/parallel/test-http-server-connection-list-when-close.js @@ -13,36 +13,14 @@ function request(server) { }); } -{ - const server = http.createServer(common.mustCallAtLeast((req, res) => { - // Hack to not remove parser out of server.connectionList - // See `freeParser` in _http_common.js - req.socket.parser.free = common.mustCall(); - req.socket.on('close', common.mustCall(() => { - server.close(); - })); - res.end('ok'); - })).listen(0, common.mustCall(() => { - request(server); +const server = http.createServer(common.mustCallAtLeast((req, res) => { + // Hack to not remove parser out of server.connectionList + // See `freeParser` in _http_common.js + req.socket.parser.free = common.mustCall(); + req.socket.on('close', common.mustCall(() => { + server.close(); })); -} - -{ - const server = http.createServer(common.mustCallAtLeast((req, res) => { - // See `freeParser` in _http_common.js - const { parser } = req.socket; - parser.free = common.mustCall(() => { - setImmediate(common.mustCall(() => { - parser.close(); - })); - }); - req.socket.on('close', common.mustCall(() => { - setImmediate(common.mustCall(() => { - server.close(); - })); - })); - res.end('ok'); - })).listen(0, common.mustCall(() => { - request(server); - })); -} + res.end('ok'); +})).listen(0, common.mustCall(() => { + request(server); +}));