Fix flaky test (#1158)

* Fix flaky test

* Fix #1154
This commit is contained in:
Tomas Della Vedova
2020-04-14 14:39:53 +02:00
committed by GitHub
parent 203bab278d
commit fd8f02b9df
4 changed files with 59 additions and 36 deletions

View File

@ -578,9 +578,8 @@ test('Retry mechanism', t => {
if (count > 0) {
res.end(JSON.stringify({ hello: 'world' }))
} else {
setTimeout(() => {
res.end(JSON.stringify({ hello: 'world' }))
}, 1000)
res.statusCode = 504
res.end(JSON.stringify({ error: true }))
}
count++
}
@ -603,7 +602,6 @@ test('Retry mechanism', t => {
connectionPool: pool,
serializer: new Serializer(),
maxRetries: 1,
requestTimeout: 250,
sniffInterval: false,
sniffOnStart: false
})
@ -624,15 +622,10 @@ test('Should not retry if the body is a stream', t => {
var count = 0
function handler (req, res) {
res.setHeader('Content-Type', 'application/json;utf=8')
if (count > 0) {
res.end(JSON.stringify({ hello: 'world' }))
} else {
setTimeout(() => {
res.end(JSON.stringify({ hello: 'world' }))
}, 1000)
}
count++
res.setHeader('Content-Type', 'application/json;utf=8')
res.statusCode = 504
res.end(JSON.stringify({ error: true }))
}
buildServer(handler, ({ port }, server) => {
@ -653,7 +646,6 @@ test('Should not retry if the body is a stream', t => {
connectionPool: pool,
serializer: new Serializer(),
maxRetries: 1,
requestTimeout: 10,
sniffInterval: false,
sniffOnStart: false
})
@ -663,7 +655,7 @@ test('Should not retry if the body is a stream', t => {
path: '/hello',
body: intoStream(JSON.stringify({ hello: 'world' }))
}, (err, { body }) => {
t.ok(err instanceof TimeoutError)
t.ok(err instanceof ResponseError)
t.strictEqual(count, 1)
server.stop()
})
@ -679,9 +671,8 @@ test('Custom retry mechanism', t => {
if (count > 0) {
res.end(JSON.stringify({ hello: 'world' }))
} else {
setTimeout(() => {
res.end(JSON.stringify({ hello: 'world' }))
}, 1000)
res.statusCode = 504
res.end(JSON.stringify({ error: true }))
}
count++
}
@ -704,7 +695,6 @@ test('Custom retry mechanism', t => {
connectionPool: pool,
serializer: new Serializer(),
maxRetries: 0,
requestTimeout: 250,
sniffInterval: false,
sniffOnStart: false
})