diff options
author | Alexander Early <alex@npmjs.com> | 2019-02-13 17:14:55 -0800 |
---|---|---|
committer | Alexander Early <alex@npmjs.com> | 2019-02-13 17:14:58 -0800 |
commit | 34694aab75b2d7e0dc989de8ef63e71b4ecb7760 (patch) | |
tree | 00d33af5885beaeaab77ca1528a476b33ac7e50c | |
parent | ec2867d3b6df6ea2e8292fa75679b15731e7d2df (diff) | |
download | async-fix-retry-interval-func.tar.gz |
fix: send proper retry count to retry's interaval funcfix-retry-interval-func
Closes #1578
-rw-r--r-- | lib/retry.js | 2 | ||||
-rw-r--r-- | test/retry.js | 7 |
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(); }); }); |