Skip to content

Commit da19af8

Browse files
[CAE-342] Fix a couple of bugs
1 parent 4cbecf6 commit da19af8

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

packages/client/lib/client/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ export default class RedisClient<
325325
return this._self.#watchEpoch !== undefined;
326326
}
327327

328+
get watchEpoch() {
329+
return this._self.#watchEpoch
330+
}
331+
332+
setWatchEpoch(watchEpoch: number | undefined) {
333+
this._self.#watchEpoch = watchEpoch
334+
}
335+
328336
setDirtyWatch(msg: string) {
329337
this._self.#dirtyWatch = msg;
330338
}

packages/client/lib/sentinel/index.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ async function steadyState(frame: SentinelFramework) {
197197

198198
await assert.doesNotReject(sentinel.get('x'));
199199
});
200+
201+
it('failed to connect', async function() {
202+
sentinel = frame.getSentinelClient({sentinelRootNodes: [{host: "127.0.0.1", port: 1010}], maxCommandRediscovers: 0})
203+
await assert.rejects(sentinel.connect());
204+
});
200205

201206
it('try to connect multiple times', async function () {
202207
sentinel = frame.getSentinelClient();

packages/client/lib/sentinel/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,10 @@ class RedisSentinelInternal<
682682

683683
async #connect() {
684684
let count = 0;
685-
while (true) {
685+
while (true) {
686686
this.#trace("starting connect loop");
687687

688+
count+=1;
688689
if (this.#destroy) {
689690
this.#trace("in #connect and want to destroy")
690691
return;
@@ -1106,10 +1107,12 @@ class RedisSentinelInternal<
11061107
this.#trace(`transform: opening a new master`);
11071108
const masterPromises = [];
11081109
const masterWatches: Array<boolean> = [];
1110+
const watchEpochs: Array<number|undefined> = [];
11091111

11101112
this.#trace(`transform: destroying old masters if open`);
11111113
for (const client of this.#masterClients) {
11121114
masterWatches.push(client.isWatching);
1115+
watchEpochs.push(client.watchEpoch);
11131116

11141117
if (client.isOpen) {
11151118
client.destroy()
@@ -1135,6 +1138,7 @@ class RedisSentinelInternal<
11351138
});
11361139

11371140
if (masterWatches[i]) {
1141+
client.setWatchEpoch(watchEpochs[i])
11381142
client.setDirtyWatch("sentinel config changed in middle of a WATCH Transaction");
11391143
}
11401144
this.#masterClients.push(client);

packages/client/lib/sentinel/test-util.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,14 @@ export class SentinelFramework extends DockerBase {
180180
RedisScripts,
181181
RespVersions,
182182
TypeMapping>>, errors = true) {
183-
if (opts?.sentinelRootNodes !== undefined) {
184-
throw new Error("cannot specify sentinelRootNodes here");
185-
}
183+
// remove this safeguard
184+
// in order to test the case when
185+
// connecting to sentinel fails
186+
187+
// if (opts?.sentinelRootNodes !== undefined) {
188+
// throw new Error("cannot specify sentinelRootNodes here");
189+
// }
190+
186191
if (opts?.name !== undefined) {
187192
throw new Error("cannot specify sentinel db name here");
188193
}

0 commit comments

Comments
 (0)