11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci// Flags: --expose-gc 31cb0ef41Sopenharmony_ci// just like test-gc-http-client.js, 41cb0ef41Sopenharmony_ci// but aborting every connection that comes in. 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst common = require('../common'); 71cb0ef41Sopenharmony_ciconst onGC = require('../common/ongc'); 81cb0ef41Sopenharmony_ciconst http = require('http'); 91cb0ef41Sopenharmony_ciconst os = require('os'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst cpus = os.availableParallelism(); 121cb0ef41Sopenharmony_cilet createClients = true; 131cb0ef41Sopenharmony_cilet done = 0; 141cb0ef41Sopenharmony_cilet count = 0; 151cb0ef41Sopenharmony_cilet countGC = 0; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_cifunction serverHandler(req, res) { 181cb0ef41Sopenharmony_ci res.connection.destroy(); 191cb0ef41Sopenharmony_ci} 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciconst server = http.createServer(serverHandler); 221cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 231cb0ef41Sopenharmony_ci for (let i = 0; i < cpus; i++) 241cb0ef41Sopenharmony_ci getAll(); 251cb0ef41Sopenharmony_ci})); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_cifunction getAll() { 281cb0ef41Sopenharmony_ci if (!createClients) 291cb0ef41Sopenharmony_ci return; 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci const req = http.get({ 321cb0ef41Sopenharmony_ci hostname: 'localhost', 331cb0ef41Sopenharmony_ci pathname: '/', 341cb0ef41Sopenharmony_ci port: server.address().port 351cb0ef41Sopenharmony_ci }, cb).on('error', cb); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci count++; 381cb0ef41Sopenharmony_ci onGC(req, { ongc }); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci setImmediate(getAll); 411cb0ef41Sopenharmony_ci} 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_cifunction cb(res) { 441cb0ef41Sopenharmony_ci done += 1; 451cb0ef41Sopenharmony_ci} 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_cifunction ongc() { 481cb0ef41Sopenharmony_ci countGC++; 491cb0ef41Sopenharmony_ci} 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_cisetImmediate(status); 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_cifunction status() { 541cb0ef41Sopenharmony_ci if (done > 0) { 551cb0ef41Sopenharmony_ci createClients = false; 561cb0ef41Sopenharmony_ci global.gc(); 571cb0ef41Sopenharmony_ci console.log(`done/collected/total: ${done}/${countGC}/${count}`); 581cb0ef41Sopenharmony_ci if (countGC === count) { 591cb0ef41Sopenharmony_ci server.close(); 601cb0ef41Sopenharmony_ci return; 611cb0ef41Sopenharmony_ci } 621cb0ef41Sopenharmony_ci } 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci setImmediate(status); 651cb0ef41Sopenharmony_ci} 66