|
| 1 | +// Flags: --allow_natives_syntax |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +const common = require('../common'); |
| 5 | +const assert = require('assert'); |
| 6 | +const http = require('http'); |
| 7 | + |
| 8 | +const server = |
| 9 | + http.createServer(onrequest).listen(0, common.localhostIPv4, () => next(0)); |
| 10 | + |
| 11 | +function onrequest(req, res) { |
| 12 | + res.end('ok'); |
| 13 | + onrequest.requests.push(req); |
| 14 | + onrequest.responses.push(res); |
| 15 | +} |
| 16 | +onrequest.requests = []; |
| 17 | +onrequest.responses = []; |
| 18 | + |
| 19 | +function 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 | + |
| 25 | +function 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 | +} |
| 37 | +onresponse.requests = []; |
| 38 | +onresponse.responses = []; |
| 39 | + |
| 40 | +function 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 | + |
| 47 | +process.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 | +}); |
0 commit comments