Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const http = require('http') | ||
const Fastify = require('fastify') | ||
const From = require('..') | ||
const got = require('got') | ||
const FakeTimers = require('@sinonjs/fake-timers') | ||
|
||
const clock = FakeTimers.createClock() | ||
|
||
t.autoend(false) | ||
|
||
const target = http.createServer((req, res) => { | ||
t.pass('request proxied') | ||
req.on('data', () => undefined) | ||
req.on('end', () => { | ||
res.flushHeaders() | ||
clock.setTimeout(() => { | ||
res.end() | ||
t.end() | ||
}, 1000) | ||
}) | ||
}) | ||
|
||
async function main () { | ||
await target.listen(0) | ||
|
||
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(0) | ||
|
||
try { | ||
await got.get(`http://localhost:${instance.server.address().port}/`, { retry: 0 }) | ||
} catch (err) { | ||
t.equal(err.response.statusCode, 500) | ||
t.deepEqual(JSON.parse(err.response.body), { | ||
statusCode: 500, | ||
code: 'UND_ERR_BODY_TIMEOUT', | ||
error: 'Internal Server Error', | ||
message: 'Body Timeout Error' | ||
}) | ||
clock.tick(1000) | ||
return | ||
} | ||
|
||
t.fail() | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters