-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathhttp2-target-multi-crash.test.js
58 lines (49 loc) · 1.42 KB
/
http2-target-multi-crash.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
'use strict'
const { test } = require('tap')
const Fastify = require('fastify')
const { request } = require('undici')
const From = require('..')
test('http -> http2 crash multiple times', async (t) => {
const instance = Fastify()
t.teardown(instance.close.bind(instance))
instance.get('/', (_request, reply) => {
reply.from()
})
instance.register(From, {
base: 'http://localhost:3128',
http2: {
sessionTimeout: 6000
},
sessionTimeout: 200
})
await instance.listen({ port: 0 })
let target = setupTarget()
await target.listen({ port: 3128 })
await request(`http://localhost:${instance.server.address().port}`)
await target.close()
target = setupTarget()
await target.listen({ port: 3128 })
await request(`http://localhost:${instance.server.address().port}`)
await target.close()
const result = await request(`http://localhost:${instance.server.address().port}`)
t.equal(result.statusCode, 503)
t.match(result.headers['content-type'], /application\/json/)
t.same(await result.body.json(), {
statusCode: 503,
code: 'FST_REPLY_FROM_SERVICE_UNAVAILABLE',
error: 'Service Unavailable',
message: 'Service Unavailable'
})
function setupTarget () {
const target = Fastify({
http2: true
})
target.get('/', (request, reply) => {
t.pass('request proxied')
reply.code(200).send({
hello: 'world'
})
})
return target
}
})