diff options
-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(); }); }); |