Skip to content

Commit

Permalink
fixed a responseType stream called and endpoint...
Browse files Browse the repository at this point in the history
  • Loading branch information
ildella committed Nov 22, 2023
1 parent 1c2b2de commit cacc916
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
19 changes: 18 additions & 1 deletion tests/http/http-timeout.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const axios = require('axios')

Check warning on line 1 in tests/http/http-timeout.test.js

View workflow job for this annotation

GitHub Actions / test (20)

'axios' is assigned a value but never used
const {jsonClient} = global.t

test('basic http test', async () => {
test('timeout is too short', async () => {
const {post} = jsonClient({timeout: 100})
await expect(post('/long', {})).rejects.toMatchObject({
code: 'ETIMEDOUT',
Expand All @@ -14,3 +15,19 @@ test('timeout is ok', async () => {
const {status} = await jsonClient({timeout: 500}).post('/long', {})
expect(status).toEqual(200)
})

test('short timeout with response stream', async () => {
const {post} = jsonClient({timeout: 100, responseType: 'stream'})
await expect(post('/stream', {})).rejects.toMatchObject({
code: 'ETIMEDOUT',
timeout: 100,
status: 408,
message: 'Timed out.',
})
})

test.only('wait', async () => {

Check failure on line 29 in tests/http/http-timeout.test.js

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected focused test
const {post} = jsonClient({timeout: 500, responseType: 'stream'})
const {status} = await post('/stream', {})
expect(status).toEqual(201)
})
13 changes: 12 additions & 1 deletion tests/http/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module.exports = app => {
})

app.get('/booom', () => {
// console.log(request.headers)
// eslint-disable-next-line fp/no-throw
throw new Error('big booom')
})
Expand All @@ -37,10 +36,22 @@ module.exports = app => {
})

app.post('/long', async () => {
// console.log('Called...')
await sleep(400)
return {slow: true}
})

app.post('/stream', async (request, reply) => {
reply.raw.setHeader('transfer-encoding', 'chunked')
reply.code(201)
// reply.hijack()
// console.log('Stream started...')
await sleep(400)
reply.raw.write('new line...')
// console.log('Stream finished.')
reply.raw.end()
})

app.get('/async-pipe-booom', async (request, reply) => {
await __([1])
// eslint-disable-next-line require-await
Expand Down

0 comments on commit cacc916

Please sign in to comment.