-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathundici-timeout-body-partial.test.js
55 lines (44 loc) · 1.22 KB
/
undici-timeout-body-partial.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
'use strict'
const t = require('tap')
const http = require('node:http')
const Fastify = require('fastify')
const { request, Agent } = require('undici')
const From = require('..')
const FakeTimers = require('@sinonjs/fake-timers')
const clock = FakeTimers.createClock()
t.test('undici body timeout', async (t) => {
const target = http.createServer((req, res) => {
t.pass('request proxied')
req.on('data', () => undefined)
req.on('end', () => {
res.writeHead(200)
res.flushHeaders()
res.write('test')
clock.setTimeout(() => {
res.end()
t.end()
}, 1000)
})
})
await new Promise(resolve => target.listen({ port: 0 }, resolve))
const instance = Fastify()
t.teardown(instance.close.bind(instance))
t.teardown(target.close.bind(target))
instance.register(From, {
base: `http://localhost:${target.address().port}`,
undici: {
bodyTimeout: 100
}
})
instance.get('/', (_request, reply) => {
reply.from()
})
await instance.listen({ port: 0 })
const result = await request(`http://localhost:${instance.server.address().port}/`, {
dispatcher: new Agent({
pipelining: 0
})
})
t.equal(result.statusCode, 200)
clock.tick(1000)
})