Skip to content

Commit

Permalink
elasticio-4080 (#145)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Kotenko <anton@elastic.io>
  • Loading branch information
anton-kotenko and Anton Kotenko committed Jun 3, 2020
1 parent 7aafee8 commit 6ab87f1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/amqp.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class Amqp {
_getDelay(defaultDelay, maxDelay, iteration) {
log.debug({ defaultDelay }, 'Current delay');
log.debug({ maxDelay }, 'Current delay');
const delay = Math.min(defaultDelay * (iteration + 1), maxDelay);
const delay = Math.min(defaultDelay * Math.pow(2, iteration), maxDelay);
log.debug({ delay }, 'Calculated delay');
return delay;
}
Expand Down
22 changes: 22 additions & 0 deletions mocha_spec/unit/amqp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1114,4 +1114,26 @@ describe('AMQP', () => {
expect(amqp.amqp.close).to.have.been.calledOnce;
expect(amqp.amqp.removeAllListeners).to.have.been.calledOnce.and.calledWith('close');
});
describe('_getDelay', () => {
let amqp;
beforeEach(() => {
amqp = new Amqp(settings);
});
it('should return defaultDelay * 2^^iteration as delay', () => {
expect(amqp._getDelay(100, 300 * 1000, 0)).to.equal(100);
expect(amqp._getDelay(100, 300 * 1000, 1)).to.equal(200);
expect(amqp._getDelay(100, 300 * 1000, 2)).to.equal(400);
expect(amqp._getDelay(100, 300 * 1000, 4)).to.equal(1600);
});
it('should return default delay for first iteration', () => {
expect(amqp._getDelay(100, 300 * 1000, 0)).to.equal(100);
});
it('should reutrn maxDelay if calculated delay is greater then maxDelay', () => {
expect(amqp._getDelay(100, 300 * 1000, 12)).to.equal(300 * 1000);
expect(amqp._getDelay(100, 300 * 1000, 15)).to.equal(300 * 1000);
});
it('should reutrn maxDelay if calculated delay is infinity then maxDelay', () => {
expect(amqp._getDelay(100, 300 * 1000, 1e6)).to.equal(300 * 1000);
});
});
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "elasticio-sailor-nodejs",
"description": "The official elastic.io library for bootstrapping and executing for Node.js connectors",
"version": "2.6.9",
"version": "2.6.10",
"main": "run.js",
"scripts": {
"lint": "./node_modules/.bin/eslint lib spec mocha_spec lib run.js runService.js",
Expand Down

0 comments on commit 6ab87f1

Please sign in to comment.