From f351c8a6c12cac56b386dc94d297d43104cd2574 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Tue, 6 Jun 2023 17:42:42 +0200 Subject: [PATCH] test: refactor test-gc-http-client-timeout Due to server response delay, all possible requests are created anyway. Instead of doing `36 * os.availableParallelism()` requests, use a fixed number. Refs: https://github.com/nodejs/node/pull/48078#issuecomment-1568183115 PR-URL: https://github.com/nodejs/node/pull/48292 Reviewed-By: Santiago Gimeno Reviewed-By: Rich Trott Reviewed-By: Yagiz Nizipli Reviewed-By: James M Snell Reviewed-By: LiviaMedeiros Reviewed-By: Daijiro Wachi --- .../sequential/test-gc-http-client-timeout.js | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/test/sequential/test-gc-http-client-timeout.js b/test/sequential/test-gc-http-client-timeout.js index 51dec7f043182d..02913e178ad89e 100644 --- a/test/sequential/test-gc-http-client-timeout.js +++ b/test/sequential/test-gc-http-client-timeout.js @@ -1,12 +1,10 @@ 'use strict'; // Flags: --expose-gc -// just like test-gc-http-client.js, -// but with a timeout set +// Like test-gc-http-client.js, but with a timeout set. const common = require('../common'); const onGC = require('../common/ongc'); const http = require('http'); -const os = require('os'); function serverHandler(req, res) { setTimeout(function() { @@ -16,20 +14,16 @@ function serverHandler(req, res) { }, 100); } -const cpus = os.availableParallelism(); -const numRequests = 36; -let createClients = true; +const numRequests = 128; let done = 0; -let count = 0; let countGC = 0; const server = http.createServer(serverHandler); -server.listen(0, common.mustCall(() => getAll(numRequests))); +server.listen(0, common.mustCall(() => { + getAll(numRequests); +})); function getAll(requestsRemaining) { - if (!createClients) - return; - if (requestsRemaining <= 0) return; @@ -41,15 +35,11 @@ function getAll(requestsRemaining) { req.setTimeout(10, common.mustCall()); - count++; onGC(req, { ongc }); setImmediate(getAll, requestsRemaining - 1); } -for (let i = 0; i < cpus; i++) - getAll(numRequests); - function cb(res) { res.resume(); done += 1; @@ -63,10 +53,9 @@ setImmediate(status); function status() { if (done > 0) { - createClients = false; global.gc(); - console.log(`done/collected/total: ${done}/${countGC}/${count}`); - if (countGC === count) { + console.log(`done/collected/total: ${done}/${countGC}/${numRequests}`); + if (countGC === numRequests) { server.close(); return; }