1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const http = require('http'); 5 6let socketsCreated = 0; 7 8class Agent extends http.Agent { 9 createConnection(options, oncreate) { 10 const socket = super.createConnection(options, oncreate); 11 socketsCreated++; 12 return socket; 13 } 14} 15 16const server = http.createServer((req, res) => res.end()); 17 18server.listen(0, common.mustCall(() => { 19 const port = server.address().port; 20 const agent = new Agent({ 21 keepAlive: true, 22 maxSockets: 1 23 }); 24 25 const req = http.get({ agent, port }, common.mustCall((res) => { 26 res.resume(); 27 res.on('end', () => { 28 res.destroy(); 29 30 http.get({ agent, port }, common.mustCall((res) => { 31 res.resume(); 32 assert.strictEqual(socketsCreated, 1); 33 agent.destroy(); 34 server.close(); 35 })); 36 }); 37 })); 38 req.end(); 39})); 40