From e402b22bd5d9d33ba93790a974d7caa01890d8c4 Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Mon, 1 Oct 2018 15:29:08 +0300 Subject: [PATCH] test: improve test-gc-http-client-onerror * refactor out usage of 'function' for scoping * inline runTest function PR-URL: https://github.com/nodejs/node/pull/23196 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- .../sequential/test-gc-http-client-onerror.js | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/test/sequential/test-gc-http-client-onerror.js b/test/sequential/test-gc-http-client-onerror.js index ef643d255e7ed8..28a8aecd27e794 100644 --- a/test/sequential/test-gc-http-client-onerror.js +++ b/test/sequential/test-gc-http-client-onerror.js @@ -3,7 +3,7 @@ // just like test-gc-http-client.js, // but with an on('error') handler that does nothing. -require('../common'); +const common = require('../common'); const onGC = require('../common/ongc'); function serverHandler(req, res) { @@ -21,37 +21,34 @@ let countGC = 0; console.log(`We should do ${todo} requests`); const server = http.createServer(serverHandler); -server.listen(0, runTest); +server.listen(0, common.mustCall(() => { + for (let i = 0; i < 10; i++) + getall(); +})); function getall() { if (count >= todo) return; - (function() { - function cb(res) { - res.resume(); - done += 1; - } - function onerror(er) { - throw er; - } + const req = http.get({ + hostname: 'localhost', + pathname: '/', + port: server.address().port + }, cb).on('error', onerror); - const req = http.get({ - hostname: 'localhost', - pathname: '/', - port: server.address().port - }, cb).on('error', onerror); - - count++; - onGC(req, { ongc }); - })(); + count++; + onGC(req, { ongc }); setImmediate(getall); } -function runTest() { - for (let i = 0; i < 10; i++) - getall(); +function cb(res) { + res.resume(); + done += 1; +} + +function onerror(err) { + throw err; } function ongc() {