1'use strict'; 2// Flags: --expose-gc 3// just a simple http server and client. 4 5const common = require('../common'); 6const onGC = require('../common/ongc'); 7 8function serverHandler(req, res) { 9 res.writeHead(200, { 'Content-Type': 'text/plain' }); 10 res.end('Hello World\n'); 11} 12 13const http = require('http'); 14const todo = 300; 15let done = 0; 16let count = 0; 17let countGC = 0; 18 19console.log(`We should do ${todo} requests`); 20 21const server = http.createServer(serverHandler); 22server.listen(0, common.mustCall(() => { 23 for (let i = 0; i < 15; 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); 36 37 count++; 38 onGC(req, { ongc }); 39 40 setImmediate(getall); 41} 42 43function cb(res) { 44 res.resume(); 45 done += 1; 46} 47 48function ongc() { 49 countGC++; 50} 51 52setInterval(status, 100).unref(); 53 54function status() { 55 global.gc(); 56 console.log('Done: %d/%d', done, todo); 57 console.log('Collected: %d/%d', countGC, count); 58 if (countGC === todo) server.close(); 59} 60