diff --git a/addon/policies/delay.js b/addon/policies/delay.js index 39cc2f8a..d25aca43 100644 --- a/addon/policies/delay.js +++ b/addon/policies/delay.js @@ -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); diff --git a/tests/unit/policies/delay-test.js b/tests/unit/policies/delay-test.js index 6fd1e59f..6bf888d4 100644 --- a/tests/unit/policies/delay-test.js +++ b/tests/unit/policies/delay-test.js @@ -94,7 +94,7 @@ 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"); @@ -102,6 +102,6 @@ module('Unit: DelayPolicy', function() { done(); }); assert.equal(taskAttemptCounter, 1); - }); + }, 620); }); }); diff --git a/tests/unit/policies/exponential-backoff-test.js b/tests/unit/policies/exponential-backoff-test.js index 2358cfa6..05497fd5 100644 --- a/tests/unit/policies/exponential-backoff-test.js +++ b/tests/unit/policies/exponential-backoff-test.js @@ -131,7 +131,7 @@ 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"); @@ -139,6 +139,6 @@ module('Unit: ExponentialBackoffPolicy', function() { done(); }); assert.equal(taskAttemptCounter, 1); - }); + }, 10 + 20 + 40 + 80 + 160 + 320); }); });