Skip to content

Commit

Permalink
Merge pull request #8 from maxfierke/mf-fix_off_by_one
Browse files Browse the repository at this point in the history
Fixed off-by-one error in DelayPolicy
  • Loading branch information
maxfierke authored Mar 2, 2019
2 parents b9377c9 + 9b1fba6 commit 95ca712
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion addon/policies/delay.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export default class DelayPolicy extends Policy {
*/
*retry(retryInstance) {
const retryCount = get(retryInstance, 'retryCount');
const currentDelayMs = this.delay[retryCount];
const currentDelayMs = this.delay[retryCount - 1];

assert("DelayPolicy.delay was unexpectedly exhausted.", Number.isFinite(currentDelayMs));

yield timeout(currentDelayMs);
return yield* super.retry(retryInstance);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/policies/delay-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ module('Unit: DelayPolicy', function() {

assert.equal(taskAttemptCounter, 0);

run(() => {
later(() => {
obj = Obj.create();
obj.get('doStuff').perform().catch((e) => {
assert.equal(e.message, "I will never complete", "expected to have thrown original error");
assert.equal(taskAttemptCounter, 4, "expected to have been run four times");
done();
});
assert.equal(taskAttemptCounter, 1);
});
}, 620);
});
});
4 changes: 2 additions & 2 deletions tests/unit/policies/exponential-backoff-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ module('Unit: ExponentialBackoffPolicy', function() {

assert.equal(taskAttemptCounter, 0);

run(() => {
later(() => {
obj = Obj.create();
obj.get('doStuff').perform().catch((e) => {
assert.equal(e.message, "I will never complete", "expected to have thrown original error");
assert.equal(taskAttemptCounter, 7, "expected to have been run seven times");
done();
});
assert.equal(taskAttemptCounter, 1);
});
}, 10 + 20 + 40 + 80 + 160 + 320);
});
});

0 comments on commit 95ca712

Please sign in to comment.