diff --git a/src/classes/worker.ts b/src/classes/worker.ts index 5ddcda94f4..c711ab68d0 100644 --- a/src/classes/worker.ts +++ b/src/classes/worker.ts @@ -350,8 +350,12 @@ export class Worker< } set concurrency(concurrency: number) { - if (typeof concurrency !== 'number' || concurrency < 1) { - throw new Error('concurrency must be a number greater than 0'); + if ( + typeof concurrency !== 'number' || + concurrency < 1 || + !isFinite(concurrency) + ) { + throw new Error('concurrency must be a finite number greater than 0'); } this.opts.concurrency = concurrency; } @@ -595,6 +599,8 @@ export class Worker< } } + // Update limitUntil and delayUntil + // TODO: Refactor out of this function this.limitUntil = Math.max(limitUntil, 0) || 0; if (delayUntil) { this.blockUntil = Math.max(delayUntil, 0) || 0; diff --git a/tests/test_worker.ts b/tests/test_worker.ts index 26a68c9173..315b22dfa8 100644 --- a/tests/test_worker.ts +++ b/tests/test_worker.ts @@ -1631,7 +1631,21 @@ describe('workers', function () { throw new Error('Should have thrown an exception'); } catch (err) { expect(err.message).to.be.equal( - 'concurrency must be a number greater than 0', + 'concurrency must be a finite number greater than 0', + ); + } + }); + + it('should thrown an exception if I specify a NaN concurrency', () => { + try { + const worker = new Worker(queueName, async () => {}, { + connection, + concurrency: NaN, + }); + throw new Error('Should have thrown an exception'); + } catch (err) { + expect(err.message).to.be.equal( + 'concurrency must be a finite number greater than 0', ); } });