From cc86c82bda0ce48d1bfb5481ed1f2ccffa20eb30 Mon Sep 17 00:00:00 2001 From: lshabalkin Date: Wed, 10 Jun 2020 18:33:57 +0300 Subject: [PATCH] fix(release): Change default retry strategy --- src/retry-strategies/infinite.spec.ts | 14 ++++++++++++++ src/service.ts | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 src/retry-strategies/infinite.spec.ts diff --git a/src/retry-strategies/infinite.spec.ts b/src/retry-strategies/infinite.spec.ts new file mode 100644 index 0000000..1ce72f4 --- /dev/null +++ b/src/retry-strategies/infinite.spec.ts @@ -0,0 +1,14 @@ +import infiniteRetryStrategy from './infinite'; + +describe('#infiniteRetryStrategy', () => { + it('is a function', () => { + expect(typeof infiniteRetryStrategy).toBe('function'); + }); + + it('returns a number', () => { + const delay = infiniteRetryStrategy(1); + + expect(typeof delay).toBe('number'); + expect(delay).toBe(1000); + }); +}); diff --git a/src/service.ts b/src/service.ts index 9c7a7de..ad6a93e 100644 --- a/src/service.ts +++ b/src/service.ts @@ -5,7 +5,6 @@ import EventEmitter from 'events'; import timeout from './timeout'; import randomPickConnectionString from './random-pick'; -import infiniteRetryStrategy from './retry-strategies/infinite'; import { EmptyMessageError, AmqpConnectGracefullyStopped, @@ -18,6 +17,7 @@ import { RawMessage, Message, MessageOptions, MessageHandlerOptions, MessageHand import { ConnectionStatus } from './connection'; import { AMQPAdapter, AMQPOptions, AMQPConnection } from './adapters/amqp-node'; import { Logger } from './logger'; +import defaultRetryStrategy from './retry-strategies/default'; const DEFAULT_HEART_BEAT = 30; @@ -173,7 +173,7 @@ export class ServiceConnection extends EventEmitter { * default one. Default retry strategy implements exponential backoff algorithm. */ async getConnection(attempt: number = 1): Promise { - const { retryStrategy = infiniteRetryStrategy, maxReconnects = Infinity } = this.options; + const { retryStrategy = defaultRetryStrategy, maxReconnects = Infinity } = this.options; let connection; if (this.status === ConnectionStatus.DISCONNECTING) {