From 59a8662da2d8a3f26e19b484627a87d45382006f Mon Sep 17 00:00:00 2001 From: Alex Early Date: Wed, 13 Feb 2019 17:22:30 -0800 Subject: fix: send proper retry count to retry's interaval func (#1621) Closes #1578 --- lib/retry.js | 2 +- 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(); }); }); -- cgit v1.2.1