From 323f543cf6400f6b043d07d393e8f7d4f621e4e8 Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Sun, 30 Sep 2018 22:04:14 +0300 Subject: [PATCH] test: harden test-gc-http-client-timeout * decrease number of requests 500 -> 300 * extract 'cb' to a file-local function This should make test more reliable and less resource intensive. PR-URL: https://github.com/nodejs/node/pull/23184 Refs: https://github.com/nodejs/node/issues/23066 Reviewed-By: Anna Henningsen Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell --- .../sequential/test-gc-http-client-timeout.js | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/test/sequential/test-gc-http-client-timeout.js b/test/sequential/test-gc-http-client-timeout.js index 4b4d1610c3ebdb..359f890dc3944e 100644 --- a/test/sequential/test-gc-http-client-timeout.js +++ b/test/sequential/test-gc-http-client-timeout.js @@ -3,7 +3,7 @@ // just like test-gc-http-client.js, // but with a timeout set -require('../common'); +const common = require('../common'); const onGC = require('../common/ongc'); function serverHandler(req, res) { @@ -15,7 +15,7 @@ function serverHandler(req, res) { } const http = require('http'); -const todo = 550; +const todo = 300; let done = 0; let count = 0; let countGC = 0; @@ -23,31 +23,24 @@ let countGC = 0; console.log(`We should do ${todo} requests`); const server = http.createServer(serverHandler); -server.listen(0, getall); +server.listen(0, common.mustCall(getall)); function getall() { if (count >= todo) return; - (function() { - function cb(res) { - res.resume(); - done += 1; - } + const req = http.get({ + hostname: 'localhost', + pathname: '/', + port: server.address().port + }, cb); - const req = http.get({ - hostname: 'localhost', - pathname: '/', - port: server.address().port - }, cb); + req.setTimeout(10, function() { + console.log('timeout (expected)'); + }); - req.setTimeout(10, function() { - console.log('timeout (expected)'); - }); - - count++; - onGC(req, { ongc }); - })(); + count++; + onGC(req, { ongc }); setImmediate(getall); } @@ -55,6 +48,11 @@ function getall() { for (let i = 0; i < 10; i++) getall(); +function cb(res) { + res.resume(); + done += 1; +} + function ongc() { countGC++; }