|
| 1 | +import { AdaptiveRetryStrategy } from "./AdaptiveRetryStrategy"; |
1 | 2 | import { DEFAULT_MAX_ATTEMPTS } from "./config";
|
2 | 3 | import {
|
3 | 4 | CONFIG_MAX_ATTEMPTS,
|
|
7 | 8 | } from "./configurations";
|
8 | 9 | import { StandardRetryStrategy } from "./StandardRetryStrategy";
|
9 | 10 |
|
| 11 | +jest.mock("./AdaptiveRetryStrategy"); |
10 | 12 | jest.mock("./StandardRetryStrategy");
|
11 | 13 |
|
12 | 14 | describe(resolveRetryConfig.name, () => {
|
@@ -46,12 +48,69 @@ describe(resolveRetryConfig.name, () => {
|
46 | 48 | const { retryStrategy } = resolveRetryConfig({ maxAttempts, retryMode, retryModeProvider });
|
47 | 49 | await retryStrategy();
|
48 | 50 | expect(StandardRetryStrategy as jest.Mock).toHaveBeenCalledTimes(1);
|
| 51 | + expect(AdaptiveRetryStrategy as jest.Mock).not.toHaveBeenCalled(); |
49 | 52 | const output = await (StandardRetryStrategy as jest.Mock).mock.calls[0][0]();
|
50 | 53 | expect(output).toStrictEqual(maxAttempts);
|
51 | 54 | });
|
52 | 55 | }
|
53 | 56 | });
|
54 | 57 | });
|
| 58 | + |
| 59 | + describe("when retryModeProvider returns 'standard'", () => { |
| 60 | + describe("passes maxAttempts if present", () => { |
| 61 | + beforeEach(() => { |
| 62 | + retryModeProvider.mockResolvedValueOnce("standard"); |
| 63 | + }); |
| 64 | + for (const maxAttempts of [1, 2, 3]) { |
| 65 | + it(`when maxAttempts=${maxAttempts}`, async () => { |
| 66 | + const { retryStrategy } = resolveRetryConfig({ maxAttempts, retryModeProvider }); |
| 67 | + await retryStrategy(); |
| 68 | + expect(retryModeProvider).toHaveBeenCalledTimes(1); |
| 69 | + expect(StandardRetryStrategy as jest.Mock).toHaveBeenCalledTimes(1); |
| 70 | + expect(AdaptiveRetryStrategy as jest.Mock).not.toHaveBeenCalled(); |
| 71 | + const output = await (StandardRetryStrategy as jest.Mock).mock.calls[0][0](); |
| 72 | + expect(output).toStrictEqual(maxAttempts); |
| 73 | + }); |
| 74 | + } |
| 75 | + }); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + describe("AdaptiveRetryStrategy", () => { |
| 80 | + describe("when retryMode=adaptive", () => { |
| 81 | + describe("passes maxAttempts if present", () => { |
| 82 | + const retryMode = "adaptive"; |
| 83 | + for (const maxAttempts of [1, 2, 3]) { |
| 84 | + it(`when maxAttempts=${maxAttempts}`, async () => { |
| 85 | + const { retryStrategy } = resolveRetryConfig({ maxAttempts, retryMode, retryModeProvider }); |
| 86 | + await retryStrategy(); |
| 87 | + expect(StandardRetryStrategy as jest.Mock).not.toHaveBeenCalled(); |
| 88 | + expect(AdaptiveRetryStrategy as jest.Mock).toHaveBeenCalledTimes(1); |
| 89 | + const output = await (AdaptiveRetryStrategy as jest.Mock).mock.calls[0][0](); |
| 90 | + expect(output).toStrictEqual(maxAttempts); |
| 91 | + }); |
| 92 | + } |
| 93 | + }); |
| 94 | + }); |
| 95 | + |
| 96 | + describe("when retryModeProvider returns 'adaptive'", () => { |
| 97 | + describe("passes maxAttempts if present", () => { |
| 98 | + beforeEach(() => { |
| 99 | + retryModeProvider.mockResolvedValueOnce("adaptive"); |
| 100 | + }); |
| 101 | + for (const maxAttempts of [1, 2, 3]) { |
| 102 | + it(`when maxAttempts=${maxAttempts}`, async () => { |
| 103 | + const { retryStrategy } = resolveRetryConfig({ maxAttempts, retryModeProvider }); |
| 104 | + await retryStrategy(); |
| 105 | + expect(retryModeProvider).toHaveBeenCalledTimes(1); |
| 106 | + expect(StandardRetryStrategy as jest.Mock).not.toHaveBeenCalled(); |
| 107 | + expect(AdaptiveRetryStrategy as jest.Mock).toHaveBeenCalledTimes(1); |
| 108 | + const output = await (AdaptiveRetryStrategy as jest.Mock).mock.calls[0][0](); |
| 109 | + expect(output).toStrictEqual(maxAttempts); |
| 110 | + }); |
| 111 | + } |
| 112 | + }); |
| 113 | + }); |
55 | 114 | });
|
56 | 115 | });
|
57 | 116 | });
|
|
0 commit comments