| 20 | }) |
| 21 | |
| 22 | function httpAgent (t, options, req) { |
| 23 | var r = (req || request)(options, function (_err, res, body) { |
| 24 | t.ok(r.agent instanceof http.Agent, 'is http.Agent') |
| 25 | t.equal(r.agent.options.keepAlive, true, 'is keepAlive') |
| 26 | t.equal(Object.keys(r.agent.sockets).length, 1, '1 socket name') |
| 27 | |
| 28 | var name = (typeof r.agent.getName === 'function') |
| 29 | ? r.agent.getName({port: s.port}) |
| 30 | : 'localhost:' + s.port // node 0.10- |
| 31 | t.equal(r.agent.sockets[name].length, 1, '1 open socket') |
| 32 | |
| 33 | var socket = r.agent.sockets[name][0] |
| 34 | socket.on('close', function () { |
| 35 | t.equal(Object.keys(r.agent.sockets).length, 0, '0 open sockets') |
| 36 | t.end() |
| 37 | }) |
| 38 | socket.end() |
| 39 | }) |
| 40 | } |
| 41 | |
| 42 | function foreverAgent (t, options, req) { |
| 43 | var r = (req || request)(options, function (_err, res, body) { |