1'use strict'; 2// Flags: --expose-gc 3// just like test-gc-http-client.js, 4// but aborting every connection that comes in. 5 6const common = require('../common'); 7const onGC = require('../common/ongc'); 8 9const http = require('http'); 10const todo = 500; 11let done = 0; 12let count = 0; 13let countGC = 0; 14 15console.log(`We should do ${todo} requests`); 16 17function serverHandler(req, res) { 18 res.connection.destroy(); 19} 20 21const server = http.createServer(serverHandler); 22server.listen(0, common.mustCall(() => { 23 for (let i = 0; i < 10; i++) 24 getall(); 25})); 26 27function getall() { 28 if (count >= todo) 29 return; 30 31 const req = http.get({ 32 hostname: 'localhost', 33 pathname: '/', 34 port: server.address().port 35 }, cb).on('error', cb); 36 37 count++; 38 onGC(req, { ongc }); 39 40 setImmediate(getall); 41} 42 43function cb(res) { 44 done += 1; 45} 46 47function ongc() { 48 countGC++; 49} 50 51setInterval(status, 100).unref(); 52 53function status() { 54 global.gc(); 55 console.log('Done: %d/%d', done, todo); 56 console.log('Collected: %d/%d', countGC, count); 57 if (countGC === todo) server.close(); 58} 59