Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connection option params #926

Merged
merged 3 commits into from Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/classes/redis-connection.ts
Expand Up @@ -12,13 +12,11 @@ import * as path from 'path';

const overrideMessage = [
'BullMQ: WARNING! Your redis options maxRetriesPerRequest must be null and enableReadyCheck false',
'and will be overrided by BullMQ.',
'and will be overridden by BullMQ.',
].join(' ');

const deprecationMessage = [
'BullMQ: DEPRECATION WARNING! Your redis options maxRetriesPerRequest must be null and enableReadyCheck false.',
'On the next versions having this settings will throw an exception',
].join(' ');
const connectionErrorMessage = `Using a redis instance with enableReadyCheck or maxRetriesPerRequest is not permitted.
See https://https://github.com/OptimalBits/bull/issues/1873`;

export class RedisConnection extends EventEmitter {
static minimumVersion = '5.0.0';
Expand Down Expand Up @@ -55,7 +53,12 @@ export class RedisConnection extends EventEmitter {
options = (<IORedis.ClusterOptions>options).redisOptions;
}

this.checkOptions(deprecationMessage, options);
if (
(<IORedis.RedisOptions>options).maxRetriesPerRequest ||
options.enableReadyCheck
) {
throw new Error(connectionErrorMessage);
}
}

this.handleClientError = (err: Error): void => {
Expand Down
26 changes: 26 additions & 0 deletions tests/test_connection.ts
Expand Up @@ -42,6 +42,32 @@ describe('connection', () => {
checkOptions(await queue.client);
});

describe('when reusing connection with enableReadyCheck as true', () => {
it('throws an error', async () => {
const connection = new IORedis({
maxRetriesPerRequest: null,
enableReadyCheck: true,
});

expect(() => new QueueBase(queueName, { connection })).to
.throw(`Using a redis instance with enableReadyCheck or maxRetriesPerRequest is not permitted.
See https://https://github.com/OptimalBits/bull/issues/1873`);
});
});

describe('when reusing connection with maxRetriesPerRequest different than null', () => {
it('throws an error', async () => {
const connection = new IORedis({
maxRetriesPerRequest: 1,
enableReadyCheck: false,
});

expect(() => new QueueBase(queueName, { connection })).to
.throw(`Using a redis instance with enableReadyCheck or maxRetriesPerRequest is not permitted.
See https://https://github.com/OptimalBits/bull/issues/1873`);
});
});

describe('when maxmemory-policy is different than noeviction in Redis', () => {
it('throws an error', async () => {
const opts = {
Expand Down
5 changes: 4 additions & 1 deletion tests/test_worker.ts
Expand Up @@ -654,7 +654,10 @@ describe('workers', function () {

describe('when sharing a redis connection between workers', function () {
it('should not close the connection', async () => {
const connection = new IORedis();
const connection = new IORedis({
maxRetriesPerRequest: null,
enableReadyCheck: false,
});

return new Promise((resolve, reject) => {
connection.on('ready', async () => {
Expand Down