Skip to content

Commit

Permalink
Merge pull request #1269 from moleculerjs/fix-redis-connect-event
Browse files Browse the repository at this point in the history
change from 'connect' to 'ready' event in redis clients. Fixes #1257
  • Loading branch information
icebob authored Jan 13, 2024
2 parents b2c5a49 + 8b1f39e commit 7560626
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
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

0 comments on commit 7560626

Please sign in to comment.