Skip to content

Commit

Permalink
fixes tests timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
leorossi committed Sep 30, 2021
1 parent 5628d50 commit 4144ca4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -119,7 +119,7 @@ module.exports = fp(function from (fastify, opts, next) {
const contentLength = requestHeaders['content-length']
let requestImpl
if (retryMethods.has(req.method) && !contentLength) {
requestImpl = createRequestRetry(request, this, retriesCount, retryOnError, 503)
requestImpl = createRequestRetry(request, this, retriesCount, retryOnError)
} else {
requestImpl = request
}
Expand Down
27 changes: 13 additions & 14 deletions test/retry-on-503.js
Expand Up @@ -13,7 +13,7 @@ function createTargetServer (withRetryAfterHeader, stopAfter = 1) {
res.statusCode = 503
res.setHeader('Content-Type', 'text/plain')
if (withRetryAfterHeader) {
res.setHeader('Retry-After', 500)
res.setHeader('Retry-After', 100)
}
return res.end('This Service is Unavailable')
}
Expand All @@ -24,7 +24,7 @@ function createTargetServer (withRetryAfterHeader, stopAfter = 1) {
}

test('Should retry on 503 HTTP error', async function (t) {
t.plan(4)
t.plan(3)
const target = createTargetServer()
await target.listen(0)
t.teardown(target.close.bind(target))
Expand All @@ -42,15 +42,14 @@ test('Should retry on 503 HTTP error', async function (t) {
t.teardown(instance.close.bind(instance))
await instance.listen(0)

const res = await got.get(`http://localhost:${instance.server.address().port}`)
const res = await got.get(`http://localhost:${instance.server.address().port}`, { retry: 0 })
t.equal(res.headers['content-type'], 'text/plain')
t.equal(res.statusCode, 205)
t.equal(res.body.toString(), 'Hello World 2!')
t.pass()
})

test('Should retry on 503 HTTP error with Retry-After response header', async function (t) {
t.plan(4)
t.plan(3)
const target = createTargetServer(true)
await target.listen(0)
t.teardown(target.close.bind(target))
Expand All @@ -68,15 +67,14 @@ test('Should retry on 503 HTTP error with Retry-After response header', async fu
t.teardown(instance.close.bind(instance))
await instance.listen(0)

const res = await got.get(`http://localhost:${instance.server.address().port}`)
const res = await got.get(`http://localhost:${instance.server.address().port}`, { retry: 0 })
t.equal(res.headers['content-type'], 'text/plain')
t.equal(res.statusCode, 205)
t.equal(res.body.toString(), 'Hello World 2!')
t.pass()
})

test('Should abort if server is always returning 503', async function (t) {
t.plan(4)
t.plan(2)
const target = createTargetServer(true, Number.MAX_SAFE_INTEGER)
await target.listen(0)
t.teardown(target.close.bind(target))
Expand All @@ -93,10 +91,11 @@ test('Should abort if server is always returning 503', async function (t) {

t.teardown(instance.close.bind(instance))
await instance.listen(0)

const res = await got.get(`http://localhost:${instance.server.address().port}`)
t.equal(res.headers['content-type'], 'text/plain')
t.equal(res.statusCode, 503)
t.equal(res.body.toString(), 'This Service is Unavailable')
t.pass()
try {
await got.get(`http://localhost:${instance.server.address().port}`, { retry: 0 })
t.fail()
} catch (err) {
t.equal(err.response.statusCode, 503)
t.equal(err.response.body.toString(), 'This Service is Unavailable')
}
})

0 comments on commit 4144ca4

Please sign in to comment.