Skip to content

Commit 08aae09

Browse files
Develop-KIMclaude
andauthored
test: add unexpected disconnect guards to http2 tests (#5533)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 7c84c90 commit 08aae09

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

test/http2-connection.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ test('Should support H2 connection', async t => {
4444
})
4545
after(() => client.close())
4646

47+
client.on('disconnect', () => {
48+
if (!client.closed && !client.destroyed) {
49+
t.fail('unexpected disconnect')
50+
}
51+
})
52+
4753
const response = await client.request({
4854
path: '/',
4955
method: 'GET',
@@ -98,6 +104,12 @@ test('Should support H2 connection(multiple requests)', async t => {
98104
})
99105
after(() => client.close())
100106

107+
client.on('disconnect', () => {
108+
if (!client.closed && !client.destroyed) {
109+
t.fail('unexpected disconnect')
110+
}
111+
})
112+
101113
for (let i = 0; i < 3; i++) {
102114
const sendBody = `seq ${i}`
103115
const body = []
@@ -156,6 +168,12 @@ test('Should support H2 connection (headers as array)', async t => {
156168
})
157169
after(() => client.close())
158170

171+
client.on('disconnect', () => {
172+
if (!client.closed && !client.destroyed) {
173+
t.fail('unexpected disconnect')
174+
}
175+
})
176+
159177
const response = await client.request({
160178
path: '/',
161179
method: 'GET',
@@ -215,6 +233,12 @@ test('Should support multiple header values with semicolon separator', async t =
215233
})
216234
after(() => client.close())
217235

236+
client.on('disconnect', () => {
237+
if (!client.closed && !client.destroyed) {
238+
t.fail('unexpected disconnect')
239+
}
240+
})
241+
218242
const response = await client.request({
219243
path: '/',
220244
method: 'GET',
@@ -298,6 +322,12 @@ test('Should support H2 connection(POST Buffer)', async t => {
298322
})
299323
after(() => client.close())
300324

325+
client.on('disconnect', () => {
326+
if (!client.closed && !client.destroyed) {
327+
t.fail('unexpected disconnect')
328+
}
329+
})
330+
301331
const sendBody = 'hello!'
302332
const body = []
303333
const response = await client.request({

test/http2-continue.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ test('Should handle h2 continue', async t => {
4343
})
4444
after(() => client.close())
4545

46+
client.on('disconnect', () => {
47+
if (!client.closed && !client.destroyed) {
48+
t.fail('unexpected disconnect')
49+
}
50+
})
51+
4652
const response = await client.request({
4753
path: '/',
4854
method: 'POST',
@@ -92,6 +98,12 @@ test('Should deliver an early final response to an Expect: 100-continue request
9298
})
9399
after(() => client.close())
94100

101+
client.on('disconnect', () => {
102+
if (!client.closed && !client.destroyed) {
103+
t.fail('unexpected disconnect')
104+
}
105+
})
106+
95107
const response = await client.request({
96108
path: '/',
97109
method: 'POST',

test/http2-pipelining-default.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ test('h2 client multiplexes concurrent requests by default (#4143)', async t =>
3636
})
3737
after(() => client.close())
3838

39+
client.on('disconnect', () => {
40+
if (!client.closed && !client.destroyed) {
41+
t.fail('unexpected disconnect')
42+
}
43+
})
44+
3945
const results = await Promise.all(
4046
Array.from({ length: N }, () =>
4147
client.request({ path: '/', method: 'GET' })
@@ -96,6 +102,12 @@ test('Pool with connections=1 multiplexes h2 streams on the single session (#414
96102
})
97103
after(() => pool.close())
98104

105+
pool.on('disconnect', () => {
106+
if (!pool.closed && !pool.destroyed) {
107+
t.fail('unexpected disconnect')
108+
}
109+
})
110+
99111
const results = await Promise.all(
100112
Array.from({ length: N }, () =>
101113
pool.request({ path: '/', method: 'GET' })
@@ -277,6 +289,12 @@ test('Client#pipelining keeps its h1 (RFC7230) semantic on an h2 client', async
277289
})
278290
after(() => client.close())
279291

292+
client.on('disconnect', () => {
293+
if (!client.closed && !client.destroyed) {
294+
t.fail('unexpected disconnect')
295+
}
296+
})
297+
280298
// Even after negotiating h2, client.pipelining reflects only the user-set
281299
// h1 pipelining factor — the h2 dispatch limit is maxConcurrentStreams.
282300
const r = await client.request({ path: '/', method: 'GET' })

test/http2-pseudo-headers.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ test('Should provide pseudo-headers in proper order', async t => {
4444
})
4545
after(() => client.close())
4646

47+
client.on('disconnect', () => {
48+
if (!client.closed && !client.destroyed) {
49+
t.fail('unexpected disconnect')
50+
}
51+
})
52+
4753
const response = await client.request({
4854
path: '/',
4955
method: 'GET'
@@ -79,6 +85,12 @@ test('The h2 pseudo-headers is not included in the headers', async t => {
7985
})
8086
after(() => client.close())
8187

88+
client.on('disconnect', () => {
89+
if (!client.closed && !client.destroyed) {
90+
t.fail('unexpected disconnect')
91+
}
92+
})
93+
8294
const response = await client.request({
8395
path: '/',
8496
method: 'GET'

0 commit comments

Comments
 (0)