diff --git a/common/core/src/retry_policy.ts b/common/core/src/retry_policy.ts index a2167402b..c660d30dc 100644 --- a/common/core/src/retry_policy.ts +++ b/common/core/src/retry_policy.ts @@ -134,7 +134,7 @@ export class ExponentialBackOffWithJitter implements RetryPolicy { let minRandomFactor = constants.c * (1 - constants.jd); let maxRandomFactor = constants.c * (1 - constants.ju); let randomJitter = Math.random() * (maxRandomFactor - minRandomFactor); - return Math.min(constants.cMin + (Math.pow(retryCount - 1, 2) - 1) * randomJitter, constants.cMax); + return Math.min(constants.cMin + (Math.pow(2, retryCount - 1) - 1) * randomJitter, constants.cMax); } } diff --git a/common/core/test/_retry_policy_test.js b/common/core/test/_retry_policy_test.js index a3c752440..16a892e72 100644 --- a/common/core/test/_retry_policy_test.js +++ b/common/core/test/_retry_policy_test.js @@ -38,10 +38,10 @@ describe('RetryPolicy', function () { Math.random.restore(); }); - it('returns \'C\' for the first retry if the first retry is not set to be immediate', function () { + it('returns a non-zero value for the first retry if the first retry is not set to be immediate', function () { sinon.stub(Math, 'random').returns(0.42); var policy = new ExponentialBackOffWithJitter(false); - assert.strictEqual(policy.nextRetryTimeout(0, false), 100); + assert.isAbove(policy.nextRetryTimeout(0, false), 0); Math.random.restore(); }); @@ -59,10 +59,10 @@ describe('RetryPolicy', function () { ```]*/ [ { retryCount: 0, expected: 0 }, - { retryCount: 1, expected: 89.5 }, - { retryCount: 2, expected: 100 }, + { retryCount: 1, expected: 100 }, + { retryCount: 2, expected: 110.5 }, { retryCount: 3, expected: 131.5 }, - { retryCount: 10, expected: 940 }, + { retryCount: 10, expected: 5465.5 }, { retryCount: 42, expected: 10000 } ].forEach(function (testConfig) { assert.strictEqual(policy.nextRetryTimeout(testConfig.retryCount, false), testConfig.expected); @@ -77,11 +77,11 @@ describe('RetryPolicy', function () { jd = 0.25 ```]*/ [ - { retryCount: 0, expected: 10000 }, - { retryCount: 1, expected: 9475 }, - { retryCount: 2, expected: 10000 }, + { retryCount: 0, expected: 9737.5 }, + { retryCount: 1, expected: 10000 }, + { retryCount: 2, expected: 10525 }, { retryCount: 3, expected: 11575 }, - { retryCount: 10, expected: 52000 }, + { retryCount: 10, expected: 60000 }, { retryCount: 42, expected: 60000 } ].forEach(function (testConfig) { assert.strictEqual(policy.nextRetryTimeout(testConfig.retryCount, true), testConfig.expected);