summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Early <alexander.early@gmail.com>2019-02-13 17:22:30 -0800
committerGitHub <noreply@github.com>2019-02-13 17:22:30 -0800
commit59a8662da2d8a3f26e19b484627a87d45382006f (patch)
tree39a60d7efafd36ad3b2f623324e6b0beea17e5b1
parentaa8a3ee08e0af40a0409fe287a9b3a7a51fa46d3 (diff)
downloadasync-59a8662da2d8a3f26e19b484627a87d45382006f.tar.gz
fix: send proper retry count to retry's interaval func (#1621)
Closes #1578
-rw-r--r--lib/retry.js2
-rw-r--r--test/retry.js7
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/retry.js b/lib/retry.js
index 5ef6971..55dce0a 100644
--- a/lib/retry.js
+++ b/lib/retry.js
@@ -122,7 +122,7 @@ export default function retry(opts, task, callback) {
if (err && attempt++ < options.times &&
(typeof options.errorFilter != 'function' ||
options.errorFilter(err))) {
- setTimeout(retryAttempt, options.intervalFunc(attempt));
+ setTimeout(retryAttempt, options.intervalFunc(attempt - 1));
} else {
callback(err, ...args);
}
diff --git a/test/retry.js b/test/retry.js
index e7bc36a..d6cc06d 100644
--- a/test/retry.js
+++ b/test/retry.js
@@ -79,7 +79,11 @@ describe("retry", () => {
it('retry with custom interval when all attempts fail',(done) => {
var times = 3;
- var intervalFunc = function(retryCount) { return retryCount * 100; };
+ var retryCounts = []
+ var intervalFunc = function(retryCount) {
+ retryCounts.push(retryCount)
+ return retryCount * 100;
+ };
var callCount = 0;
var error = 'ERROR';
var erroredResult = 'RESULT';
@@ -94,6 +98,7 @@ describe("retry", () => {
assert.equal(callCount, 3, "did not retry the correct number of times");
assert.equal(err, error + times, "Incorrect error was returned");
assert.equal(result, erroredResult + times, "Incorrect result was returned");
+ assert.deepEqual(retryCounts, [1, 2])
done();
});
});