1
0
Fork 0
mirror of https://github.com/actions/toolkit synced 2025-05-09 00:22:56 +00:00

only retry downloadtool on 500s and 408 and 429 (#373)

This commit is contained in:
eric sciple 2020-03-09 14:35:53 -04:00 committed by GitHub
parent 82fbe5da0f
commit 5859d7172e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 136 additions and 38 deletions

View file

@ -66,7 +66,7 @@ describe('retry-helper tests', () => {
expect(info[3]).toMatch(/Waiting .+ seconds before trying again/)
})
it('all attempts fail succeeds', async () => {
it('all attempts fail', async () => {
let attempts = 0
let error: Error = (null as unknown) as Error
try {
@ -84,4 +84,42 @@ describe('retry-helper tests', () => {
expect(info[2]).toBe('some error 2')
expect(info[3]).toMatch(/Waiting .+ seconds before trying again/)
})
it('checks retryable after first attempt', async () => {
let attempts = 0
let error: Error = (null as unknown) as Error
try {
await retryHelper.execute(
async () => {
throw new Error(`some error ${++attempts}`)
},
() => false
)
} catch (err) {
error = err
}
expect(error.message).toBe('some error 1')
expect(attempts).toBe(1)
expect(info).toHaveLength(0)
})
it('checks retryable after second attempt', async () => {
let attempts = 0
let error: Error = (null as unknown) as Error
try {
await retryHelper.execute(
async () => {
throw new Error(`some error ${++attempts}`)
},
(e: Error) => e.message === 'some error 1'
)
} catch (err) {
error = err
}
expect(error.message).toBe('some error 2')
expect(attempts).toBe(2)
expect(info).toHaveLength(2)
expect(info[0]).toBe('some error 1')
expect(info[1]).toMatch(/Waiting .+ seconds before trying again/)
})
})