Skip to content

Commit

Permalink
fix: send proper retry count to retry's interaval func (#1621)
Browse files Browse the repository at this point in the history
Closes #1578
  • Loading branch information
aearly committed Feb 14, 2019
1 parent aa8a3ee commit 59a8662
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 6 additions & 1 deletion test/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
});
});
Expand Down

0 comments on commit 59a8662

Please sign in to comment.