From 6bea43c3924926998400a341fa6259e745265acf Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Mon, 1 Oct 2018 14:28:18 +0300 Subject: [PATCH] test: improve test-gc-http-client-connaborted * refactor out usage of 'function' for scoping * wait till server is up to start firing requests PR-URL: https://github.com/nodejs/node/pull/23193 Reviewed-By: James M Snell Reviewed-By: Joyee Cheung Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca Reviewed-By: Sakthipriyan Vairamani --- .../test-gc-http-client-connaborted.js | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/test/sequential/test-gc-http-client-connaborted.js b/test/sequential/test-gc-http-client-connaborted.js index c043c474a65c6b..fa6bf20c176560 100644 --- a/test/sequential/test-gc-http-client-connaborted.js +++ b/test/sequential/test-gc-http-client-connaborted.js @@ -3,13 +3,9 @@ // just like test-gc-http-client.js, // but aborting every connection that comes in. -require('../common'); +const common = require('../common'); const onGC = require('../common/ongc'); -function serverHandler(req, res) { - res.connection.destroy(); -} - const http = require('http'); const todo = 500; let done = 0; @@ -18,33 +14,35 @@ let countGC = 0; console.log(`We should do ${todo} requests`); +function serverHandler(req, res) { + res.connection.destroy(); +} + const server = http.createServer(serverHandler); -server.listen(0, getall); +server.listen(0, common.mustCall(() => { + for (let i = 0; i < 10; i++) + getall(); +})); function getall() { if (count >= todo) return; - (function() { - function cb(res) { - done += 1; - } + const req = http.get({ + hostname: 'localhost', + pathname: '/', + port: server.address().port + }, cb).on('error', cb); - const req = http.get({ - hostname: 'localhost', - pathname: '/', - port: server.address().port - }, cb).on('error', cb); - - count++; - onGC(req, { ongc }); - })(); + count++; + onGC(req, { ongc }); setImmediate(getall); } -for (let i = 0; i < 10; i++) - getall(); +function cb(res) { + done += 1; +} function ongc() { countGC++;