-
Notifications
You must be signed in to change notification settings - Fork 500
/
pipeline-pipelining.js
115 lines (99 loc) · 2.74 KB
/
pipeline-pipelining.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
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
109
110
111
112
113
114
115
'use strict'
const { test } = require('tap')
const { Client } = require('..')
const { createServer } = require('http')
const { kConnect } = require('../lib/core/symbols')
const util = require('../lib/core/util')
test('pipeline pipelining', (t) => {
t.plan(10)
const server = createServer((req, res) => {
t.strictDeepEqual(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.on('disconnect', () => {
t.fail()
})
client[kConnect](() => {
t.strictEqual(client.running, 0)
client.pipeline({
method: 'GET',
path: '/'
}, ({ body }) => body).end().resume()
t.strictEqual(client.busy, true)
t.strictDeepEqual(client.running, 0)
t.strictDeepEqual(client.pending, 1)
client.pipeline({
method: 'GET',
path: '/'
}, ({ body }) => body).end().resume()
t.strictEqual(client.busy, true)
t.strictDeepEqual(client.running, 0)
t.strictDeepEqual(client.pending, 2)
util.queueMicrotask(() => {
t.strictEqual(client.running, 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.on('disconnect', () => {
t.fail()
})
})
client[kConnect](() => {
client.pipeline({
method: 'GET',
path: '/'
}, ({ body }) => body).end().resume()
.on('error', (err) => {
t.ok(err)
})
t.strictEqual(client.busy, true)
t.strictDeepEqual(client.running, 0)
t.strictDeepEqual(client.pending, 1)
client.pipeline({
method: 'GET',
path: '/'
}, ({ body }) => body).end().resume()
t.strictEqual(client.busy, true)
t.strictDeepEqual(client.running, 0)
t.strictDeepEqual(client.pending, 2)
client.pipeline({
method: 'GET',
path: '/'
}, ({ body }) => body).end().resume()
t.strictEqual(client.busy, true)
t.strictDeepEqual(client.running, 0)
t.strictDeepEqual(client.pending, 3)
util.queueMicrotask(() => {
t.strictEqual(client.running, 3)
})
client.close(() => {
t.pass()
})
})
})
})