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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
'use strict'
const { test } = require('tap')
const { Client } = require('..')
const { createServer } = require('http')
const { kConnect } = require('../lib/core/symbols')
const { kBusy, kPending, kRunning } = require('../lib/core/symbols')
test('pipeline pipelining', (t) => {
t.plan(10)
const server = createServer((req, res) => {
t.strictSame(req.headers['transfer-encoding'], undefined)
res.end()
})
t.teardown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
pipelining: 2
})
t.teardown(client.close.bind(client))
client[kConnect](() => {
t.equal(client[kRunning], 0)
client.pipeline({
method: 'GET',
path: '/'
}, ({ body }) => body).end().resume()
t.equal(client[kBusy], true)
t.strictSame(client[kRunning], 0)
t.strictSame(client[kPending], 1)
client.pipeline({
method: 'GET',
path: '/'
}, ({ body }) => body).end().resume()
t.equal(client[kBusy], true)
t.strictSame(client[kRunning], 0)
t.strictSame(client[kPending], 2)
process.nextTick(() => {
t.equal(client[kRunning], 2)
})
})
})
})
test('pipeline pipelining retry', (t) => {
t.plan(13)
let count = 0
const server = createServer((req, res) => {
if (count++ === 0) {
res.destroy()
} else {
res.end()
}
})
t.teardown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
pipelining: 3
})
t.teardown(client.destroy.bind(client))
client.once('disconnect', () => {
t.pass()
})
client[kConnect](() => {
client.pipeline({
method: 'GET',
path: '/'
}, ({ body }) => body).end().resume()
.on('error', (err) => {
t.ok(err)
})
t.equal(client[kBusy], true)
t.strictSame(client[kRunning], 0)
t.strictSame(client[kPending], 1)
client.pipeline({
method: 'GET',
path: '/'
}, ({ body }) => body).end().resume()
t.equal(client[kBusy], true)
t.strictSame(client[kRunning], 0)
t.strictSame(client[kPending], 2)
client.pipeline({
method: 'GET',
path: '/'
}, ({ body }) => body).end().resume()
t.equal(client[kBusy], true)
t.strictSame(client[kRunning], 0)
t.strictSame(client[kPending], 3)
process.nextTick(() => {
t.equal(client[kRunning], 3)
})
client.close(() => {
t.pass()
})
})
})
})
|