Skip to content

Commit b958ea0

Browse files
authored
fix: Fix http2-dispatcher test (#4640)
1 parent 37fbd5c commit b958ea0

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

test/http2-dispatcher.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ test('Dispatcher#Stream', async t => {
2323
stream.on('data', chunk => {
2424
requestBody += chunk
2525
})
26+
stream.on('error', err => {
27+
t.fail(err)
28+
})
2629

2730
stream.respond({ ':status': 200, 'x-custom': 'custom-header' })
2831
stream.end('hello h2!')
@@ -74,6 +77,10 @@ test('Dispatcher#Pipeline', async t => {
7477
requestBody += chunk
7578
})
7679

80+
stream.on('error', err => {
81+
t.fail(err)
82+
})
83+
7784
stream.respond({ ':status': 200, 'x-custom': 'custom-header' })
7885
stream.end('hello h2!')
7986
})
@@ -137,6 +144,10 @@ test('Dispatcher#Connect', async t => {
137144
return
138145
}
139146

147+
stream.on('error', err => {
148+
t.fail(err)
149+
})
150+
140151
const forward = new Client(`https://localhost:${server.address().port}`, {
141152
connect: {
142153
rejectUnauthorized: false
@@ -156,7 +167,7 @@ test('Dispatcher#Connect', async t => {
156167
})
157168

158169
stream.respond({ ':status': 200, 'x-my-header': response.headers['x-my-header'] })
159-
pipeline(response.body, stream, () => {})
170+
response.body.pipe(stream)
160171
} catch (err) {
161172
stream.destroy(err)
162173
}
@@ -171,6 +182,10 @@ test('Dispatcher#Connect', async t => {
171182
t.strictEqual(requestBody, expectedBody)
172183
})
173184

185+
stream.on('error', err => {
186+
t.fail(err)
187+
})
188+
174189
stream.respond({ ':status': 200, 'x-my-header': headers['x-my-header'] })
175190
stream.end('helloworld')
176191
})
@@ -199,9 +214,7 @@ test('Dispatcher#Connect', async t => {
199214
t.strictEqual(responseBody, 'helloworld')
200215
})
201216
socket.setEncoding('utf-8')
202-
socket.cork()
203217
socket.write(expectedBody)
204-
socket.uncork()
205218
socket.end()
206219

207220
await t.completed
@@ -213,6 +226,12 @@ test('Dispatcher#Upgrade', async t => {
213226
const server = createSecureServer(await pem.generate({ opts: { keySize: 2048 } }))
214227

215228
server.on('stream', (stream, headers) => {
229+
stream.on('error', err => {
230+
t.fail(err)
231+
})
232+
233+
stream.resume()
234+
216235
stream.end()
217236
})
218237

@@ -244,6 +263,10 @@ test('Dispatcher#destroy', async t => {
244263
const server = createSecureServer(await pem.generate({ opts: { keySize: 2048 } }))
245264

246265
server.on('stream', (stream, headers) => {
266+
stream.on('error', err => {
267+
t.fail(err)
268+
})
269+
stream.resume()
247270
setTimeout(stream.end.bind(stream), 1500)
248271
})
249272

@@ -329,6 +352,10 @@ test('Should handle h2 request without body', async t => {
329352
':status': 200
330353
})
331354

355+
stream.on('error', err => {
356+
t.fail(err)
357+
})
358+
332359
for await (const chunk of stream) {
333360
requestChunks.push(chunk)
334361
}

0 commit comments

Comments
 (0)