@webex/test-helper-retry 2.37.0 → 2.37.1
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/dist/index.js +2 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +15 -8
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
6
|
-
|
|
7
5
|
/*!
|
|
8
6
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
9
7
|
*/
|
|
@@ -15,13 +13,12 @@ if (typeof _promise.default === 'undefined') {
|
|
|
15
13
|
// eslint-disable-next-line global-require
|
|
16
14
|
require('es6-promise').polyfill();
|
|
17
15
|
}
|
|
18
|
-
|
|
19
16
|
var backoffPattern = [0, 1000, 2000, 4000, 8000, 16000, 32000, 32000, 32000];
|
|
17
|
+
|
|
20
18
|
/**
|
|
21
19
|
* @param {Function} fn
|
|
22
20
|
* @returns {Object}
|
|
23
21
|
*/
|
|
24
|
-
|
|
25
22
|
function retry(fn) {
|
|
26
23
|
return backoffPattern.reduce(function (promise, delay) {
|
|
27
24
|
return promise.catch(function (err) {
|
|
@@ -29,7 +26,6 @@ function retry(fn) {
|
|
|
29
26
|
if (err) {
|
|
30
27
|
console.error("###Test error: ".concat(err, ". Retrying test in ").concat(delay, " seconds"));
|
|
31
28
|
}
|
|
32
|
-
|
|
33
29
|
setTimeout(function () {
|
|
34
30
|
resolve(fn());
|
|
35
31
|
}, delay);
|
|
@@ -37,19 +33,17 @@ function retry(fn) {
|
|
|
37
33
|
});
|
|
38
34
|
}, _promise.default.reject());
|
|
39
35
|
}
|
|
36
|
+
|
|
40
37
|
/**
|
|
41
38
|
* Determines the expected timeout for the test.
|
|
42
39
|
* @param {number} estimate estimated of how long a single attempt should take
|
|
43
40
|
* @returns {number}
|
|
44
41
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
42
|
function timeout(estimate) {
|
|
48
43
|
return backoffPattern.reduce(function (sum, next) {
|
|
49
44
|
return sum + next + estimate;
|
|
50
45
|
}, 0);
|
|
51
46
|
}
|
|
52
|
-
|
|
53
47
|
module.exports = retry;
|
|
54
48
|
retry.timeout = timeout;
|
|
55
49
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require","polyfill","backoffPattern","retry","fn","reduce","promise","delay","catch","err","resolve","console","error","setTimeout","reject","timeout","estimate","sum","next","module","exports"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-disable max-nested-callbacks */\n\n/* istanbul ignore next */\nif (typeof Promise === 'undefined') {\n // eslint-disable-next-line global-require\n require('es6-promise').polyfill();\n}\n\nconst backoffPattern = [0, 1000, 2000, 4000, 8000, 16000, 32000, 32000, 32000];\n\n/**\n * @param {Function} fn\n * @returns {Object}\n */\nfunction retry(fn) {\n return backoffPattern.reduce((promise, delay)
|
|
1
|
+
{"version":3,"names":["require","polyfill","backoffPattern","retry","fn","reduce","promise","delay","catch","err","resolve","console","error","setTimeout","reject","timeout","estimate","sum","next","module","exports"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-disable max-nested-callbacks */\n\n/* istanbul ignore next */\nif (typeof Promise === 'undefined') {\n // eslint-disable-next-line global-require\n require('es6-promise').polyfill();\n}\n\nconst backoffPattern = [0, 1000, 2000, 4000, 8000, 16000, 32000, 32000, 32000];\n\n/**\n * @param {Function} fn\n * @returns {Object}\n */\nfunction retry(fn) {\n return backoffPattern.reduce(\n (promise, delay) =>\n promise.catch(\n (err) =>\n new Promise((resolve) => {\n if (err) {\n console.error(`###Test error: ${err}. Retrying test in ${delay} seconds`);\n }\n\n setTimeout(() => {\n resolve(fn());\n }, delay);\n })\n ),\n Promise.reject()\n );\n}\n\n/**\n * Determines the expected timeout for the test.\n * @param {number} estimate estimated of how long a single attempt should take\n * @returns {number}\n */\nfunction timeout(estimate) {\n return backoffPattern.reduce((sum, next) => sum + next + estimate, 0);\n}\n\nmodule.exports = retry;\nretry.timeout = timeout;\n"],"mappings":";;;;AAAA;AACA;AACA;;AAEA;;AAEA;AACA,IAAI,uBAAc,KAAK,WAAW,EAAE;EAClC;EACAA,OAAO,CAAC,aAAa,CAAC,CAACC,QAAQ,EAAE;AACnC;AAEA,IAAMC,cAAc,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;;AAE9E;AACA;AACA;AACA;AACA,SAASC,KAAK,CAACC,EAAE,EAAE;EACjB,OAAOF,cAAc,CAACG,MAAM,CAC1B,UAACC,OAAO,EAAEC,KAAK;IAAA,OACbD,OAAO,CAACE,KAAK,CACX,UAACC,GAAG;MAAA,OACF,qBAAY,UAACC,OAAO,EAAK;QACvB,IAAID,GAAG,EAAE;UACPE,OAAO,CAACC,KAAK,0BAAmBH,GAAG,gCAAsBF,KAAK,cAAW;QAC3E;QAEAM,UAAU,CAAC,YAAM;UACfH,OAAO,CAACN,EAAE,EAAE,CAAC;QACf,CAAC,EAAEG,KAAK,CAAC;MACX,CAAC,CAAC;IAAA,EACL;EAAA,GACH,iBAAQO,MAAM,EAAE,CACjB;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASC,OAAO,CAACC,QAAQ,EAAE;EACzB,OAAOd,cAAc,CAACG,MAAM,CAAC,UAACY,GAAG,EAAEC,IAAI;IAAA,OAAKD,GAAG,GAAGC,IAAI,GAAGF,QAAQ;EAAA,GAAE,CAAC,CAAC;AACvE;AAEAG,MAAM,CAACC,OAAO,GAAGjB,KAAK;AACtBA,KAAK,CAACY,OAAO,GAAGA,OAAO"}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -17,15 +17,22 @@ const backoffPattern = [0, 1000, 2000, 4000, 8000, 16000, 32000, 32000, 32000];
|
|
|
17
17
|
* @returns {Object}
|
|
18
18
|
*/
|
|
19
19
|
function retry(fn) {
|
|
20
|
-
return backoffPattern.reduce(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
return backoffPattern.reduce(
|
|
21
|
+
(promise, delay) =>
|
|
22
|
+
promise.catch(
|
|
23
|
+
(err) =>
|
|
24
|
+
new Promise((resolve) => {
|
|
25
|
+
if (err) {
|
|
26
|
+
console.error(`###Test error: ${err}. Retrying test in ${delay} seconds`);
|
|
27
|
+
}
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
resolve(fn());
|
|
31
|
+
}, delay);
|
|
32
|
+
})
|
|
33
|
+
),
|
|
34
|
+
Promise.reject()
|
|
35
|
+
);
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
/**
|