From 149c2091714e95f03d2554eecf2f30366f6f28c0 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Fri, 17 Aug 2018 14:25:03 +0200 Subject: [PATCH] test: harden test-gc-http-client This reduces the total number of requests from 500 to 300 and triggers more requests in parallel. It also moves some function creation out and waits with the first request until the server is listening. PR-URL: https://github.com/nodejs/node/pull/22373 Fixes: https://github.com/nodejs/node/issues/22336 Reviewed-By: Joyee Cheung Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- test/parallel/test-gc-http-client.js | 40 +++++++++++++--------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/test/parallel/test-gc-http-client.js b/test/parallel/test-gc-http-client.js index d31874fa1666c7..5248a1504dfd37 100644 --- a/test/parallel/test-gc-http-client.js +++ b/test/parallel/test-gc-http-client.js @@ -10,7 +10,7 @@ function serverHandler(req, res) { } const http = require('http'); -const todo = 500; +const todo = 300; let done = 0; let count = 0; let countGC = 0; @@ -18,36 +18,32 @@ let countGC = 0; console.log(`We should do ${todo} requests`); const server = http.createServer(serverHandler); -server.listen(0, getall); - +server.listen(0, common.mustCall(() => { + for (let i = 0; i < 15; i++) + getall(); +})); function getall() { - if (count >= todo) + if (count === todo) return; - (function() { - function cb(res) { - res.resume(); - console.error('in cb'); - done += 1; - res.on('end', global.gc); - } - - const req = http.get({ - hostname: 'localhost', - pathname: '/', - port: server.address().port - }, cb); + const req = http.get({ + hostname: 'localhost', + pathname: '/', + port: server.address().port + }, cb); - count++; - common.onGC(req, { ongc }); - })(); + count++; + common.onGC(req, { ongc }); setImmediate(getall); } -for (let i = 0; i < 10; i++) - getall(); +function cb(res) { + res.resume(); + done += 1; + res.on('end', global.gc); +} function ongc() { countGC++;