Skip to content

Commit f809281

Browse files
committed
test: update configurations test s to check for adaptive
1 parent 80236cb commit f809281

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

packages/middleware-retry/src/configurations.spec.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AdaptiveRetryStrategy } from "./AdaptiveRetryStrategy";
12
import { DEFAULT_MAX_ATTEMPTS } from "./config";
23
import {
34
CONFIG_MAX_ATTEMPTS,
@@ -7,6 +8,7 @@ import {
78
} from "./configurations";
89
import { StandardRetryStrategy } from "./StandardRetryStrategy";
910

11+
jest.mock("./AdaptiveRetryStrategy");
1012
jest.mock("./StandardRetryStrategy");
1113

1214
describe(resolveRetryConfig.name, () => {
@@ -46,12 +48,69 @@ describe(resolveRetryConfig.name, () => {
4648
const { retryStrategy } = resolveRetryConfig({ maxAttempts, retryMode, retryModeProvider });
4749
await retryStrategy();
4850
expect(StandardRetryStrategy as jest.Mock).toHaveBeenCalledTimes(1);
51+
expect(AdaptiveRetryStrategy as jest.Mock).not.toHaveBeenCalled();
4952
const output = await (StandardRetryStrategy as jest.Mock).mock.calls[0][0]();
5053
expect(output).toStrictEqual(maxAttempts);
5154
});
5255
}
5356
});
5457
});
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+
});
55114
});
56115
});
57116
});

0 commit comments

Comments
 (0)