Skip to content

Commit

Permalink
fix(azure-iot-common): Fix for Azure#338: Exp backoff retry formula
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Cauchois committed Jul 27, 2018
1 parent 08f541f commit 4a036b7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common/core/src/retry_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions common/core/test/_retry_policy_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit 4a036b7

Please sign in to comment.