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

change from 'connect' to 'ready' event in redis clients. Fixes #1257 #1269

Merged
merged 2 commits into from
Jan 13, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cachers/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class RedisCacher extends BaseCacher {

this.connected = false;

this.client.on("connect", () => {
this.client.on("ready", () => {
this.connected = true;

/* istanbul ignore next */
Expand Down
4 changes: 2 additions & 2 deletions src/transporters/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class RedisTransporter extends Transporter {
let clientSub = this.getRedisClient(this.opts);
this._clientSub = clientSub; // For tests

clientSub.on("connect", () => {
clientSub.on("ready", () => {
this.logger.info("Redis-sub client is connected.");

let clientPub = this.getRedisClient(this.opts);
this._clientPub = clientPub; // For tests

clientPub.on("connect", () => {
clientPub.on("ready", () => {
this.clientSub = clientSub;
this.clientPub = clientPub;

Expand Down
24 changes: 12 additions & 12 deletions test/unit/transporters/redis.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function itShouldTestRedisTransportConnectDisconnect(clusterMode = false) {
let p = transporter.connect().then(() => {
expect(transporter.clientSub).toBeDefined();
expect(transporter.clientSub.on).toHaveBeenCalledTimes(4);
expect(transporter.clientSub.on).toHaveBeenCalledWith("connect", expect.any(Function));
expect(transporter.clientSub.on).toHaveBeenCalledWith("ready", expect.any(Function));
expect(transporter.clientSub.on).toHaveBeenCalledWith("error", expect.any(Function));
expect(transporter.clientSub.on).toHaveBeenCalledWith("close", expect.any(Function));
expect(transporter.clientSub.on).toHaveBeenCalledWith(
Expand All @@ -151,13 +151,13 @@ function itShouldTestRedisTransportConnectDisconnect(clusterMode = false) {

expect(transporter.clientPub).toBeDefined();
expect(transporter.clientPub.on).toHaveBeenCalledTimes(3);
expect(transporter.clientPub.on).toHaveBeenCalledWith("connect", expect.any(Function));
expect(transporter.clientPub.on).toHaveBeenCalledWith("ready", expect.any(Function));
expect(transporter.clientPub.on).toHaveBeenCalledWith("error", expect.any(Function));
expect(transporter.clientPub.on).toHaveBeenCalledWith("close", expect.any(Function));
});

transporter._clientSub.onCallbacks.connect();
transporter._clientPub.onCallbacks.connect();
transporter._clientSub.onCallbacks.ready();
transporter._clientPub.onCallbacks.ready();

return p;
});
Expand All @@ -182,8 +182,8 @@ function itShouldTestRedisTransportConnectDisconnect(clusterMode = false) {
});
});

transporter._clientSub.onCallbacks.connect();
transporter._clientPub.onCallbacks.connect();
transporter._clientSub.onCallbacks.ready();
transporter._clientPub.onCallbacks.ready();
// Trigger an error
transporter._clientPub.onCallbacks.error(new Error("Ups"));
transporter._clientSub.onCallbacks.error(new Error("Ups"));
Expand All @@ -198,8 +198,8 @@ function itShouldTestRedisTransportConnectDisconnect(clusterMode = false) {
expect(transporter.onConnected).toHaveBeenCalledWith();
});

transporter._clientSub.onCallbacks.connect();
transporter._clientPub.onCallbacks.connect();
transporter._clientSub.onCallbacks.ready();
transporter._clientPub.onCallbacks.ready();

return p;
});
Expand All @@ -215,8 +215,8 @@ function itShouldTestRedisTransportConnectDisconnect(clusterMode = false) {
expect(cbPub).toHaveBeenCalledTimes(1);
});

transporter._clientSub.onCallbacks.connect(); // Trigger the `resolve`
transporter._clientPub.onCallbacks.connect(); // Trigger the `resolve`
transporter._clientSub.onCallbacks.ready(); // Trigger the `resolve`
transporter._clientPub.onCallbacks.ready(); // Trigger the `resolve`
return p;
});
}
Expand Down Expand Up @@ -247,8 +247,8 @@ function itShouldTestRedisTransportPublishSubscribe(clusterMode = false) {
transporter.incomingMessage = jest.fn();

let p = transporter.connect();
transporter._clientSub.onCallbacks.connect(); // Trigger the `resolve`
transporter._clientPub.onCallbacks.connect(); // Trigger the `resolve`
transporter._clientSub.onCallbacks.ready(); // Trigger the `resolve`
transporter._clientPub.onCallbacks.ready(); // Trigger the `resolve`
return p;
});

Expand Down
Loading