-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and add tests for retry options
- Loading branch information
Luke Tomlinson
committed
Sep 23, 2022
1 parent
355d895
commit 660d907
Showing
4 changed files
with
293 additions
and
185 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
|
||
| import {getRetryOptions} from '../src/retry-options' | ||
|
|
||
| describe('getRequestOptions', () => { | ||
| test('retries disabled if retries == 0', async () => { | ||
| const [retryOptions, requestOptions] = getRetryOptions(0, 8, [ | ||
| 400, | ||
| 500, | ||
| 502 | ||
| ]) | ||
|
|
||
| expect(retryOptions.enabled).toBe(false) | ||
| expect(retryOptions.doNotRetry).toBeFalsy() | ||
|
|
||
| expect(requestOptions.retries).toBeFalsy() | ||
| }) | ||
|
|
||
| test('properties set if retries > 0', async () => { | ||
| const [retryOptions, requestOptions] = getRetryOptions(1, 8, [ | ||
| 400, | ||
| 500, | ||
| 502 | ||
| ]) | ||
|
|
||
| expect(retryOptions.enabled).toBe(true) | ||
| expect(retryOptions.doNotRetry).toEqual([400, 500, 502]) | ||
|
|
||
| expect(requestOptions.retries).toEqual(1) | ||
| expect(requestOptions.retryAfter).toEqual(8) | ||
| }) | ||
|
|
||
| test('properties set if retries > 0', async () => { | ||
| const [retryOptions, requestOptions] = getRetryOptions(1, 8, [ | ||
| 400, | ||
| 500, | ||
| 502 | ||
| ]) | ||
|
|
||
| expect(retryOptions.enabled).toBe(true) | ||
| expect(retryOptions.doNotRetry).toEqual([400, 500, 502]) | ||
|
|
||
| expect(requestOptions.retries).toEqual(1) | ||
| expect(requestOptions.retryAfter).toEqual(8) | ||
| }) | ||
|
|
||
| test('retryAfter can be set to zero', async () => { | ||
| const [retryOptions, requestOptions] = getRetryOptions(1, 0, [ | ||
| 400, | ||
| 500, | ||
| 502 | ||
| ]) | ||
|
|
||
| expect(retryOptions.enabled).toBe(true) | ||
| expect(retryOptions.doNotRetry).toEqual([400, 500, 502]) | ||
|
|
||
| expect(requestOptions.retries).toEqual(1) | ||
| expect(requestOptions.retryAfter).toEqual(0) | ||
| }) | ||
|
|
||
| test('retryOptions.doNotRetry not set if doNotRetry isEmpty', async () => { | ||
| const [retryOptions, requestOptions] = getRetryOptions(1, 0, []) | ||
|
|
||
| expect(retryOptions.enabled).toBe(true) | ||
| expect(retryOptions.doNotRetry).toBeUndefined() | ||
|
|
||
| expect(requestOptions.retries).toEqual(1) | ||
| expect(requestOptions.retryAfter).toEqual(0) | ||
| }) | ||
| }) |
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
Oops, something went wrong.