Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 536fb06

Browse files
authored
Merge pull request #2 from szenti/master
feat(exponential-delay): fix exponential strategy, add tests for exponential base
2 parents 394e078 + 76f96b3 commit 536fb06

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/strategies/delay/exponential-delay.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class ExponentialDelay {
99
}
1010

1111
delay(attempts) {
12-
const delayInSeconds = this._delayInSeconds[attempts - 1];
13-
const delayInMilliSeconds = delayInSeconds * 1000 * this._multiplier;
12+
const delayInSeconds = this._delayInSeconds[attempts - 1] * this._multiplier;
13+
const delayInMilliSeconds = delayInSeconds * 1000;
1414
return Delay.wait(delayInMilliSeconds, delayInSeconds);
1515
}
1616

src/strategies/delay/exponential-delay.spec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,27 @@ describe('Exponential Strategy', () => {
3434
const subject = new ExponentialDelay(3, 10);
3535
this.disableDelay();
3636

37+
yield subject.delay(1);
3738
yield subject.delay(2);
3839

39-
expect(Delay.wait).to.have.been.calledWith(20000, 2);
40+
expect(Delay.wait.firstCall.args).to.eql([10000, 10]);
41+
expect(Delay.wait.secondCall.args).to.eql([20000, 20]);
42+
});
43+
44+
});
45+
46+
47+
describe('#delay with multiplier and exponential', () => {
48+
49+
it('should wait on retry', function*() {
50+
const subject = new ExponentialDelay(3, 2, 3);
51+
this.disableDelay();
52+
53+
yield subject.delay(1);
54+
yield subject.delay(2);
55+
56+
expect(Delay.wait.firstCall.args).to.eql([2000, 2]);
57+
expect(Delay.wait.secondCall.args).to.eql([6000, 6]);
4058
});
4159

4260
});

0 commit comments

Comments
 (0)