@mimik/request-retry 4.0.6 → 4.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/pre-commit +0 -2
- package/.husky/pre-push +0 -2
- package/README.md +10 -9
- package/eslint.config.js +9 -8
- package/index.js +12 -15
- package/lib/rp-axios-wrapper.js +1 -1
- package/manual-test/man.js +1 -1
- package/manual-test/retryMockMan.js +4 -4
- package/manual-test/testEnv.js +1 -1
- package/manual-test/testRace.js +1 -4
- package/package.json +17 -17
- package/test/retryMock.js +3 -3
- package/test/rpRetry.spec.js +63 -6
- package/.nycrc +0 -4
package/.husky/pre-commit
CHANGED
package/.husky/pre-push
CHANGED
package/README.md
CHANGED
|
@@ -4,20 +4,21 @@
|
|
|
4
4
|
**Example**
|
|
5
5
|
```js
|
|
6
6
|
import { rpRetry } from '@mimik/request-retry';
|
|
7
|
-
or
|
|
7
|
+
// or
|
|
8
8
|
import rp from '@mimik/request-retry';
|
|
9
9
|
```
|
|
10
10
|
<a name="module_request-retry..rpRetry"></a>
|
|
11
11
|
|
|
12
|
-
### request-retry~rpRetry(options) ⇒ <code>Promise
|
|
12
|
+
### request-retry~rpRetry(options) ⇒ <code>Promise.<object></code>
|
|
13
13
|
Make a request with retries.
|
|
14
14
|
|
|
15
15
|
**Kind**: inner method of [<code>request-retry</code>](#module_request-retry)
|
|
16
|
+
**Returns**: <code>Promise.<object></code> - A bluebird promise (supports cancellation).
|
|
16
17
|
**Category**: async
|
|
17
18
|
**Throws**:
|
|
18
19
|
|
|
19
|
-
- <code>Error</code> An error produced by `getRichError`, wrapping an
|
|
20
|
-
[
|
|
20
|
+
- <code>Error</code> An error produced by `getRichError`, wrapping an
|
|
21
|
+
[Axios](https://www.npmjs.com/package/axios) error or a `TimeoutError`.
|
|
21
22
|
|
|
22
23
|
The following properties may be added to the `options` object under the `retry` property:
|
|
23
24
|
- retries `{int}`: Maximum number of retries, independent of the `retryStrategy`. Default: `2`.
|
|
@@ -27,9 +28,9 @@ The following properties may be added to the `options` object under the `retry`
|
|
|
27
28
|
- delayStrategy `{function}`: A function that returns the delay (in milliseconds) to wait before the next retry.
|
|
28
29
|
Signature: `(nbRetry, err, options, correlationId)`. Must return a number `> 0` and `< 30000`; otherwise `delay` is used.
|
|
29
30
|
- logLevel `{object}`: Controls logging behavior:
|
|
30
|
-
- *response*: Log level for responses.
|
|
31
|
-
- *error*: Log level for errors.
|
|
32
|
-
- *request*: Log level for requests.
|
|
31
|
+
- *response*: Log level for responses. Invalid values fall back to `silly`.
|
|
32
|
+
- *error*: Log level for errors. Invalid values fall back to `silly`.
|
|
33
|
+
- *request*: Log level for requests. Invalid values fall back to `silly`.
|
|
33
34
|
- *responseDetails*: Detail level when displaying the response: `count`, `type`, or `full`. Default: `type`
|
|
34
35
|
(invalid values fall back to `type`).
|
|
35
36
|
- *responseName*: Label associated with the response. Default: `response`
|
|
@@ -55,8 +56,8 @@ defaultRetry = (...args) => {
|
|
|
55
56
|
```
|
|
56
57
|
|
|
57
58
|
If `logLevel` is empty, requests and responses are logged at `info`, the response is logged with full details
|
|
58
|
-
under the `response` property, and request errors generate a `warn`. If
|
|
59
|
-
the provided keys
|
|
59
|
+
under the `response` property, and request errors generate a `warn`. If logLevel is provided but incomplete,
|
|
60
|
+
only the provided keys are active; missing keys disable that logging.
|
|
60
61
|
|
|
61
62
|
If not already set, the `User-Agent` header is set to:
|
|
62
63
|
`mimik-{serverType}/{serverVersion}/{serverId} {architecture} {node}`.
|
package/eslint.config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import globals from 'globals';
|
|
1
2
|
import importPlugin from 'eslint-plugin-import';
|
|
2
3
|
import js from '@eslint/js';
|
|
3
4
|
import processDoc from '@mimik/eslint-plugin-document-env';
|
|
@@ -10,13 +11,13 @@ const MAX_LINES_IN_FUNCTION = 150;
|
|
|
10
11
|
const MAX_STATEMENTS_IN_FUNCTION = 45;
|
|
11
12
|
const MIN_KEYS_IN_OBJECT = 10;
|
|
12
13
|
const MAX_COMPLEXITY = 30;
|
|
13
|
-
const ECMA_VERSION =
|
|
14
|
+
const ECMA_VERSION = 'latest';
|
|
14
15
|
const MAX_DEPTH = 6;
|
|
15
16
|
const ALLOWED_CONSTANTS = [0, 1, -1];
|
|
16
17
|
|
|
17
18
|
export default [
|
|
18
19
|
{
|
|
19
|
-
ignores: ['mochawesome-report/**', 'node_modules/**', 'dist/**'],
|
|
20
|
+
ignores: ['coverage/**', 'mochawesome-report/**', 'node_modules/**', 'dist/**'],
|
|
20
21
|
},
|
|
21
22
|
importPlugin.flatConfigs.recommended,
|
|
22
23
|
stylistic.configs.recommended,
|
|
@@ -28,10 +29,8 @@ export default [
|
|
|
28
29
|
languageOptions: {
|
|
29
30
|
ecmaVersion: ECMA_VERSION,
|
|
30
31
|
globals: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
it: 'readonly',
|
|
34
|
-
require: 'readonly',
|
|
32
|
+
...globals.mocha,
|
|
33
|
+
...globals.nodeBuiltin,
|
|
35
34
|
},
|
|
36
35
|
sourceType: 'module',
|
|
37
36
|
},
|
|
@@ -39,6 +38,7 @@ export default [
|
|
|
39
38
|
'@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
|
|
40
39
|
'@stylistic/line-comment-position': ['off'],
|
|
41
40
|
'@stylistic/max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true }],
|
|
41
|
+
'@stylistic/quotes': ['warn', 'single'],
|
|
42
42
|
'@stylistic/semi': ['error', 'always'],
|
|
43
43
|
'capitalized-comments': ['off'],
|
|
44
44
|
'complexity': ['error', MAX_COMPLEXITY],
|
|
@@ -49,19 +49,20 @@ export default [
|
|
|
49
49
|
'init-declarations': ['off'],
|
|
50
50
|
'linebreak-style': ['off'],
|
|
51
51
|
'max-depth': ['error', MAX_DEPTH],
|
|
52
|
+
'max-len': ['off'],
|
|
52
53
|
'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true, skipBlankLines: true }],
|
|
53
54
|
'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true, skipBlankLines: true }],
|
|
54
55
|
'max-params': ['error', MAX_FUNCTION_PARAMETERS],
|
|
55
56
|
'max-statements': ['warn', MAX_STATEMENTS_IN_FUNCTION],
|
|
56
57
|
'no-confusing-arrow': ['off'],
|
|
57
58
|
'no-inline-comments': ['off'],
|
|
58
|
-
'no-magic-numbers': ['error', { ignore: ALLOWED_CONSTANTS, enforceConst: true, detectObjects:
|
|
59
|
+
'no-magic-numbers': ['error', { ignore: ALLOWED_CONSTANTS, enforceConst: true, detectObjects: false }],
|
|
59
60
|
'no-process-env': ['error'],
|
|
60
61
|
'no-ternary': ['off'],
|
|
61
62
|
'no-undefined': ['off'],
|
|
62
63
|
'one-var': ['error', 'never'],
|
|
63
64
|
'processDoc/validate-document-env': ['error'],
|
|
64
|
-
'quotes': ['
|
|
65
|
+
'quotes': ['off'],
|
|
65
66
|
'sort-imports': ['error', { allowSeparatedGroups: true }],
|
|
66
67
|
'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false, allowLineSeparatedGroups: true }],
|
|
67
68
|
},
|
package/index.js
CHANGED
|
@@ -25,10 +25,8 @@ const DEFAULT_LOGLEVEL_RESPONSE = 'info';
|
|
|
25
25
|
const DEFAULT_LOGLEVEL_ERROR = 'warn';
|
|
26
26
|
const DEFAULT_LOGLEVEL_REQUEST = 'info';
|
|
27
27
|
|
|
28
|
-
const MILLI_SECONDS = 0;
|
|
29
|
-
const MILLI_NANO_SECONDS = 1;
|
|
30
28
|
const MILLI = 1000;
|
|
31
|
-
const
|
|
29
|
+
const NANO_TO_MS = 1000000;
|
|
32
30
|
|
|
33
31
|
Promise.config({ cancellation: true });
|
|
34
32
|
|
|
@@ -36,7 +34,7 @@ Promise.config({ cancellation: true });
|
|
|
36
34
|
* @module request-retry
|
|
37
35
|
* @example
|
|
38
36
|
* import { rpRetry } from '@mimik/request-retry';
|
|
39
|
-
* or
|
|
37
|
+
* // or
|
|
40
38
|
* import rp from '@mimik/request-retry';
|
|
41
39
|
*/
|
|
42
40
|
|
|
@@ -51,10 +49,10 @@ Promise.config({ cancellation: true });
|
|
|
51
49
|
* The `validateStatus` option is disabled: an error is thrown for status codes outside **[200, 300)**.
|
|
52
50
|
* An additional option, `resolveWithFullResponse`, controls the return shape:
|
|
53
51
|
* when `true`, the full Axios response object is returned; when `false` or omitted, only `response.data` is returned.
|
|
54
|
-
* @return {Promise}
|
|
52
|
+
* @return {Promise<object>} A bluebird promise (supports cancellation).
|
|
55
53
|
* @fulfil {object} - The Axios response when `resolveWithFullResponse` is `true`; otherwise `response.data`.
|
|
56
|
-
* @throws {Error} An error produced by `getRichError`, wrapping an
|
|
57
|
-
* [
|
|
54
|
+
* @throws {Error} An error produced by `getRichError`, wrapping an
|
|
55
|
+
* [Axios](https://www.npmjs.com/package/axios) error or a `TimeoutError`.
|
|
58
56
|
*
|
|
59
57
|
* The following properties may be added to the `options` object under the `retry` property:
|
|
60
58
|
* - retries `{int}`: Maximum number of retries, independent of the `retryStrategy`. Default: `2`.
|
|
@@ -64,9 +62,9 @@ Promise.config({ cancellation: true });
|
|
|
64
62
|
* - delayStrategy `{function}`: A function that returns the delay (in milliseconds) to wait before the next retry.
|
|
65
63
|
* Signature: `(nbRetry, err, options, correlationId)`. Must return a number `> 0` and `< 30000`; otherwise `delay` is used.
|
|
66
64
|
* - logLevel `{object}`: Controls logging behavior:
|
|
67
|
-
* - *response*: Log level for responses.
|
|
68
|
-
* - *error*: Log level for errors.
|
|
69
|
-
* - *request*: Log level for requests.
|
|
65
|
+
* - *response*: Log level for responses. Invalid values fall back to `silly`.
|
|
66
|
+
* - *error*: Log level for errors. Invalid values fall back to `silly`.
|
|
67
|
+
* - *request*: Log level for requests. Invalid values fall back to `silly`.
|
|
70
68
|
* - *responseDetails*: Detail level when displaying the response: `count`, `type`, or `full`. Default: `type`
|
|
71
69
|
* (invalid values fall back to `type`).
|
|
72
70
|
* - *responseName*: Label associated with the response. Default: `response`
|
|
@@ -92,8 +90,8 @@ Promise.config({ cancellation: true });
|
|
|
92
90
|
* ```
|
|
93
91
|
*
|
|
94
92
|
* If `logLevel` is empty, requests and responses are logged at `info`, the response is logged with full details
|
|
95
|
-
* under the `response` property, and request errors generate a `warn`. If
|
|
96
|
-
* the provided keys
|
|
93
|
+
* under the `response` property, and request errors generate a `warn`. If logLevel is provided but incomplete,
|
|
94
|
+
* only the provided keys are active; missing keys disable that logging.
|
|
97
95
|
*
|
|
98
96
|
* If not already set, the `User-Agent` header is set to:
|
|
99
97
|
* `mimik-{serverType}/{serverVersion}/{serverId} {architecture} {node}`.
|
|
@@ -104,7 +102,7 @@ Promise.config({ cancellation: true });
|
|
|
104
102
|
* - `qs` is mapped to Axios `params`.
|
|
105
103
|
*/
|
|
106
104
|
export const rpRetry = (origOptions) => {
|
|
107
|
-
const startHrTime = process.hrtime();
|
|
105
|
+
const startHrTime = process.hrtime.bigint();
|
|
108
106
|
const options = origOptions;
|
|
109
107
|
const { metrics } = options;
|
|
110
108
|
const enteredUrl = options.uri || options.url;
|
|
@@ -118,8 +116,7 @@ export const rpRetry = (origOptions) => {
|
|
|
118
116
|
let mainTimeout;
|
|
119
117
|
const measure = (statusCode) => {
|
|
120
118
|
if (metrics && metrics.HTTPRequestDuration) {
|
|
121
|
-
const
|
|
122
|
-
const elapsedTimeInMs = elapsedHrTime[MILLI_SECONDS] * MILLI + elapsedHrTime[MILLI_NANO_SECONDS] / NANO;
|
|
119
|
+
const elapsedTimeInMs = Number(process.hrtime.bigint() - startHrTime) / NANO_TO_MS;
|
|
123
120
|
|
|
124
121
|
metrics.HTTPRequestDuration
|
|
125
122
|
.labels('rpRetry', options.method, metrics.url || enteredUrl, enteredUrl.includes('?'), statusCode)
|
package/lib/rp-axios-wrapper.js
CHANGED
package/manual-test/man.js
CHANGED
|
@@ -30,11 +30,11 @@ let message;
|
|
|
30
30
|
|
|
31
31
|
app.use(bodyParser.json());
|
|
32
32
|
app.get(`${config.base}${config.path}`, (req, res) => {
|
|
33
|
-
if (nbRequest === 0) message = '
|
|
33
|
+
if (nbRequest === 0) message = 'Received first request';
|
|
34
34
|
else {
|
|
35
|
-
const
|
|
35
|
+
const timeLapse = Date.now() - time;
|
|
36
36
|
|
|
37
|
-
message = `Received ${nbRequest} retry with
|
|
37
|
+
message = `Received ${nbRequest} retry with timelapse ${timeLapse}`;
|
|
38
38
|
}
|
|
39
39
|
console.log('----->', message);
|
|
40
40
|
time = Date.now();
|
|
@@ -57,7 +57,7 @@ app.post(`${config.base}${config.path}`, (req, res) => {
|
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
app.post('/logs/:id', (req, res) => {
|
|
60
|
-
console.log('--->', '
|
|
60
|
+
console.log('--->', 'Received a log');
|
|
61
61
|
console.log('---> id:', req.params.id);
|
|
62
62
|
console.log('---> body:', req.body);
|
|
63
63
|
res.statusCode = config.post.success;
|
package/manual-test/testEnv.js
CHANGED
package/manual-test/testRace.js
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/request-retry",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.8",
|
|
4
4
|
"description": "Request retry wrapping axios",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"lint": "eslint . --no-error-on-unmatched-pattern",
|
|
9
9
|
"docs": "jsdoc2md index.js > README.md",
|
|
10
|
-
"test": "mocha --reporter mochawesome --bail --check-leaks test/",
|
|
11
|
-
"test-ci": "c8 --reporter=lcov --reporter=text npm test
|
|
10
|
+
"test": "mocha --reporter mochawesome --bail --check-leaks --exit test/",
|
|
11
|
+
"test-ci": "c8 --reporter=lcov --reporter=text npm test",
|
|
12
12
|
"prepublishOnly": "npm run docs && npm run lint && npm run test-ci",
|
|
13
13
|
"commit-ready": "npm run docs && npm run lint && npm run test-ci"
|
|
14
14
|
},
|
|
@@ -29,27 +29,27 @@
|
|
|
29
29
|
"url": "https://bitbucket.org/mimiktech/request-retry"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@mimik/request-helper": "^2.0.
|
|
33
|
-
"@mimik/response-helper": "^4.0.
|
|
34
|
-
"@mimik/sumologic-winston-logger": "^2.1.
|
|
35
|
-
"axios": "1.
|
|
32
|
+
"@mimik/request-helper": "^2.0.5",
|
|
33
|
+
"@mimik/response-helper": "^4.0.10",
|
|
34
|
+
"@mimik/sumologic-winston-logger": "^2.1.12",
|
|
35
|
+
"axios": "1.13.5",
|
|
36
36
|
"bluebird": "3.7.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@eslint/js": "9.
|
|
39
|
+
"@eslint/js": "9.39.2",
|
|
40
40
|
"@mimik/eslint-plugin-document-env": "^2.0.8",
|
|
41
|
-
"@stylistic/eslint-plugin": "5.
|
|
42
|
-
"
|
|
43
|
-
"body-parser": "2.2.0",
|
|
41
|
+
"@stylistic/eslint-plugin": "5.9.0",
|
|
42
|
+
"body-parser": "2.2.2",
|
|
44
43
|
"c8": "10.1.3",
|
|
45
|
-
"chai": "6.
|
|
46
|
-
"eslint": "9.
|
|
44
|
+
"chai": "6.2.2",
|
|
45
|
+
"eslint": "9.39.2",
|
|
47
46
|
"eslint-plugin-import": "2.32.0",
|
|
48
|
-
"express": "5.1
|
|
47
|
+
"express": "5.2.1",
|
|
48
|
+
"globals": "17.3.0",
|
|
49
49
|
"husky": "9.1.7",
|
|
50
|
-
"jsdoc-to-markdown": "9.1.
|
|
51
|
-
"mocha": "11.7.
|
|
50
|
+
"jsdoc-to-markdown": "9.1.3",
|
|
51
|
+
"mocha": "11.7.5",
|
|
52
52
|
"mochawesome": "7.1.4",
|
|
53
|
-
"sinon": "21.0.
|
|
53
|
+
"sinon": "21.0.1"
|
|
54
54
|
}
|
|
55
55
|
}
|
package/test/retryMock.js
CHANGED
|
@@ -30,11 +30,11 @@ let message;
|
|
|
30
30
|
|
|
31
31
|
app.use(bodyParser.json());
|
|
32
32
|
app.get(`${config.base}${config.path}`, (req, res) => {
|
|
33
|
-
if (nbRequest === 0) message = '
|
|
33
|
+
if (nbRequest === 0) message = 'Received first request';
|
|
34
34
|
else {
|
|
35
|
-
const
|
|
35
|
+
const timeLapse = Date.now() - time;
|
|
36
36
|
|
|
37
|
-
message = `Received ${nbRequest} retry with
|
|
37
|
+
message = `Received ${nbRequest} retry with timelapse ${timeLapse}`;
|
|
38
38
|
}
|
|
39
39
|
console.log('----->', message);
|
|
40
40
|
time = Date.now();
|
package/test/rpRetry.spec.js
CHANGED
|
@@ -139,7 +139,7 @@ describe('request-retry Unit Tests', () => {
|
|
|
139
139
|
expect(callArgs[CALL_ARG_MESSAGE]).to.equal('out of scope timeout, reset to min');
|
|
140
140
|
});
|
|
141
141
|
});
|
|
142
|
-
it('should generate warning: out of scope timeout: 150
|
|
142
|
+
it('should generate warning: out of scope timeout: 150 becoming max', () => {
|
|
143
143
|
options.retry.timeout = OUT_OF_SCOPE_RETRY_TIMEOUT;
|
|
144
144
|
return rpRetry(options).then(() => {
|
|
145
145
|
assert.calledOnce(loggerSpyWarn);
|
|
@@ -163,7 +163,7 @@ describe('request-retry Unit Tests', () => {
|
|
|
163
163
|
assert.notCalled(loggerSpyWarn);
|
|
164
164
|
});
|
|
165
165
|
});
|
|
166
|
-
it('should generate warning: invalid retryStrategy: "
|
|
166
|
+
it('should generate warning: invalid retryStrategy: "notAFunction" becoming default function', () => {
|
|
167
167
|
options.retry.retryStrategy = 'notAFunction';
|
|
168
168
|
return rpRetry(options).then(() => {
|
|
169
169
|
assert.calledOnce(loggerSpyWarn);
|
|
@@ -172,7 +172,7 @@ describe('request-retry Unit Tests', () => {
|
|
|
172
172
|
expect(callArgs[CALL_ARG_MESSAGE]).to.equal('invalid retryStrategy, ignoring');
|
|
173
173
|
});
|
|
174
174
|
});
|
|
175
|
-
it('should generate warning: invalid delayStrategy: "
|
|
175
|
+
it('should generate warning: invalid delayStrategy: "notAFunction" becoming delay or default', () => {
|
|
176
176
|
options.retry.delayStrategy = 'notAFunction';
|
|
177
177
|
return rpRetry(options).then(() => {
|
|
178
178
|
assert.calledOnce(loggerSpyWarn);
|
|
@@ -240,7 +240,7 @@ describe('request-retry Unit Tests', () => {
|
|
|
240
240
|
expect(callArgs[CALL_ARG_MESSAGE]).to.equal('invalid logLevel.responseName, reset to default');
|
|
241
241
|
});
|
|
242
242
|
});
|
|
243
|
-
it('should generate warning: invalid logLevel.responseName ("
|
|
243
|
+
it('should generate warning: invalid logLevel.responseName (" "), reset to default', () => {
|
|
244
244
|
options.retry.logLevel = {
|
|
245
245
|
responseName: ' ',
|
|
246
246
|
};
|
|
@@ -252,6 +252,63 @@ describe('request-retry Unit Tests', () => {
|
|
|
252
252
|
});
|
|
253
253
|
});
|
|
254
254
|
});
|
|
255
|
+
describe('rpRetry(options) request mapping and response details', () => {
|
|
256
|
+
it('should succeed with body mapped to axios data', () => rpRetry({
|
|
257
|
+
method: 'POST',
|
|
258
|
+
headers: { 'x-correlation-id': correlationId },
|
|
259
|
+
url: 'http://localhost:9070/test/retry',
|
|
260
|
+
body: { test: 'data' },
|
|
261
|
+
retry: {},
|
|
262
|
+
}).then((response) => {
|
|
263
|
+
expect(response).to.have.property('statusCode');
|
|
264
|
+
}));
|
|
265
|
+
it('should succeed with json object mapped to axios data', () => rpRetry({
|
|
266
|
+
method: 'POST',
|
|
267
|
+
headers: { 'x-correlation-id': correlationId },
|
|
268
|
+
url: 'http://localhost:9070/test/retry',
|
|
269
|
+
json: { test: 'data' },
|
|
270
|
+
retry: {},
|
|
271
|
+
}).then((response) => {
|
|
272
|
+
expect(response).to.have.property('statusCode');
|
|
273
|
+
}));
|
|
274
|
+
it('should succeed with qs mapped to axios params', () => rpRetry({
|
|
275
|
+
method: 'POST',
|
|
276
|
+
headers: { 'x-correlation-id': correlationId },
|
|
277
|
+
url: 'http://localhost:9070/test/retry',
|
|
278
|
+
json: true,
|
|
279
|
+
qs: { key: 'value' },
|
|
280
|
+
retry: {},
|
|
281
|
+
}).then((response) => {
|
|
282
|
+
expect(response).to.have.property('statusCode');
|
|
283
|
+
}));
|
|
284
|
+
it('should throw a System error on network failure', () => rpRetry({
|
|
285
|
+
method: 'GET',
|
|
286
|
+
headers: { 'x-correlation-id': correlationId },
|
|
287
|
+
url: 'http://localhost:1/unreachable',
|
|
288
|
+
retry: { retries: 0, timeout: 10 },
|
|
289
|
+
}).catch((err) => {
|
|
290
|
+
expect(err.name).to.be.a('string');
|
|
291
|
+
}));
|
|
292
|
+
it('should log response with count details', () => {
|
|
293
|
+
const loggerSpySilly = spy(logger, 'silly');
|
|
294
|
+
|
|
295
|
+
return rpRetry({
|
|
296
|
+
method: 'POST',
|
|
297
|
+
headers: { 'x-correlation-id': correlationId },
|
|
298
|
+
url: 'http://localhost:9070/test/retry',
|
|
299
|
+
json: true,
|
|
300
|
+
retry: {
|
|
301
|
+
logLevel: {
|
|
302
|
+
response: 'silly',
|
|
303
|
+
responseDetails: 'count',
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
}).then(() => {
|
|
307
|
+
assert.calledOnce(loggerSpySilly);
|
|
308
|
+
loggerSpySilly.restore();
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
});
|
|
255
312
|
describe('rpRetry(options) options validation run', function Test() {
|
|
256
313
|
this.timeout(TIMEOUT);
|
|
257
314
|
const options = {
|
|
@@ -294,7 +351,7 @@ describe('request-retry Unit Tests', () => {
|
|
|
294
351
|
expect(callArgs[CALL_ARG_MESSAGE]).to.equal('bad retry strategy');
|
|
295
352
|
});
|
|
296
353
|
});
|
|
297
|
-
it('should not generate warning
|
|
354
|
+
it('should not generate warning for retry strategy, but warn on request error', () => {
|
|
298
355
|
options.retry.retryStrategy = () => false;
|
|
299
356
|
options.retry.retries = RETRY_RETRIES;
|
|
300
357
|
return rpRetry(options)
|
|
@@ -337,7 +394,7 @@ describe('request-retry Unit Tests', () => {
|
|
|
337
394
|
expect(callArgs[CALL_ARG_MESSAGE]).to.equal('calculated delay out of scope: using delay or default');
|
|
338
395
|
});
|
|
339
396
|
});
|
|
340
|
-
it('should not generate warning
|
|
397
|
+
it('should not generate warning for delay strategy, but warn on request error', () => {
|
|
341
398
|
options.retry.delayStrategy = () => DELAY_STRATEGY_RESPONSE_2;
|
|
342
399
|
options.retry.retries = RETRY_RETRIES;
|
|
343
400
|
return rpRetry(options)
|
package/.nycrc
DELETED