1// Flags: --allow_natives_syntax 2'use strict'; 3 4const common = require('../common'); 5const assert = require('assert'); 6const http = require('http'); 7 8const server = 9 http.createServer(onrequest).listen(0, common.localhostIPv4, () => next(0)); 10 11function onrequest(req, res) { 12 res.end('ok'); 13 onrequest.requests.push(req); 14 onrequest.responses.push(res); 15} 16onrequest.requests = []; 17onrequest.responses = []; 18 19function next(n) { 20 const { address: host, port } = server.address(); 21 const req = http.get({ host, port }); 22 req.once('response', (res) => onresponse(n, req, res)); 23} 24 25function onresponse(n, req, res) { 26 res.resume(); 27 28 if (n < 3) { 29 res.once('end', () => next(n + 1)); 30 } else { 31 server.close(); 32 } 33 34 onresponse.requests.push(req); 35 onresponse.responses.push(res); 36} 37onresponse.requests = []; 38onresponse.responses = []; 39 40function allSame(list) { 41 assert(list.length >= 2); 42 // Use |elt| in no-op position to pacify eslint. 43 for (const elt of list) elt, eval('%DebugPrint(elt)'); 44 for (const elt of list) elt, assert(eval('%HaveSameMap(list[0], elt)')); 45} 46 47process.on('exit', () => { 48 eval('%CollectGarbage(0)'); 49 // TODO(bnoordhuis) Investigate why the first IncomingMessage ends up 50 // with a deprecated map. The map is stable after the first request. 51 allSame(onrequest.requests.slice(1)); 52 allSame(onrequest.responses); 53 allSame(onresponse.requests); 54 allSame(onresponse.responses); 55}); 56