1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

fix(sentinel): Migrated to the new testing framework, fixed issues that were discovered during transition

* [CAE-342] Fix a couple of bugs

* Fixed issue with nodes masterauth persistency, changed docker container

* [CAE-342] Fixed a couple of sentinel issues, enabled most tests

* [CAE-342] Added comment

* [CAE-342] Migrate majority of tests to testUtils

* [CAE-342] Minor refactor

* .

* [CAE-342] Using cae containers for sentinel

* [CAE-342] Improved resiliency of the legacy tests, added TSdoc comment

* [CAE-342] Some extra logging, removed unneeded changes

* [CAE-342] Moved docker env as optional part of redisserverdockerconfig

* [CAE-342] Move password to serverArguments

* [CAE-342] Moved ts-node to devDependencies

* [CAE-342] Reverted legacy testing framework improvements
This commit is contained in:
Hristo Temelski
2025-04-30 15:56:29 +03:00
committed by GitHub
parent 048df302e4
commit 10ff6debab
9 changed files with 1459 additions and 1253 deletions

View File

@@ -299,6 +299,9 @@ export default class RedisClient<
#monitorCallback?: MonitorCallback<TYPE_MAPPING>;
private _self = this;
private _commandOptions?: CommandOptions<TYPE_MAPPING>;
// flag used to annotate that the client
// was in a watch transaction when
// a topology change occured
#dirtyWatch?: string;
#epoch: number;
#watchEpoch?: number;
@@ -325,6 +328,20 @@ export default class RedisClient<
return this._self.#watchEpoch !== undefined;
}
/**
* Indicates whether the client's WATCH command has been invalidated by a topology change.
* When this returns true, any transaction using WATCH will fail with a WatchError.
* @returns true if the watched keys have been modified, false otherwise
*/
get isDirtyWatch(): boolean {
return this._self.#dirtyWatch !== undefined
}
/**
* Marks the client's WATCH command as invalidated due to a topology change.
* This will cause any subsequent EXEC in a transaction to fail with a WatchError.
* @param msg - The error message explaining why the WATCH is dirty
*/
setDirtyWatch(msg: string) {
this._self.#dirtyWatch = msg;
}

File diff suppressed because it is too large Load Diff

View File

@@ -345,9 +345,12 @@ export default class RedisSentinel<
key: K,
value: V
) {
const proxy = Object.create(this._self);
proxy._commandOptions = Object.create(this._self.#commandOptions ?? null);
proxy._commandOptions[key] = value;
const proxy = Object.create(this);
// Create new commandOptions object with the inherited properties
proxy._self.#commandOptions = {
...(this._self.#commandOptions || {}),
[key]: value
};
return proxy as RedisSentinelType<
M,
F,
@@ -682,9 +685,10 @@ class RedisSentinelInternal<
async #connect() {
let count = 0;
while (true) {
while (true) {
this.#trace("starting connect loop");
count+=1;
if (this.#destroy) {
this.#trace("in #connect and want to destroy")
return;
@@ -1109,7 +1113,7 @@ class RedisSentinelInternal<
this.#trace(`transform: destroying old masters if open`);
for (const client of this.#masterClients) {
masterWatches.push(client.isWatching);
masterWatches.push(client.isWatching || client.isDirtyWatch);
if (client.isOpen) {
client.destroy()
@@ -1460,4 +1464,4 @@ export class RedisSentinelFactory extends EventEmitter {
}
});
}
}
}

View File

@@ -602,4 +602,4 @@ export class SentinelFramework extends DockerBase {
}
}
}
}
}

View File

@@ -2,9 +2,10 @@ import TestUtils from '@redis/test-utils';
import { SinonSpy } from 'sinon';
import { setTimeout } from 'node:timers/promises';
import { CredentialsProvider } from './authx';
import { Command } from './RESP/types';
import { BasicCommandParser } from './client/parser';
import { Command, NumberReply } from './RESP/types';
import { BasicCommandParser, CommandParser } from './client/parser';
import { defineScript } from './lua-script';
import RedisBloomModules from '@redis/bloom';
const utils = TestUtils.createFromConfig({
dockerImageName: 'redislabs/client-libs-test',
dockerImageVersionArgument: 'redis-version',
@@ -42,6 +43,45 @@ const streamingCredentialsProvider: CredentialsProvider =
} as const;
const SQUARE_SCRIPT = defineScript({
SCRIPT:
`local number = redis.call('GET', KEYS[1])
return number * number`,
NUMBER_OF_KEYS: 1,
FIRST_KEY_INDEX: 0,
parseCommand(parser: CommandParser, key: string) {
parser.pushKey(key);
},
transformReply: undefined as unknown as () => NumberReply
});
export const MATH_FUNCTION = {
name: 'math',
engine: 'LUA',
code:
`#!LUA name=math
redis.register_function {
function_name = "square",
callback = function(keys, args)
local number = redis.call('GET', keys[1])
return number * number
end,
flags = { "no-writes" }
}`,
library: {
square: {
NAME: 'square',
IS_READ_ONLY: true,
NUMBER_OF_KEYS: 1,
FIRST_KEY_INDEX: 0,
parseCommand(parser: CommandParser, key: string) {
parser.pushKey(key);
},
transformReply: undefined as unknown as () => NumberReply
}
}
};
export const GLOBAL = {
SERVERS: {
OPEN: {
@@ -86,6 +126,43 @@ export const GLOBAL = {
useReplicas: true
}
}
},
SENTINEL: {
OPEN: {
serverArguments: [...DEBUG_MODE_ARGS],
},
PASSWORD: {
serverArguments: ['--requirepass', 'test_password', ...DEBUG_MODE_ARGS],
},
WITH_SCRIPT: {
serverArguments: [...DEBUG_MODE_ARGS],
scripts: {
square: SQUARE_SCRIPT,
},
},
WITH_FUNCTION: {
serverArguments: [...DEBUG_MODE_ARGS],
functions: {
math: MATH_FUNCTION.library,
},
},
WITH_MODULE: {
serverArguments: [...DEBUG_MODE_ARGS],
modules: RedisBloomModules,
},
WITH_REPLICA_POOL_SIZE_1: {
serverArguments: [...DEBUG_MODE_ARGS],
replicaPoolSize: 1,
},
WITH_RESERVE_CLIENT_MASTER_POOL_SIZE_2: {
serverArguments: [...DEBUG_MODE_ARGS],
masterPoolSize: 2,
reserveClient: true,
},
WITH_MASTER_POOL_SIZE_2: {
serverArguments: [...DEBUG_MODE_ARGS],
masterPoolSize: 2,
}
}
};