/
test-pool.js
65 lines (56 loc) 路 1.25 KB
/
test-pool.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict'
var request = require('../index')
, http = require('http')
, tape = require('tape')
var s = http.createServer(function (req, res) {
res.statusCode = 200
res.end('asdf')
})
tape('setup', function(t) {
s.listen(6767, function() {
t.end()
})
})
tape('pool', function(t) {
request({
url: 'http://localhost:6767',
pool: false
}, function(err, res, body) {
t.equal(err, null)
t.equal(res.statusCode, 200)
t.equal(body, 'asdf')
var agent = res.request.agent
t.equal(agent, false)
t.end()
})
})
tape('forever', function(t) {
var r = request({
url: 'http://localhost:6767',
forever: true,
pool: {maxSockets: 1024}
}, function(err, res, body) {
// explicitly shut down the agent
if (r.agent.destroy === typeof 'function') {
r.agent.destroy()
} else {
// node < 0.12
Object.keys(r.agent.sockets).forEach(function (name) {
r.agent.sockets[name].forEach(function (socket) {
socket.end()
})
})
}
t.equal(err, null)
t.equal(res.statusCode, 200)
t.equal(body, 'asdf')
var agent = res.request.agent
t.equal(agent.maxSockets, 1024)
t.end()
})
})
tape('cleanup', function(t) {
s.close(function() {
t.end()
})
})