-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathhttp2-timeout-disabled.test.js
90 lines (69 loc) · 2.38 KB
/
http2-timeout-disabled.test.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
'use strict'
const { test } = require('tap')
const Fastify = require('fastify')
const { request, Agent } = require('undici')
const From = require('..')
test('http2 request timeout disabled', async (t) => {
const target = Fastify({ http2: true })
t.teardown(target.close.bind(target))
target.get('/', () => {
t.pass('request arrives')
})
await target.listen({ port: 0 })
const instance = Fastify()
t.teardown(instance.close.bind(instance))
instance.register(From, {
base: `http://localhost:${target.server.address().port}`,
http2: { requestTimeout: 0, sessionTimeout: 16000 }
})
instance.get('/', (_request, reply) => {
reply.from(`http://localhost:${target.server.address().port}/`)
})
await instance.listen({ port: 0 })
const result = await Promise.race([
request(`http://localhost:${instance.server.address().port}/`, {
dispatcher: new Agent({
pipelining: 0
})
}),
new Promise(resolve => setTimeout(resolve, 11000, 'passed'))
])
// if we wait 11000 ms without a timeout error, we assume disabling the timeout worked
// 10000 ms is the default timeout
t.equal(result, 'passed')
})
test('http2 session timeout disabled', async (t) => {
const target = Fastify({ http2: true })
target.get('/', () => {
t.pass('request arrives')
})
await target.listen({ port: 0 })
const instance = Fastify()
instance.register(From, {
sessionTimeout: 3000,
destroyAgent: true,
base: `http://localhost:${target.server.address().port}`,
http2: { requestTimeout: 0, sessionTimeout: 0 }
})
instance.get('/', (_request, reply) => {
reply.from(`http://localhost:${target.server.address().port}/`)
})
await instance.listen({ port: 0 })
const abortController = new AbortController()
const result = await Promise.race([
request(`http://localhost:${instance.server.address().port}/`, {
dispatcher: new Agent({
pipelining: 0
}),
signal: abortController.signal
}),
new Promise(resolve => setTimeout(resolve, 4000, 'passed'))
])
// clean up right after the timeout, otherwise test will hang
abortController.abort()
target.close()
instance.close()
// if we wait 4000 ms without a timeout error, we assume disabling the session timeout for reply-from worked
// because we pass 3000 ms as session timeout to the Fastify options itself
t.equal(result, 'passed')
})