diff options
author | Rebecca Turner <me@re-becca.org> | 2018-04-13 00:10:59 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2018-04-13 00:11:01 +0300 |
commit | 0b802f2a0bfa15c6af8074ebf9347f07bccdbcc7 (patch) | |
tree | 10268a65b3f847d740d0f506a084554ce9eaa13d /node_modules/retry | |
parent | 77dac72dfdb6add66ec859a949b1d2d788a379b7 (diff) |
retry@0.12.0
Diffstat (limited to 'node_modules/retry')
-rw-r--r-- | node_modules/retry/.npmignore | 1 | ||||
-rw-r--r-- | node_modules/retry/.travis.yml | 15 | ||||
-rw-r--r-- | node_modules/retry/Makefile | 6 | ||||
-rw-r--r-- | node_modules/retry/Readme.md | 20 | ||||
-rw-r--r-- | node_modules/retry/lib/retry.js | 9 | ||||
-rw-r--r-- | node_modules/retry/lib/retry_operation.js | 17 | ||||
-rw-r--r-- | node_modules/retry/package.json | 46 | ||||
-rw-r--r-- | node_modules/retry/test/integration/test-retry-operation.js | 86 | ||||
-rw-r--r-- | node_modules/retry/test/integration/test-retry-wrap.js | 48 | ||||
-rw-r--r-- | node_modules/retry/test/runner.js | 5 |
10 files changed, 199 insertions, 54 deletions
diff --git a/node_modules/retry/.npmignore b/node_modules/retry/.npmignore index e7726a071..432f2855d 100644 --- a/node_modules/retry/.npmignore +++ b/node_modules/retry/.npmignore @@ -1,2 +1,3 @@ /node_modules/* npm-debug.log +coverage diff --git a/node_modules/retry/.travis.yml b/node_modules/retry/.travis.yml new file mode 100644 index 000000000..bcde2122b --- /dev/null +++ b/node_modules/retry/.travis.yml @@ -0,0 +1,15 @@ +language: node_js +node_js: + - "4" +before_install: + - pip install --user codecov +after_success: + - codecov --file coverage/lcov.info --disable search +# travis encrypt [subdomain]:[api token]@[room id] +# notifications: +# email: false +# campfire: +# rooms: +# secure: xyz +# on_failure: always +# on_success: always diff --git a/node_modules/retry/Makefile b/node_modules/retry/Makefile index eee21a99d..1968d8ff8 100644 --- a/node_modules/retry/Makefile +++ b/node_modules/retry/Makefile @@ -1,8 +1,5 @@ SHELL := /bin/bash -test: - @node test/runner.js - release-major: test npm version major -m "Release %s" git push @@ -18,5 +15,4 @@ release-patch: test git push npm publish -.PHONY: test - +.PHONY: test release-major release-minor release-patch diff --git a/node_modules/retry/Readme.md b/node_modules/retry/Readme.md index eee05f7bb..16e28ec26 100644 --- a/node_modules/retry/Readme.md +++ b/node_modules/retry/Readme.md @@ -1,3 +1,8 @@ +<!-- badges/ --> +[![Build Status](https://secure.travis-ci.org/tim-kos/node-retry.png?branch=master)](http://travis-ci.org/tim-kos/node-retry "Check this project's build status on TravisCI") +[![codecov](https://codecov.io/gh/tim-kos/node-retry/branch/master/graph/badge.svg)](https://codecov.io/gh/tim-kos/node-retry) +<!-- /badges --> + # retry Abstraction for exponential and custom retry strategies for failed operations. @@ -60,7 +65,8 @@ var operation = retry.operation({ Creates a new `RetryOperation` object. `options` is the same as `retry.timeouts()`'s `options`, with two additions: * `forever`: Whether to retry forever, defaults to `false`. -* `unref`: Wether to [unref](https://nodejs.org/api/timers.html#timers_unref) the setTimeout's, defaults to `false`. +* `unref`: Whether to [unref](https://nodejs.org/api/timers.html#timers_unref) the setTimeout's, defaults to `false`. +* `maxRetryTime`: The maximum time (in milliseconds) that the retried operation is allowed to run. Default is `Infinity`. ### retry.timeouts([options]) @@ -69,7 +75,7 @@ milliseconds. If `options` is an array, a copy of that array is returned. `options` is a JS object that can contain any of the following keys: -* `retries`: The maximum amount of times to retry the operation. Default is `10`. +* `retries`: The maximum amount of times to retry the operation. Default is `10`. Seting this to `1` means `do it once, then retry it once`. * `factor`: The exponential factor to use. Default is `2`. * `minTimeout`: The number of milliseconds before starting the first retry. Default is `1000`. * `maxTimeout`: The maximum number of milliseconds between two retries. Default is `Infinity`. @@ -143,8 +149,10 @@ If `forever` is true, the following changes happen: #### retryOperation.errors() -Returns an array of all errors that have been passed to -`retryOperation.retry()` so far. +Returns an array of all errors that have been passed to `retryOperation.retry()` so far. The +returning array has the errors ordered chronologically based on when they were passed to +`retryOperation.retry()`, which means the first passed error is at index zero and the last is +at the last index. #### retryOperation.mainError() @@ -185,6 +193,10 @@ the current attempt number. Allows you to stop the operation being retried. Useful for aborting the operation on a fatal error etc. +#### retryOperation.reset() + +Resets the internal state of the operation object, so that you can call `attempt()` again as if this was a new operation object. + #### retryOperation.attempts() Returns an int representing the number of attempts it took to call `fn` before it was successful. diff --git a/node_modules/retry/lib/retry.js b/node_modules/retry/lib/retry.js index 77428cfd0..dcb576807 100644 --- a/node_modules/retry/lib/retry.js +++ b/node_modules/retry/lib/retry.js @@ -4,7 +4,8 @@ exports.operation = function(options) { var timeouts = exports.timeouts(options); return new RetryOperation(timeouts, { forever: options && options.forever, - unref: options && options.unref + unref: options && options.unref, + maxRetryTime: options && options.maxRetryTime }); }; @@ -75,9 +76,9 @@ exports.wrap = function(obj, options, methods) { var method = methods[i]; var original = obj[method]; - obj[method] = function retryWrapper() { + obj[method] = function retryWrapper(original) { var op = exports.operation(options); - var args = Array.prototype.slice.call(arguments); + var args = Array.prototype.slice.call(arguments, 1); var callback = args.pop(); args.push(function(err) { @@ -93,7 +94,7 @@ exports.wrap = function(obj, options, methods) { op.attempt(function() { original.apply(obj, args); }); - }; + }.bind(obj, original); obj[method].options = options; } }; diff --git a/node_modules/retry/lib/retry_operation.js b/node_modules/retry/lib/retry_operation.js index 2b3db8e17..1e564696f 100644 --- a/node_modules/retry/lib/retry_operation.js +++ b/node_modules/retry/lib/retry_operation.js @@ -4,14 +4,17 @@ function RetryOperation(timeouts, options) { options = { forever: options }; } + this._originalTimeouts = JSON.parse(JSON.stringify(timeouts)); this._timeouts = timeouts; this._options = options || {}; + this._maxRetryTime = options && options.maxRetryTime || Infinity; this._fn = null; this._errors = []; this._attempts = 1; this._operationTimeout = null; this._operationTimeoutCb = null; this._timeout = null; + this._operationStart = null; if (this._options.forever) { this._cachedTimeouts = this._timeouts.slice(0); @@ -19,6 +22,11 @@ function RetryOperation(timeouts, options) { } module.exports = RetryOperation; +RetryOperation.prototype.reset = function() { + this._attempts = 1; + this._timeouts = this._originalTimeouts; +} + RetryOperation.prototype.stop = function() { if (this._timeout) { clearTimeout(this._timeout); @@ -36,6 +44,11 @@ RetryOperation.prototype.retry = function(err) { if (!err) { return false; } + var currentTime = new Date().getTime(); + if (err && currentTime - this._operationStart >= this._maxRetryTime) { + this._errors.unshift(new Error('RetryOperation timeout occurred')); + return false; + } this._errors.push(err); @@ -60,7 +73,7 @@ RetryOperation.prototype.retry = function(err) { self._operationTimeoutCb(self._attempts); }, self._operationTimeout); - if (this._options.unref) { + if (self._options.unref) { self._timeout.unref(); } } @@ -94,6 +107,8 @@ RetryOperation.prototype.attempt = function(fn, timeoutOps) { }, self._operationTimeout); } + this._operationStart = new Date().getTime(); + this._fn(this._attempts); }; diff --git a/node_modules/retry/package.json b/node_modules/retry/package.json index a92d62726..1dec990b5 100644 --- a/node_modules/retry/package.json +++ b/node_modules/retry/package.json @@ -1,35 +1,33 @@ { - "_from": "retry@~0.10.1", - "_id": "retry@0.10.1", - "_integrity": "sha1-52OI0heZLCUnUCQdPTlW/tmNj/Q=", + "_from": "retry@0.12.0", + "_id": "retry@0.12.0", + "_inBundle": false, + "_integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=", "_location": "/retry", "_phantomChildren": {}, "_requested": { - "type": "range", + "type": "version", "registry": true, - "raw": "retry@~0.10.1", + "raw": "retry@0.12.0", "name": "retry", "escapedName": "retry", - "rawSpec": "~0.10.1", + "rawSpec": "0.12.0", "saveSpec": null, - "fetchSpec": "~0.10.1" + "fetchSpec": "0.12.0" }, "_requiredBy": [ - "/", - "/npm-registry-client", - "/pacote/promise-retry" + "#USER", + "/" ], - "_resolved": "https://registry.npmjs.org/retry/-/retry-0.10.1.tgz", - "_shasum": "e76388d217992c252750241d3d3956fed98d8ff4", - "_shrinkwrap": null, - "_spec": "retry@~0.10.1", - "_where": "/Users/zkat/Documents/code/npm", + "_resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", + "_shasum": "1b42a6266a21f07421d1b0b54b7dc167b01c013b", + "_spec": "retry@0.12.0", + "_where": "/Users/rebecca/code/npm", "author": { "name": "Tim Koschützki", "email": "tim@debuggable.com", "url": "http://debuggable.com/" }, - "bin": null, "bugs": { "url": "https://github.com/tim-kos/node-retry/issues" }, @@ -39,23 +37,29 @@ "description": "Abstraction for exponential and custom retry strategies for failed operations.", "devDependencies": { "fake": "0.2.0", - "far": "0.0.1" + "istanbul": "^0.4.5", + "tape": "^4.8.0" }, "directories": { "lib": "./lib" }, "engines": { - "node": "*" + "node": ">= 4" }, "homepage": "https://github.com/tim-kos/node-retry", "license": "MIT", "main": "index", "name": "retry", - "optionalDependencies": {}, - "peerDependencies": {}, "repository": { "type": "git", "url": "git://github.com/tim-kos/node-retry.git" }, - "version": "0.10.1" + "scripts": { + "release": "npm version ${SEMANTIC:-patch} -m \"Release %s\" && git push && git push --tags && npm publish", + "release:major": "env SEMANTIC=major npm run release", + "release:minor": "env SEMANTIC=minor npm run release", + "release:patch": "env SEMANTIC=patch npm run release", + "test": "istanbul cover ./node_modules/tape/bin/tape ./test/integration/*.js" + }, + "version": "0.12.0" } diff --git a/node_modules/retry/test/integration/test-retry-operation.js b/node_modules/retry/test/integration/test-retry-operation.js index 916936424..e351bb683 100644 --- a/node_modules/retry/test/integration/test-retry-operation.js +++ b/node_modules/retry/test/integration/test-retry-operation.js @@ -3,6 +3,45 @@ var assert = common.assert; var fake = common.fake.create(); var retry = require(common.dir.lib + '/retry'); +(function testReset() { + var error = new Error('some error'); + var operation = retry.operation([1, 2, 3]); + var attempts = 0; + + var finalCallback = fake.callback('finalCallback'); + fake.expectAnytime(finalCallback); + + var expectedFinishes = 1; + var finishes = 0; + + var fn = function() { + operation.attempt(function(currentAttempt) { + attempts++; + assert.equal(currentAttempt, attempts); + if (operation.retry(error)) { + return; + } + + finishes++ + assert.equal(expectedFinishes, finishes); + assert.strictEqual(attempts, 4); + assert.strictEqual(operation.attempts(), attempts); + assert.strictEqual(operation.mainError(), error); + + if (finishes < 2) { + attempts = 0; + expectedFinishes++; + operation.reset(); + fn() + } else { + finalCallback(); + } + }); + }; + + fn(); +})(); + (function testErrors() { var operation = retry.operation(); @@ -53,7 +92,6 @@ var retry = require(common.dir.lib + '/retry'); })(); (function testRetry() { - var times = 3; var error = new Error('some error'); var operation = retry.operation([1, 2, 3]); var attempts = 0; @@ -132,7 +170,7 @@ var retry = require(common.dir.lib + '/retry'); var endTime = new Date().getTime(); var minTime = startTime + (delay * 3); var maxTime = minTime + 20 // add a little headroom for code execution time - assert(endTime > minTime) + assert(endTime >= minTime) assert(endTime < maxTime) assert.strictEqual(attempts, 4); assert.strictEqual(operation.attempts(), attempts); @@ -174,3 +212,47 @@ var retry = require(common.dir.lib + '/retry'); fn(); })(); + +(function testMaxRetryTime() { + var error = new Error('some error'); + var maxRetryTime = 30; + var operation = retry.operation({ + minTimeout: 1, + maxRetryTime: maxRetryTime + }); + var attempts = 0; + + var finalCallback = fake.callback('finalCallback'); + fake.expectAnytime(finalCallback); + + var longAsyncFunction = function (wait, callback){ + setTimeout(callback, wait); + }; + + var fn = function() { + var startTime = new Date().getTime(); + operation.attempt(function(currentAttempt) { + attempts++; + assert.equal(currentAttempt, attempts); + + if (attempts !== 2) { + if (operation.retry(error)) { + return; + } + } else { + var curTime = new Date().getTime(); + longAsyncFunction(maxRetryTime - (curTime - startTime - 1), function(){ + if (operation.retry(error)) { + assert.fail('timeout should be occurred'); + return; + } + + assert.strictEqual(operation.mainError(), error); + finalCallback(); + }); + } + }); + }; + + fn(); +})(); diff --git a/node_modules/retry/test/integration/test-retry-wrap.js b/node_modules/retry/test/integration/test-retry-wrap.js index 7ca8bc7eb..3d2b6bfa6 100644 --- a/node_modules/retry/test/integration/test-retry-wrap.js +++ b/node_modules/retry/test/integration/test-retry-wrap.js @@ -14,17 +14,17 @@ function getLib() { (function wrapAll() { var lib = getLib(); retry.wrap(lib); - assert.equal(lib.fn1.name, 'retryWrapper'); - assert.equal(lib.fn2.name, 'retryWrapper'); - assert.equal(lib.fn3.name, 'retryWrapper'); + assert.equal(lib.fn1.name, 'bound retryWrapper'); + assert.equal(lib.fn2.name, 'bound retryWrapper'); + assert.equal(lib.fn3.name, 'bound retryWrapper'); }()); (function wrapAllPassOptions() { var lib = getLib(); retry.wrap(lib, {retries: 2}); - assert.equal(lib.fn1.name, 'retryWrapper'); - assert.equal(lib.fn2.name, 'retryWrapper'); - assert.equal(lib.fn3.name, 'retryWrapper'); + assert.equal(lib.fn1.name, 'bound retryWrapper'); + assert.equal(lib.fn2.name, 'bound retryWrapper'); + assert.equal(lib.fn3.name, 'bound retryWrapper'); assert.equal(lib.fn1.options.retries, 2); assert.equal(lib.fn2.options.retries, 2); assert.equal(lib.fn3.options.retries, 2); @@ -33,17 +33,17 @@ function getLib() { (function wrapDefined() { var lib = getLib(); retry.wrap(lib, ['fn2', 'fn3']); - assert.notEqual(lib.fn1.name, 'retryWrapper'); - assert.equal(lib.fn2.name, 'retryWrapper'); - assert.equal(lib.fn3.name, 'retryWrapper'); + assert.notEqual(lib.fn1.name, 'bound retryWrapper'); + assert.equal(lib.fn2.name, 'bound retryWrapper'); + assert.equal(lib.fn3.name, 'bound retryWrapper'); }()); (function wrapDefinedAndPassOptions() { var lib = getLib(); retry.wrap(lib, {retries: 2}, ['fn2', 'fn3']); - assert.notEqual(lib.fn1.name, 'retryWrapper'); - assert.equal(lib.fn2.name, 'retryWrapper'); - assert.equal(lib.fn3.name, 'retryWrapper'); + assert.notEqual(lib.fn1.name, 'bound retryWrapper'); + assert.equal(lib.fn2.name, 'bound retryWrapper'); + assert.equal(lib.fn3.name, 'bound retryWrapper'); assert.equal(lib.fn2.options.retries, 2); assert.equal(lib.fn3.options.retries, 2); }()); @@ -63,6 +63,30 @@ function getLib() { assert.ok(callbackCalled); }()); +(function runWrappedSeveralWithoutError() { + var callbacksCalled = 0; + var lib = { + fn1: function (a, callback) { + assert.equal(a, 1); + assert.equal(typeof callback, 'function'); + callback(); + }, + fn2: function (a, callback) { + assert.equal(a, 2); + assert.equal(typeof callback, 'function'); + callback(); + } + }; + retry.wrap(lib, {}, ['fn1', 'fn2']); + lib.fn1(1, function() { + callbacksCalled++; + }); + lib.fn2(2, function() { + callbacksCalled++; + }); + assert.equal(callbacksCalled, 2); +}()); + (function runWrappedWithError() { var callbackCalled; var lib = {method: function(callback) { diff --git a/node_modules/retry/test/runner.js b/node_modules/retry/test/runner.js deleted file mode 100644 index e0ee2f570..000000000 --- a/node_modules/retry/test/runner.js +++ /dev/null @@ -1,5 +0,0 @@ -var far = require('far').create(); - -far.add(__dirname); -far.include(/\/test-.*\.js$/); -far.execute(); |