.
This commit is contained in:
3
qwen/nodejs/node_modules/retry-as-promised/.travis.yml
generated
vendored
Normal file
3
qwen/nodejs/node_modules/retry-as-promised/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "8.0"
|
||||
23
qwen/nodejs/node_modules/retry-as-promised/LICENSE
generated
vendored
Normal file
23
qwen/nodejs/node_modules/retry-as-promised/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2015-2016 Mick Hansen. http://mhansen.io
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
41
qwen/nodejs/node_modules/retry-as-promised/README.md
generated
vendored
Normal file
41
qwen/nodejs/node_modules/retry-as-promised/README.md
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# retry-as-promised
|
||||
|
||||
Retry promises when they fail
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
$ npm install --save retry-as-promised
|
||||
$ yarn add retry-as-promised
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
```js
|
||||
var retry = require('retry-as-promised').default;
|
||||
|
||||
var warningFn = function(msg){ someLoggingFunction(msg, 'notice'); };
|
||||
|
||||
// Will call the until max retries or the promise is resolved.
|
||||
return retry(function (options) {
|
||||
// options.current, times callback has been called including this call
|
||||
return promise;
|
||||
}, {
|
||||
max: 3, // maximum amount of tries
|
||||
timeout: 10000 // throw if no response or error within millisecond timeout, default: undefined,
|
||||
match: [ // Must match error signature (ala bluebird catch) to continue
|
||||
Sequelize.ConnectionError,
|
||||
'SQLITE_BUSY'
|
||||
],
|
||||
backoffBase: 1000 // Initial backoff duration in ms. Default: 100,
|
||||
backoffExponent: 1.5 // Exponent to increase backoff each try. Default: 1.1
|
||||
backoffJitter: 150 // Amount of randomized jitter in ms to add to retry interval to spread retries out over time. Default: 0.0.
|
||||
report: warningFn, // the function used for reporting; must have a (string, object) argument signature, where string is the message that will passed in by retry-as-promised, and the object will be this configuration object + the $current property
|
||||
name: 'SourceX' // if user supplies string, it will be used when composing error/reporting messages; else if retry gets a callback, uses callback name in erroring/reporting; else (default) uses literal string 'unknown'
|
||||
});
|
||||
```
|
||||
|
||||
## Tested with
|
||||
|
||||
- Bluebird
|
||||
- Q
|
||||
33
qwen/nodejs/node_modules/retry-as-promised/dist/index.d.ts
generated
vendored
Normal file
33
qwen/nodejs/node_modules/retry-as-promised/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
export declare class TimeoutError extends Error {
|
||||
previous: Error | undefined;
|
||||
constructor(message: string, previousError?: Error);
|
||||
}
|
||||
export type MatchOption = string | RegExp | Error | Function;
|
||||
export interface Options {
|
||||
max: number;
|
||||
timeout?: number | undefined;
|
||||
match?: MatchOption[] | MatchOption | undefined;
|
||||
backoffBase?: number | undefined;
|
||||
backoffExponent?: number | undefined;
|
||||
backoffJitter?: number | undefined;
|
||||
report?: ((message: string, obj: CoercedOptions, err?: any) => void) | undefined;
|
||||
name?: string | undefined;
|
||||
}
|
||||
type CoercedOptions = {
|
||||
$current: number;
|
||||
max: number;
|
||||
timeout?: number | undefined;
|
||||
match: MatchOption[];
|
||||
backoffBase: number;
|
||||
backoffExponent: number;
|
||||
backoffJitter?: number;
|
||||
report?: ((message: string, obj: CoercedOptions, err?: any) => void) | undefined;
|
||||
name?: string | undefined;
|
||||
};
|
||||
type MaybePromise<T> = PromiseLike<T> | T;
|
||||
type RetryCallback<T> = ({ current }: {
|
||||
current: CoercedOptions['$current'];
|
||||
}) => MaybePromise<T>;
|
||||
export declare function applyJitter(delayMs: number, maxJitterMs: number): number;
|
||||
export declare function retryAsPromised<T>(callback: RetryCallback<T>, optionsInput: Options | number | CoercedOptions): Promise<T>;
|
||||
export default retryAsPromised;
|
||||
119
qwen/nodejs/node_modules/retry-as-promised/dist/index.js
generated
vendored
Normal file
119
qwen/nodejs/node_modules/retry-as-promised/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.retryAsPromised = exports.applyJitter = exports.TimeoutError = void 0;
|
||||
class TimeoutError extends Error {
|
||||
constructor(message, previousError) {
|
||||
super(message);
|
||||
this.name = "TimeoutError";
|
||||
this.previous = previousError;
|
||||
}
|
||||
}
|
||||
exports.TimeoutError = TimeoutError;
|
||||
function matches(match, err) {
|
||||
if (typeof match === 'function') {
|
||||
try {
|
||||
if (err instanceof match)
|
||||
return true;
|
||||
}
|
||||
catch (_) {
|
||||
return !!match(err);
|
||||
}
|
||||
}
|
||||
if (match === err.toString())
|
||||
return true;
|
||||
if (match === err.message)
|
||||
return true;
|
||||
return match instanceof RegExp
|
||||
&& (match.test(err.message) || match.test(err.toString()));
|
||||
}
|
||||
function applyJitter(delayMs, maxJitterMs) {
|
||||
const newDelayMs = delayMs + (Math.random() * maxJitterMs * (Math.random() > 0.5 ? 1 : -1));
|
||||
return Math.max(0, newDelayMs);
|
||||
}
|
||||
exports.applyJitter = applyJitter;
|
||||
function retryAsPromised(callback, optionsInput) {
|
||||
if (!callback || !optionsInput) {
|
||||
throw new Error('retry-as-promised must be passed a callback and a options set');
|
||||
}
|
||||
optionsInput = (typeof optionsInput === "number" ? { max: optionsInput } : optionsInput);
|
||||
const options = {
|
||||
$current: "$current" in optionsInput ? optionsInput.$current : 1,
|
||||
max: optionsInput.max,
|
||||
timeout: optionsInput.timeout || undefined,
|
||||
match: optionsInput.match ? Array.isArray(optionsInput.match) ? optionsInput.match : [optionsInput.match] : [],
|
||||
backoffBase: optionsInput.backoffBase === undefined ? 100 : optionsInput.backoffBase,
|
||||
backoffExponent: optionsInput.backoffExponent || 1.1,
|
||||
backoffJitter: optionsInput.backoffJitter || 0.0,
|
||||
report: optionsInput.report,
|
||||
name: optionsInput.name || callback.name || 'unknown'
|
||||
};
|
||||
if (options.match && !Array.isArray(options.match))
|
||||
options.match = [options.match];
|
||||
if (options.report)
|
||||
options.report('Trying ' + options.name + ' #' + options.$current + ' at ' + new Date().toLocaleTimeString(), options);
|
||||
return new Promise(function (resolve, reject) {
|
||||
let timeout;
|
||||
let backoffTimeout;
|
||||
let lastError;
|
||||
if (options.timeout) {
|
||||
timeout = setTimeout(function () {
|
||||
if (backoffTimeout)
|
||||
clearTimeout(backoffTimeout);
|
||||
reject(new TimeoutError(options.name + ' timed out', lastError));
|
||||
}, options.timeout);
|
||||
}
|
||||
Promise.resolve(callback({ current: options.$current }))
|
||||
.then(resolve)
|
||||
.then(function () {
|
||||
if (timeout)
|
||||
clearTimeout(timeout);
|
||||
if (backoffTimeout)
|
||||
clearTimeout(backoffTimeout);
|
||||
})
|
||||
.catch(function (err) {
|
||||
if (timeout)
|
||||
clearTimeout(timeout);
|
||||
if (backoffTimeout)
|
||||
clearTimeout(backoffTimeout);
|
||||
lastError = err;
|
||||
if (options.report)
|
||||
options.report((err && err.toString()) || err, options, err);
|
||||
// Should not retry if max has been reached
|
||||
var shouldRetry = options.$current < options.max;
|
||||
if (!shouldRetry)
|
||||
return reject(err);
|
||||
shouldRetry = options.match.length === 0 || options.match.some(function (match) {
|
||||
return matches(match, err);
|
||||
});
|
||||
if (!shouldRetry)
|
||||
return reject(err);
|
||||
var retryDelay = options.backoffBase * Math.pow(options.backoffExponent, options.$current - 1);
|
||||
const backoffJitter = options.backoffJitter;
|
||||
if (backoffJitter !== undefined) {
|
||||
retryDelay = applyJitter(retryDelay, backoffJitter);
|
||||
}
|
||||
// Do some accounting
|
||||
options.$current++;
|
||||
if (options.report)
|
||||
options.report(`Retrying ${options.name} (${options.$current})`, options);
|
||||
if (retryDelay) {
|
||||
// Use backoff function to ease retry rate
|
||||
if (options.report)
|
||||
options.report(`Delaying retry of ${options.name} by ${retryDelay}`, options);
|
||||
backoffTimeout = setTimeout(function () {
|
||||
retryAsPromised(callback, options)
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
}, retryDelay);
|
||||
}
|
||||
else {
|
||||
retryAsPromised(callback, options)
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.retryAsPromised = retryAsPromised;
|
||||
;
|
||||
exports.default = retryAsPromised;
|
||||
147
qwen/nodejs/node_modules/retry-as-promised/index.ts
generated
vendored
Normal file
147
qwen/nodejs/node_modules/retry-as-promised/index.ts
generated
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
'use strict';
|
||||
|
||||
export class TimeoutError extends Error {
|
||||
previous: Error | undefined;
|
||||
|
||||
constructor(message: string, previousError?: Error) {
|
||||
super(message);
|
||||
this.name = "TimeoutError";
|
||||
this.previous = previousError;
|
||||
}
|
||||
}
|
||||
|
||||
export type MatchOption =
|
||||
| string
|
||||
| RegExp
|
||||
| Error
|
||||
| Function;
|
||||
|
||||
export interface Options {
|
||||
max: number;
|
||||
timeout?: number | undefined;
|
||||
match?: MatchOption[] | MatchOption | undefined;
|
||||
backoffBase?: number | undefined;
|
||||
backoffExponent?: number | undefined;
|
||||
backoffJitter?: number | undefined;
|
||||
report?: ((message: string, obj: CoercedOptions, err?: any) => void) | undefined;
|
||||
name?: string | undefined;
|
||||
}
|
||||
|
||||
type CoercedOptions = {
|
||||
$current: number;
|
||||
max: number;
|
||||
timeout?: number | undefined;
|
||||
match: MatchOption[];
|
||||
backoffBase: number;
|
||||
backoffExponent: number;
|
||||
backoffJitter?: number;
|
||||
report?: ((message: string, obj: CoercedOptions, err?: any) => void) | undefined;
|
||||
name?: string | undefined;
|
||||
}
|
||||
type MaybePromise<T> = PromiseLike<T> | T;
|
||||
type RetryCallback<T> = ({ current }: { current: CoercedOptions['$current'] }) => MaybePromise<T>;
|
||||
|
||||
function matches(match : MatchOption, err: Error) {
|
||||
if (typeof match === 'function') {
|
||||
try {
|
||||
if (err instanceof match) return true;
|
||||
} catch (_) {
|
||||
return !!match(err);
|
||||
}
|
||||
}
|
||||
if (match === err.toString()) return true;
|
||||
if (match === err.message) return true;
|
||||
return match instanceof RegExp
|
||||
&& (match.test(err.message) || match.test(err.toString()));
|
||||
}
|
||||
|
||||
export function applyJitter(delayMs: number, maxJitterMs: number): number {
|
||||
const newDelayMs = delayMs + (Math.random() * maxJitterMs * (Math.random() > 0.5 ? 1 : -1));
|
||||
return Math.max(0, newDelayMs);
|
||||
}
|
||||
|
||||
export function retryAsPromised<T>(callback : RetryCallback<T>, optionsInput : Options | number | CoercedOptions) : Promise<T> {
|
||||
if (!callback || !optionsInput) {
|
||||
throw new Error(
|
||||
'retry-as-promised must be passed a callback and a options set'
|
||||
);
|
||||
}
|
||||
|
||||
optionsInput = (typeof optionsInput === "number" ? {max: optionsInput} : optionsInput) as Options | CoercedOptions;
|
||||
|
||||
const options : CoercedOptions = {
|
||||
$current: "$current" in optionsInput ? optionsInput.$current : 1,
|
||||
max: optionsInput.max,
|
||||
timeout: optionsInput.timeout || undefined,
|
||||
match: optionsInput.match ? Array.isArray(optionsInput.match) ? optionsInput.match : [optionsInput.match] : [],
|
||||
backoffBase: optionsInput.backoffBase === undefined ? 100 : optionsInput.backoffBase,
|
||||
backoffExponent: optionsInput.backoffExponent || 1.1,
|
||||
backoffJitter: optionsInput.backoffJitter || 0.0,
|
||||
report: optionsInput.report,
|
||||
name: optionsInput.name || callback.name || 'unknown'
|
||||
};
|
||||
|
||||
if (options.match && !Array.isArray(options.match)) options.match = [options.match];
|
||||
if (options.report) options.report('Trying ' + options.name + ' #' + options.$current + ' at ' + new Date().toLocaleTimeString(), options);
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
let timeout : NodeJS.Timeout | undefined;
|
||||
let backoffTimeout : NodeJS.Timeout | undefined;
|
||||
let lastError : Error | undefined;
|
||||
|
||||
if (options.timeout) {
|
||||
timeout = setTimeout(function() {
|
||||
if (backoffTimeout) clearTimeout(backoffTimeout);
|
||||
reject(new TimeoutError(options.name + ' timed out', lastError));
|
||||
}, options.timeout);
|
||||
}
|
||||
|
||||
Promise.resolve(callback({ current: options.$current }))
|
||||
.then(resolve)
|
||||
.then(function() {
|
||||
if (timeout) clearTimeout(timeout);
|
||||
if (backoffTimeout) clearTimeout(backoffTimeout);
|
||||
})
|
||||
.catch(function(err) {
|
||||
if (timeout) clearTimeout(timeout);
|
||||
if (backoffTimeout) clearTimeout(backoffTimeout);
|
||||
|
||||
lastError = err;
|
||||
if (options.report) options.report((err && err.toString()) || err, options, err);
|
||||
|
||||
// Should not retry if max has been reached
|
||||
var shouldRetry = options.$current! < options.max;
|
||||
if (!shouldRetry) return reject(err);
|
||||
shouldRetry = options.match.length === 0 || options.match.some(function (match) {
|
||||
return matches(match, err)
|
||||
});
|
||||
if (!shouldRetry) return reject(err);
|
||||
|
||||
var retryDelay = options.backoffBase * Math.pow(options.backoffExponent, options.$current - 1);
|
||||
const backoffJitter = options.backoffJitter;
|
||||
if (backoffJitter !== undefined) {
|
||||
retryDelay = applyJitter(retryDelay, backoffJitter);
|
||||
}
|
||||
|
||||
// Do some accounting
|
||||
options.$current++;
|
||||
if (options.report) options.report(`Retrying ${options.name} (${options.$current})`, options);
|
||||
|
||||
if (retryDelay) {
|
||||
// Use backoff function to ease retry rate
|
||||
if (options.report) options.report(`Delaying retry of ${options.name} by ${retryDelay}`, options);
|
||||
backoffTimeout = setTimeout(function() {
|
||||
retryAsPromised(callback, options)
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
}, retryDelay);
|
||||
} else {
|
||||
retryAsPromised(callback, options)
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default retryAsPromised;
|
||||
39
qwen/nodejs/node_modules/retry-as-promised/package.json
generated
vendored
Normal file
39
qwen/nodejs/node_modules/retry-as-promised/package.json
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "retry-as-promised",
|
||||
"version": "7.1.1",
|
||||
"description": "Retry a failed promise",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "cross-env DEBUG=retry-as-promised* ./node_modules/.bin/mocha --register ts-node/register --check-leaks --colors -t 10000 --reporter spec test/promise.test.js",
|
||||
"build": "tsc",
|
||||
"check": "tsc --noEmit",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mickhansen/retry-as-promised.git"
|
||||
},
|
||||
"keywords": [
|
||||
"retry",
|
||||
"promise",
|
||||
"bluebird"
|
||||
],
|
||||
"author": "Mick Hansen <maker@mhansen.io>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mickhansen/retry-as-promised/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mickhansen/retry-as-promised",
|
||||
"devDependencies": {
|
||||
"chai": "^4.2.0",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"cross-env": "^5.2.0",
|
||||
"mocha": "^9.1.3",
|
||||
"moment": "^2.10.6",
|
||||
"sinon": "^7.0.0",
|
||||
"sinon-chai": "^3.2.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.9.3"
|
||||
}
|
||||
}
|
||||
465
qwen/nodejs/node_modules/retry-as-promised/test/promise.test.js
generated
vendored
Normal file
465
qwen/nodejs/node_modules/retry-as-promised/test/promise.test.js
generated
vendored
Normal file
@@ -0,0 +1,465 @@
|
||||
var chai = require('chai'),
|
||||
expect = chai.expect,
|
||||
moment = require('moment'),
|
||||
sinon = require('sinon');
|
||||
|
||||
var delay = ms => new Promise(_ => setTimeout(_, ms));
|
||||
|
||||
chai.use(require('chai-as-promised'));
|
||||
sinon.usingPromise(Promise);
|
||||
|
||||
describe('Global Promise', function() {
|
||||
var retry = require('../').default;
|
||||
var applyJitter = require('../').applyJitter;
|
||||
|
||||
|
||||
beforeEach(function() {
|
||||
this.count = 0;
|
||||
this.soRejected = new Error(Math.random().toString());
|
||||
this.soResolved = new Error(Math.random().toString());
|
||||
});
|
||||
|
||||
it('should reject immediately if max is 1 (using options)', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.resolves(this.soResolved);
|
||||
callback.onCall(0).rejects(this.soRejected);
|
||||
|
||||
return expect(retry(callback, { max: 1, backoffBase: 0 }))
|
||||
.to.eventually.be.rejectedWith(this.soRejected)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject immediately if max is 1 (using integer)', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.resolves(this.soResolved);
|
||||
callback.onCall(0).rejects(this.soRejected);
|
||||
|
||||
return expect(retry(callback, 1))
|
||||
.to.eventually.be.rejectedWith(this.soRejected)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject after all tries if still rejected', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
|
||||
return expect(retry(callback, { max: 3, backoffBase: 0 }))
|
||||
.to.eventually.be.rejectedWith(this.soRejected)
|
||||
.then(function() {
|
||||
expect(callback.firstCall.args).to.deep.equal([{ current: 1 }]);
|
||||
expect(callback.secondCall.args).to.deep.equal([{ current: 2 }]);
|
||||
expect(callback.thirdCall.args).to.deep.equal([{ current: 3 }]);
|
||||
expect(callback.callCount).to.equal(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('should resolve immediately if resolved on first try', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.resolves(this.soResolved);
|
||||
callback.onCall(0).resolves(this.soResolved);
|
||||
|
||||
return expect(retry(callback, { max: 10, backoffBase: 0 }))
|
||||
.to.eventually.equal(this.soResolved)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should resolve if resolved before hitting max', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
callback.onCall(3).resolves(this.soResolved);
|
||||
|
||||
return expect(retry(callback, { max: 10, backoffBase: 0 }))
|
||||
.to.eventually.equal(this.soResolved)
|
||||
.then(function() {
|
||||
expect(callback.firstCall.args).to.deep.equal([{ current: 1 }]);
|
||||
expect(callback.secondCall.args).to.deep.equal([{ current: 2 }]);
|
||||
expect(callback.thirdCall.args).to.deep.equal([{ current: 3 }]);
|
||||
expect(callback.callCount).to.equal(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('options.timeout', function() {
|
||||
it('should throw if reject on first attempt', function() {
|
||||
return expect(
|
||||
retry(
|
||||
function() {
|
||||
return delay(2000);
|
||||
},
|
||||
{
|
||||
max: 1,
|
||||
backoffBase: 0,
|
||||
timeout: 1000
|
||||
}
|
||||
)
|
||||
).to.eventually.be.rejectedWith(retry.TimeoutError);
|
||||
});
|
||||
|
||||
it('should throw if reject on last attempt', function() {
|
||||
return expect(
|
||||
retry(
|
||||
function() {
|
||||
this.count++;
|
||||
if (this.count === 3) {
|
||||
return delay(3500);
|
||||
}
|
||||
return Promise.reject();
|
||||
}.bind(this),
|
||||
{
|
||||
max: 3,
|
||||
backoffBase: 0,
|
||||
timeout: 1500
|
||||
}
|
||||
)
|
||||
)
|
||||
.to.eventually.be.rejectedWith(retry.TimeoutError)
|
||||
.then(function() {
|
||||
expect(this.count).to.equal(3);
|
||||
}.bind(this));
|
||||
});
|
||||
});
|
||||
|
||||
describe('options.match', function() {
|
||||
it('should continue retry while error is equal to match string', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
callback.onCall(3).resolves(this.soResolved);
|
||||
|
||||
return expect(
|
||||
retry(callback, {
|
||||
max: 15,
|
||||
backoffBase: 0,
|
||||
match: 'Error: ' + this.soRejected.message
|
||||
})
|
||||
)
|
||||
.to.eventually.equal(this.soResolved)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject immediately if error is not equal to match string', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
|
||||
return expect(
|
||||
retry(callback, {
|
||||
max: 15,
|
||||
backoffBase: 0,
|
||||
match: 'A custom error string'
|
||||
})
|
||||
)
|
||||
.to.eventually.be.rejectedWith(this.soRejected)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should continue retry while error is instanceof match', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
callback.onCall(4).resolves(this.soResolved);
|
||||
|
||||
return expect(retry(callback, { max: 15, backoffBase: 0, match: Error }))
|
||||
.to.eventually.equal(this.soResolved)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(5);
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject immediately if error is not instanceof match', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
|
||||
return expect(
|
||||
retry(callback, { max: 15, backoffBase: 0, match: function foo() {} })
|
||||
)
|
||||
.to.eventually.be.rejectedWith(Error)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should continue retry while error is equal to match string in array', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
callback.onCall(4).resolves(this.soResolved);
|
||||
|
||||
return expect(
|
||||
retry(callback, {
|
||||
max: 15,
|
||||
backoffBase: 0,
|
||||
match: [
|
||||
'Error: ' + (this.soRejected.message + 1),
|
||||
'Error: ' + this.soRejected.message
|
||||
]
|
||||
})
|
||||
)
|
||||
.to.eventually.equal(this.soResolved)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(5);
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject immediately if error is not equal to match string in array', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
|
||||
return expect(
|
||||
retry(callback, {
|
||||
max: 15,
|
||||
backoffBase: 0,
|
||||
match: [
|
||||
'Error: ' + (this.soRejected + 1),
|
||||
'Error: ' + (this.soRejected + 2)
|
||||
]
|
||||
})
|
||||
)
|
||||
.to.eventually.be.rejectedWith(Error)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject immediately if error is not instanceof match in array', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
|
||||
return expect(
|
||||
retry(callback, {
|
||||
max: 15,
|
||||
backoffBase: 0,
|
||||
match: ['Error: ' + (this.soRejected + 1), function foo() {}]
|
||||
})
|
||||
)
|
||||
.to.eventually.be.rejectedWith(Error)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should continue retry while error is instanceof match in array', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
callback.onCall(4).resolves(this.soResolved);
|
||||
|
||||
return expect(
|
||||
retry(callback, {
|
||||
max: 15,
|
||||
backoffBase: 0,
|
||||
match: ['Error: ' + (this.soRejected + 1), Error]
|
||||
})
|
||||
)
|
||||
.to.eventually.equal(this.soResolved)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(5);
|
||||
});
|
||||
});
|
||||
|
||||
it('should continue retry while error is matched by function', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
callback.onCall(4).resolves(this.soResolved);
|
||||
|
||||
return expect(
|
||||
retry(callback, {
|
||||
max: 15,
|
||||
backoffBase: 0,
|
||||
match: (err) => err instanceof Error
|
||||
})
|
||||
)
|
||||
.to.eventually.equal(this.soResolved)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(5);
|
||||
});
|
||||
});
|
||||
|
||||
it('should continue retry while error is matched by a function in array', function() {
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
callback.onCall(4).resolves(this.soResolved);
|
||||
|
||||
return expect(
|
||||
retry(callback, {
|
||||
max: 15,
|
||||
backoffBase: 0,
|
||||
match: [
|
||||
(err) => err instanceof Error
|
||||
]
|
||||
})
|
||||
)
|
||||
.to.eventually.equal(this.soResolved)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(5);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('options.backoff', function() {
|
||||
it('should resolve after 5 retries and an eventual delay over 611ms using default backoff', async function() {
|
||||
// Given
|
||||
var callback = sinon.stub();
|
||||
callback.rejects(this.soRejected);
|
||||
callback.onCall(5).resolves(this.soResolved);
|
||||
|
||||
// When
|
||||
var startTime = moment();
|
||||
const result = await retry(callback, { max: 15 });
|
||||
var endTime = moment();
|
||||
|
||||
// Then
|
||||
expect(result).to.equal(this.soResolved);
|
||||
expect(callback.callCount).to.equal(6);
|
||||
expect(endTime.diff(startTime)).to.be.within(600, 650);
|
||||
});
|
||||
|
||||
it('should resolve after 1 retry and initial delay equal to the backoffBase', async function() {
|
||||
var initialDelay = 100;
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.onCall(0).rejects(this.soRejected);
|
||||
callback.onCall(1).resolves(this.soResolved);
|
||||
|
||||
var startTime = moment();
|
||||
const result = await retry(callback, {
|
||||
max: 2,
|
||||
backoffBase: initialDelay,
|
||||
backoffExponent: 3
|
||||
});
|
||||
var endTime = moment();
|
||||
|
||||
expect(result).to.equal(this.soResolved);
|
||||
expect(callback.callCount).to.equal(2);
|
||||
// allow for some overhead
|
||||
expect(endTime.diff(startTime)).to.be.within(initialDelay, initialDelay + 50);
|
||||
});
|
||||
|
||||
it('should throw TimeoutError and cancel backoff delay if timeout is reached', function() {
|
||||
return expect(
|
||||
retry(
|
||||
function() {
|
||||
return delay(2000);
|
||||
},
|
||||
{
|
||||
max: 15,
|
||||
timeout: 1000
|
||||
}
|
||||
)
|
||||
).to.eventually.be.rejectedWith(retry.TimeoutError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('options.report', function() {
|
||||
it('should receive the error that triggered a retry', function() {
|
||||
var report = sinon.stub();
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
callback.onCall(1).resolves(this.soResolved);
|
||||
|
||||
return expect(
|
||||
retry(callback, {max: 3, report})
|
||||
)
|
||||
.to.eventually.equal(this.soResolved)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(2);
|
||||
|
||||
// messages sent to report are:
|
||||
// Trying functionStub #1 at <timestamp>
|
||||
// Error: <random number> <--- This is the report call we want to test
|
||||
// Retrying functionStub (2)
|
||||
// Delaying retry of functionStub by 100
|
||||
// Trying functionStub #2 at <timestamp>
|
||||
expect(report.callCount).to.equal(5);
|
||||
expect(report.getCall(1).args[2]).to.be.instanceOf(Error);
|
||||
});
|
||||
});
|
||||
|
||||
it('should receive the error that exceeded max', function() {
|
||||
var report = sinon.stub();
|
||||
var callback = sinon.stub();
|
||||
|
||||
callback.rejects(this.soRejected);
|
||||
|
||||
return expect(
|
||||
retry(callback, {max: 3, report})
|
||||
)
|
||||
.to.eventually.be.rejectedWith(Error)
|
||||
.then(function() {
|
||||
expect(callback.callCount).to.equal(3);
|
||||
|
||||
// Trying functionStub #1 at <timestamp>
|
||||
// Error: <random number>
|
||||
// Retrying functionStub (2)
|
||||
// Delaying retry of functionStub by 100
|
||||
// Trying functionStub #2 at <timestamp>
|
||||
// Error: <random number>
|
||||
// Retrying functionStub (3)
|
||||
// Delaying retry of functionStub by 110.00000000000001
|
||||
// Trying functionStub #3 at <timestamp>
|
||||
// Error: <random number> <--- This is the report call we want to test
|
||||
expect(report.callCount).to.equal(10);
|
||||
expect(report.lastCall.args[2]).to.be.instanceOf(Error);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('options.backoffJitter', function() {
|
||||
|
||||
describe('fn:applyJitter', function() {
|
||||
it('applies randomized offsets to base delay', function() {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const withJitter = applyJitter(1000, 100);
|
||||
expect((withJitter >= 900 && withJitter <= 1100)).to.equal(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('never returns values less than zero', function() {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
expect(applyJitter(10, 1000) >= 0).to.equal(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should resolve after 1 retries and an eventual delay in range of 80-120 ms', async function() {
|
||||
var initialDelay = 100;
|
||||
var delayJitter = 20;
|
||||
|
||||
// Given
|
||||
var callback = sinon.stub();
|
||||
callback.rejects(this.soRejected);
|
||||
callback.onCall(1).resolves(this.soResolved);
|
||||
|
||||
// When
|
||||
var startTime = moment();
|
||||
const result = await retry(callback, { max: 5, backoffBase: initialDelay, backoffJitter: delayJitter });
|
||||
var endTime = moment();
|
||||
|
||||
// Then
|
||||
expect(result).to.equal(this.soResolved);
|
||||
expect(callback.callCount).to.equal(2);
|
||||
expect(endTime.diff(startTime)).to.be.within(75, 125);
|
||||
});
|
||||
});
|
||||
});
|
||||
104
qwen/nodejs/node_modules/retry-as-promised/tsconfig.json
generated
vendored
Normal file
104
qwen/nodejs/node_modules/retry-as-promised/tsconfig.json
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "commonjs", /* Specify what module code is generated. */
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
"outDir": "./dist/", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
"strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
"noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
"noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
"noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
},
|
||||
"files": ["index.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user