diff -Nru node-retry-0.10.1/debian/changelog node-retry-0.12.0/debian/changelog --- node-retry-0.10.1/debian/changelog 2017-12-29 14:16:06.000000000 +0000 +++ node-retry-0.12.0/debian/changelog 2020-03-09 21:01:30.000000000 +0000 @@ -1,3 +1,24 @@ +node-retry (0.12.0-1) unstable; urgency=medium + + * Team upload + + [ Paolo Greppi ] + * Update Vcs fields for migration to https://salsa.debian.org/ + * New upstream version + * Update copyright + * update salsa CI pipeline + + [ Xavier Guimard ] + * Bump debhelper compatibility level to 12 + * Declare compliance with policy 4.5.0 + * Add "Rules-Requires-Root: no" + * Add debian/gbp.conf + * Add upstream/metadata + * Use pkg-js-tools auto test & install + * Update copyright + + -- Xavier Guimard Mon, 09 Mar 2020 22:01:30 +0100 + node-retry (0.10.1-1) unstable; urgency=medium * Team upload diff -Nru node-retry-0.10.1/debian/compat node-retry-0.12.0/debian/compat --- node-retry-0.10.1/debian/compat 2017-12-29 14:16:06.000000000 +0000 +++ node-retry-0.12.0/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -9 diff -Nru node-retry-0.10.1/debian/control node-retry-0.12.0/debian/control --- node-retry-0.10.1/debian/control 2017-12-29 14:16:06.000000000 +0000 +++ node-retry-0.12.0/debian/control 2020-03-09 13:23:12.000000000 +0000 @@ -2,20 +2,20 @@ Section: javascript Priority: optional Maintainer: Debian Javascript Maintainers -Uploaders: Jérémy Lal , Paolo Greppi -Build-Depends: - debhelper (>= 9) - , nodejs - , dh-buildinfo -Standards-Version: 4.1.3 +Uploaders: Jérémy Lal , + Paolo Greppi +Build-Depends: debhelper-compat (= 12) + , pkg-js-tools (>= 0.9.20~) +Standards-Version: 4.5.0 +Vcs-Browser: https://salsa.debian.org/js-team/node-retry +Vcs-Git: https://salsa.debian.org/js-team/node-retry.git Homepage: https://github.com/tim-kos/node-retry -Vcs-Git: https://anonscm.debian.org/git/pkg-javascript/node-retry.git -Vcs-Browser: https://anonscm.debian.org/cgit/pkg-javascript/node-retry.git +Testsuite: autopkgtest-pkg-nodejs +Rules-Requires-Root: no Package: node-retry Architecture: all -Depends: - ${misc:Depends} +Depends: ${misc:Depends} , nodejs Description: Retry strategies for failed operations module for Node.js node-retry abstracts exponential and custom retry strategies for failed diff -Nru node-retry-0.10.1/debian/copyright node-retry-0.12.0/debian/copyright --- node-retry-0.10.1/debian/copyright 2017-12-29 14:16:06.000000000 +0000 +++ node-retry-0.12.0/debian/copyright 2020-03-09 13:28:48.000000000 +0000 @@ -1,11 +1,19 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: retry Files: * -Copyright: 2011 Tim Koschützki - 2011 Felix Geisendörfer +Copyright: + 2011, Tim Koschützki + 2011, Felix Geisendörfer License: Expat +Files: debian/* +Copyright: + 2013, Jérémy Lal + 2016-2018, Paolo Greppi + 2020, Xavier Guimard +License: GPL-3.0+ + License: Expat Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -25,12 +33,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Files: debian/* -Copyright: - 2013 Jérémy Lal - 2016 Paolo Greppi -License: GPL-3.0+ - License: GPL-3.0+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -43,7 +45,7 @@ GNU General Public License for more details. . You should have received a copy of the GNU General Public License - along with this program. If not, see . + along with this program. If not, see . . On Debian systems, the complete text of the GNU General Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". diff -Nru node-retry-0.10.1/debian/gbp.conf node-retry-0.12.0/debian/gbp.conf --- node-retry-0.10.1/debian/gbp.conf 1970-01-01 00:00:00.000000000 +0000 +++ node-retry-0.12.0/debian/gbp.conf 2020-03-09 13:23:07.000000000 +0000 @@ -0,0 +1,5 @@ +[DEFAULT] +pristine-tar = True + +[import-orig] +filter = [ '.gitignore', '.travis.yml', '.git*' ] diff -Nru node-retry-0.10.1/debian/gitlab-ci.yml node-retry-0.12.0/debian/gitlab-ci.yml --- node-retry-0.10.1/debian/gitlab-ci.yml 1970-01-01 00:00:00.000000000 +0000 +++ node-retry-0.12.0/debian/gitlab-ci.yml 2020-03-09 13:22:50.000000000 +0000 @@ -0,0 +1,4 @@ +--- +include: + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/pipeline-jobs.yml diff -Nru node-retry-0.10.1/debian/install node-retry-0.12.0/debian/install --- node-retry-0.10.1/debian/install 2017-12-29 14:16:06.000000000 +0000 +++ node-retry-0.12.0/debian/install 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -index.js usr/lib/nodejs/retry -lib usr/lib/nodejs/retry diff -Nru node-retry-0.10.1/debian/patches/00-fake.diff node-retry-0.12.0/debian/patches/00-fake.diff --- node-retry-0.10.1/debian/patches/00-fake.diff 2017-12-29 14:16:06.000000000 +0000 +++ node-retry-0.12.0/debian/patches/00-fake.diff 2020-03-09 13:22:50.000000000 +0000 @@ -17,140 +17,74 @@ =================================================================== --- node-retry.orig/test/integration/test-retry-operation.js +++ node-retry/test/integration/test-retry-operation.js -@@ -1,6 +1,5 @@ +@@ -1,16 +1,13 @@ var common = require('../common'); var assert = common.assert; -var fake = common.fake.create(); var retry = require(common.dir.lib + '/retry'); ++function finalCallback() {} - (function testErrors() { -@@ -51,126 +50,3 @@ var retry = require(common.dir.lib + '/r - assert.strictEqual(timeoutOpts.timeout, operation._operationTimeout); - assert.strictEqual(timeoutOpts.cb, operation._operationTimeoutCb); - })(); -- --(function testRetry() { -- var times = 3; -- 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 fn = function() { -- operation.attempt(function(currentAttempt) { -- attempts++; -- assert.equal(currentAttempt, attempts); -- if (operation.retry(error)) { -- return; -- } -- -- assert.strictEqual(attempts, 4); -- assert.strictEqual(operation.attempts(), attempts); -- assert.strictEqual(operation.mainError(), error); -- finalCallback(); -- }); -- }; -- -- fn(); --})(); -- --(function testRetryForever() { -- var error = new Error('some error'); -- var operation = retry.operation({ retries: 3, forever: true }); -- var attempts = 0; -- -- var finalCallback = fake.callback('finalCallback'); -- fake.expectAnytime(finalCallback); -- -- var fn = function() { -- operation.attempt(function(currentAttempt) { -- attempts++; -- assert.equal(currentAttempt, attempts); -- if (attempts !== 6 && operation.retry(error)) { -- return; -- } -- -- assert.strictEqual(attempts, 6); -- assert.strictEqual(operation.attempts(), attempts); -- assert.strictEqual(operation.mainError(), error); -- finalCallback(); -- }); -- }; -- -- fn(); --})(); -- --(function testRetryForeverNoRetries() { -- var error = new Error('some error'); -- var delay = 50 -- var operation = retry.operation({ -- retries: null, -- forever: true, -- minTimeout: delay, -- maxTimeout: delay -- }); -- -- var attempts = 0; -- var startTime = new Date().getTime(); -- -- var finalCallback = fake.callback('finalCallback'); -- fake.expectAnytime(finalCallback); -- -- var fn = function() { -- operation.attempt(function(currentAttempt) { -- attempts++; -- assert.equal(currentAttempt, attempts); -- if (attempts !== 4 && operation.retry(error)) { -- return; -- } -- -- 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 < maxTime) -- assert.strictEqual(attempts, 4); -- assert.strictEqual(operation.attempts(), attempts); -- assert.strictEqual(operation.mainError(), error); -- finalCallback(); -- }); -- }; -- -- fn(); --})(); -- --(function testStop() { -- 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 fn = function() { -- operation.attempt(function(currentAttempt) { -- attempts++; -- assert.equal(currentAttempt, attempts); -- -- if (attempts === 2) { -- operation.stop(); -- -- assert.strictEqual(attempts, 2); -- assert.strictEqual(operation.attempts(), attempts); -- assert.strictEqual(operation.mainError(), error); -- finalCallback(); -- } -- -- if (operation.retry(error)) { -- return; -- } -- }); -- }; + (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; + +@@ -96,9 +93,6 @@ var retry = require(common.dir.lib + '/r + var operation = retry.operation([1, 2, 3]); + var attempts = 0; + +- var finalCallback = fake.callback('finalCallback'); +- fake.expectAnytime(finalCallback); +- + var fn = function() { + operation.attempt(function(currentAttempt) { + attempts++; +@@ -122,9 +116,6 @@ var retry = require(common.dir.lib + '/r + var operation = retry.operation({ retries: 3, forever: true }); + var attempts = 0; + +- var finalCallback = fake.callback('finalCallback'); +- fake.expectAnytime(finalCallback); +- + var fn = function() { + operation.attempt(function(currentAttempt) { + attempts++; +@@ -156,9 +147,6 @@ var retry = require(common.dir.lib + '/r + var attempts = 0; + var startTime = new Date().getTime(); + +- var finalCallback = fake.callback('finalCallback'); +- fake.expectAnytime(finalCallback); +- + var fn = function() { + operation.attempt(function(currentAttempt) { + attempts++; +@@ -187,9 +175,6 @@ var retry = require(common.dir.lib + '/r + var operation = retry.operation([1, 2, 3]); + var attempts = 0; + +- var finalCallback = fake.callback('finalCallback'); +- fake.expectAnytime(finalCallback); +- + var fn = function() { + operation.attempt(function(currentAttempt) { + attempts++; +@@ -222,9 +207,6 @@ var retry = require(common.dir.lib + '/r + }); + var attempts = 0; + +- var finalCallback = fake.callback('finalCallback'); +- fake.expectAnytime(finalCallback); - -- fn(); --})(); + var longAsyncFunction = function (wait, callback){ + setTimeout(callback, wait); + }; Index: node-retry/test/integration/test-retry-wrap.js =================================================================== --- node-retry.orig/test/integration/test-retry-wrap.js diff -Nru node-retry-0.10.1/debian/patches/01-far.diff node-retry-0.12.0/debian/patches/01-far.diff --- node-retry-0.10.1/debian/patches/01-far.diff 2017-12-29 14:16:06.000000000 +0000 +++ node-retry-0.12.0/debian/patches/01-far.diff 1970-01-01 00:00:00.000000000 +0000 @@ -1,14 +0,0 @@ -Description: Avoid the far test runner (will run tests manually). -Forwarded: not-needed -Author: Paolo Greppi - -Index: node-retry/test/runner.js -=================================================================== ---- node-retry.orig/test/runner.js -+++ /dev/null -@@ -1,5 +0,0 @@ --var far = require('far').create(); -- --far.add(__dirname); --far.include(/\/test-.*\.js$/); --far.execute(); diff -Nru node-retry-0.10.1/debian/patches/series node-retry-0.12.0/debian/patches/series --- node-retry-0.10.1/debian/patches/series 2017-12-29 14:16:06.000000000 +0000 +++ node-retry-0.12.0/debian/patches/series 2020-03-09 13:22:50.000000000 +0000 @@ -1,2 +1 @@ 00-fake.diff -01-far.diff diff -Nru node-retry-0.10.1/debian/rules node-retry-0.12.0/debian/rules --- node-retry-0.10.1/debian/rules 2017-12-29 14:16:06.000000000 +0000 +++ node-retry-0.12.0/debian/rules 2020-03-09 13:25:13.000000000 +0000 @@ -5,12 +5,4 @@ #export DH_VERBOSE=1 %: - dh $@ - -override_dh_auto_build: -override_dh_auto_install: -override_dh_auto_clean: - # nothing - -override_dh_auto_test: - debian/tests/manual + dh $@ --with nodejs diff -Nru node-retry-0.10.1/debian/tests/control node-retry-0.12.0/debian/tests/control --- node-retry-0.10.1/debian/tests/control 2017-12-29 14:16:06.000000000 +0000 +++ node-retry-0.12.0/debian/tests/control 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ -Tests: require -Depends: node-string-width - -Test-Command: debian/tests/manual -Depends: @, @builddeps@ diff -Nru node-retry-0.10.1/debian/tests/manual node-retry-0.12.0/debian/tests/manual --- node-retry-0.10.1/debian/tests/manual 2017-12-29 14:16:06.000000000 +0000 +++ node-retry-0.12.0/debian/tests/manual 1970-01-01 00:00:00.000000000 +0000 @@ -1,6 +0,0 @@ -#!/bin/sh -set -e -nodejs test/integration/test-forever.js -nodejs test/integration/test-retry-operation.js -nodejs test/integration/test-retry-wrap.js -nodejs test/integration/test-timeouts.js diff -Nru node-retry-0.10.1/debian/tests/pkg-js/test node-retry-0.12.0/debian/tests/pkg-js/test --- node-retry-0.10.1/debian/tests/pkg-js/test 1970-01-01 00:00:00.000000000 +0000 +++ node-retry-0.12.0/debian/tests/pkg-js/test 2020-03-09 13:22:50.000000000 +0000 @@ -0,0 +1,6 @@ +#!/bin/sh +set -e +nodejs test/integration/test-forever.js +nodejs test/integration/test-retry-operation.js +nodejs test/integration/test-retry-wrap.js +nodejs test/integration/test-timeouts.js diff -Nru node-retry-0.10.1/debian/tests/require node-retry-0.12.0/debian/tests/require --- node-retry-0.10.1/debian/tests/require 2017-12-29 14:16:06.000000000 +0000 +++ node-retry-0.12.0/debian/tests/require 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -#!/bin/sh -set -e -nodejs -e "require('string-width');" diff -Nru node-retry-0.10.1/debian/upstream/metadata node-retry-0.12.0/debian/upstream/metadata --- node-retry-0.10.1/debian/upstream/metadata 1970-01-01 00:00:00.000000000 +0000 +++ node-retry-0.12.0/debian/upstream/metadata 2020-03-09 13:23:07.000000000 +0000 @@ -0,0 +1,7 @@ +--- +Archive: GitHub +Bug-Database: https://github.com/tim-kos/node-retry/issues +Bug-Submit: https://github.com/tim-kos/node-retry/issues/new +Changelog: https://github.com/tim-kos/node-retry/tags +Repository: https://github.com/tim-kos/node-retry.git +Repository-Browse: https://github.com/tim-kos/node-retry diff -Nru node-retry-0.10.1/.gitignore node-retry-0.12.0/.gitignore --- node-retry-0.10.1/.gitignore 2016-12-12 15:28:38.000000000 +0000 +++ node-retry-0.12.0/.gitignore 2018-04-09 09:33:34.000000000 +0000 @@ -1,2 +1,3 @@ /node_modules/* npm-debug.log +coverage diff -Nru node-retry-0.10.1/lib/retry.js node-retry-0.12.0/lib/retry.js --- node-retry-0.10.1/lib/retry.js 2016-12-12 15:28:38.000000000 +0000 +++ node-retry-0.12.0/lib/retry.js 2018-04-09 09:33:34.000000000 +0000 @@ -4,7 +4,8 @@ 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 @@ 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 @@ op.attempt(function() { original.apply(obj, args); }); - }; + }.bind(obj, original); obj[method].options = options; } }; diff -Nru node-retry-0.10.1/lib/retry_operation.js node-retry-0.12.0/lib/retry_operation.js --- node-retry-0.10.1/lib/retry_operation.js 2016-12-12 15:28:38.000000000 +0000 +++ node-retry-0.12.0/lib/retry_operation.js 2018-04-09 09:33:34.000000000 +0000 @@ -4,14 +4,17 @@ 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 @@ } 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 @@ 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 @@ self._operationTimeoutCb(self._attempts); }, self._operationTimeout); - if (this._options.unref) { + if (self._options.unref) { self._timeout.unref(); } } @@ -94,6 +107,8 @@ }, self._operationTimeout); } + this._operationStart = new Date().getTime(); + this._fn(this._attempts); }; diff -Nru node-retry-0.10.1/Makefile node-retry-0.12.0/Makefile --- node-retry-0.10.1/Makefile 2016-12-12 15:28:38.000000000 +0000 +++ node-retry-0.12.0/Makefile 2018-04-09 09:33:34.000000000 +0000 @@ -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 @@ git push npm publish -.PHONY: test - +.PHONY: test release-major release-minor release-patch diff -Nru node-retry-0.10.1/package.json node-retry-0.12.0/package.json --- node-retry-0.10.1/package.json 2016-12-12 15:28:38.000000000 +0000 +++ node-retry-0.12.0/package.json 2018-04-09 09:33:34.000000000 +0000 @@ -3,7 +3,7 @@ "name": "retry", "description": "Abstraction for exponential and custom retry strategies for failed operations.", "license": "MIT", - "version": "0.10.1", + "version": "0.12.0", "homepage": "https://github.com/tim-kos/node-retry", "repository": { "type": "git", @@ -14,11 +14,19 @@ }, "main": "index", "engines": { - "node": "*" + "node": ">= 4" }, "dependencies": {}, "devDependencies": { "fake": "0.2.0", - "far": "0.0.1" + "istanbul": "^0.4.5", + "tape": "^4.8.0" + }, + "scripts": { + "test": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/integration/*.js", + "release:major": "env SEMANTIC=major npm run release", + "release:minor": "env SEMANTIC=minor npm run release", + "release:patch": "env SEMANTIC=patch npm run release", + "release": "npm version ${SEMANTIC:-patch} -m \"Release %s\" && git push && git push --tags && npm publish" } } diff -Nru node-retry-0.10.1/README.md node-retry-0.12.0/README.md --- node-retry-0.10.1/README.md 2016-12-12 15:28:38.000000000 +0000 +++ node-retry-0.12.0/README.md 2018-04-09 09:33:34.000000000 +0000 @@ -1,3 +1,8 @@ + +[![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) + + # retry Abstraction for exponential and custom retry strategies for failed operations. @@ -60,7 +65,8 @@ 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 @@ `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 @@ #### 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 @@ 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 -Nru node-retry-0.10.1/test/integration/test-retry-operation.js node-retry-0.12.0/test/integration/test-retry-operation.js --- node-retry-0.10.1/test/integration/test-retry-operation.js 2016-12-12 15:28:38.000000000 +0000 +++ node-retry-0.12.0/test/integration/test-retry-operation.js 2018-04-09 09:33:34.000000000 +0000 @@ -3,6 +3,45 @@ 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 @@ })(); (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 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); @@ -171,6 +209,50 @@ } }); }; + + 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 -Nru node-retry-0.10.1/test/integration/test-retry-wrap.js node-retry-0.12.0/test/integration/test-retry-wrap.js --- node-retry-0.10.1/test/integration/test-retry-wrap.js 2016-12-12 15:28:38.000000000 +0000 +++ node-retry-0.12.0/test/integration/test-retry-wrap.js 2018-04-09 09:33:34.000000000 +0000 @@ -14,17 +14,17 @@ (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 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 @@ 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 -Nru node-retry-0.10.1/test/runner.js node-retry-0.12.0/test/runner.js --- node-retry-0.10.1/test/runner.js 2016-12-12 15:28:38.000000000 +0000 +++ node-retry-0.12.0/test/runner.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ -var far = require('far').create(); - -far.add(__dirname); -far.include(/\/test-.*\.js$/); -far.execute(); diff -Nru node-retry-0.10.1/.travis.yml node-retry-0.12.0/.travis.yml --- node-retry-0.10.1/.travis.yml 1970-01-01 00:00:00.000000000 +0000 +++ node-retry-0.12.0/.travis.yml 2018-04-09 09:33:34.000000000 +0000 @@ -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