-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathRetryHandlerOptions.ts
101 lines (90 loc) · 3.83 KB
/
RetryHandlerOptions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { assert } from "chai";
import { RetryHandlerOptions, ShouldRetry } from "../../../src/middleware/options/RetryHandlerOptions";
describe("RetryHandlerOptions.ts", () => {
describe("Constructor", () => {
it("Should use default values if not given", () => {
const options = new RetryHandlerOptions();
assert.equal(options["delay"], RetryHandlerOptions["DEFAULT_DELAY"]);
assert.equal(options["maxRetries"], RetryHandlerOptions["DEFAULT_MAX_RETRIES"]);
assert.equal(options["shouldRetry"], RetryHandlerOptions["defaultShouldRetry"]);
});
it("Should throw error for both delay and maxRetries are higher than the limit", () => {
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const options = new RetryHandlerOptions(100_000, 1000);
throw new Error("Test Failed - Something wrong with the delay and maxRetries max limit validation");
} catch (error) {
assert.equal(error.name, "MaxLimitExceeded");
}
});
it("Should throw error for delay is higher than the limit", () => {
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const options = new RetryHandlerOptions(100_000, 2);
throw new Error("Test Failed - Test Failed - Something wrong with the delay max limit validation");
} catch (error) {
assert.equal(error.name, "MaxLimitExceeded");
}
});
it("Should throw error for maxRetries is higher than the limit", () => {
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const options = new RetryHandlerOptions(1, 2000);
throw new Error("Test Failed - Something wrong with the maxRetries max limit validation");
} catch (error) {
assert.equal(error.name, "MaxLimitExceeded");
}
});
it("Should throw error for both delay and maxRetries are negative", () => {
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const options = new RetryHandlerOptions(-1, -100);
throw new Error("Test Failed - Something wrong with the delay and maxRetries max limit validation");
} catch (error) {
assert.equal(error.name, "MinExpectationNotMet");
}
});
it("Should throw error for delay is negative", () => {
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const options = new RetryHandlerOptions(-5, 2);
throw new Error("Test Failed - Something wrong with the delay max limit validation");
} catch (error) {
assert.equal(error.name, "MinExpectationNotMet");
}
});
it("Should throw error for maxRetries is negative", () => {
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const options = new RetryHandlerOptions(1, -10);
throw new Error("Test Failed - Something wrong with the maxRetries max limit validation");
} catch (error) {
assert.equal(error.name, "MinExpectationNotMet");
}
});
it("Should accept all the given values", () => {
const delay = 1;
const maxRetries = 3;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const shouldRetry: ShouldRetry = (d, a, req, o, res) => {
return false;
};
const options = new RetryHandlerOptions(delay, maxRetries, shouldRetry);
assert.equal(options.delay, delay);
assert.equal(options.maxRetries, maxRetries);
assert.equal(options.shouldRetry, shouldRetry);
});
});
describe("getMaxDelay", () => {
it("Should return the max delay value", () => {
const options = new RetryHandlerOptions();
assert.equal(options.getMaxDelay(), RetryHandlerOptions["MAX_DELAY"]);
});
});
});