Skip to content

Adapt legacy sentinel tests to use the new test utils #2976

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

Merged
merged 4 commits into from
May 27, 2025
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
4 changes: 2 additions & 2 deletions packages/client/lib/client/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ describe('Client', () => {
&& expected?.credentialsProvider?.type === 'async-credentials-provider') {

// Compare the actual output of the credentials functions
const resultCreds = await result.credentialsProvider.credentials();
const expectedCreds = await expected.credentialsProvider.credentials();
const resultCreds = await result.credentialsProvider?.credentials();
const expectedCreds = await expected.credentialsProvider?.credentials();
assert.deepEqual(resultCreds, expectedCreds);
} else {
assert.fail('Credentials provider type mismatch');
Expand Down
67 changes: 27 additions & 40 deletions packages/client/lib/sentinel/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ describe(`test with scripts`, () => {
}, GLOBAL.SENTINEL.WITH_SCRIPT)
});


describe(`test with functions`, () => {
testUtils.testWithClientSentinel('with function', async sentinel => {
await sentinel.functionLoad(
Expand Down Expand Up @@ -377,12 +376,9 @@ describe(`test with masterPoolSize 2`, () => {
}, GLOBAL.SENTINEL.WITH_MASTER_POOL_SIZE_2);
});


// TODO: Figure out how to modify the test utils
// so it would have fine grained controll over
// sentinel
// it should somehow replicate the `SentinelFramework` object functionallities
async function steadyState(frame: SentinelFramework) {
// wait a bit to ensure that sentinels are seeing eachother
await setTimeout(2000)
let checkedMaster = false;
let checkedReplicas = false;
while (!checkedMaster || !checkedReplicas) {
Expand Down Expand Up @@ -430,7 +426,7 @@ async function steadyState(frame: SentinelFramework) {
}
}

describe.skip('legacy tests', () => {
describe('legacy tests', () => {
const config: RedisSentinelConfig = { sentinelName: "test", numberOfNodes: 3, password: undefined };
const frame = new SentinelFramework(config);
let tracer = new Array<string>();
Expand All @@ -439,42 +435,30 @@ describe.skip('legacy tests', () => {
let longestTestDelta = 0;
let last: number;

before(async function () {
this.timeout(15000);

last = Date.now();

function deltaMeasurer() {
const delta = Date.now() - last;
if (delta > longestDelta) {
longestDelta = delta;
}
if (delta > longestTestDelta) {
longestTestDelta = delta;
}
if (!stopMeasuringBlocking) {
last = Date.now();
setImmediate(deltaMeasurer);
}
}
setImmediate(deltaMeasurer);
await frame.spawnRedisSentinel();
});

after(async function () {
this.timeout(15000);

stopMeasuringBlocking = true;

await frame.cleanup();
})

describe('Sentinel Client', function () {
let sentinel: RedisSentinelType<RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping> | undefined;

beforeEach(async function () {
this.timeout(0);

this.timeout(15000);

last = Date.now();

function deltaMeasurer() {
const delta = Date.now() - last;
if (delta > longestDelta) {
longestDelta = delta;
}
if (delta > longestTestDelta) {
longestTestDelta = delta;
}
if (!stopMeasuringBlocking) {
last = Date.now();
setImmediate(deltaMeasurer);
}
}
setImmediate(deltaMeasurer);
await frame.spawnRedisSentinel();
await frame.getAllRunning();
await steadyState(frame);
longestTestDelta = 0;
Expand Down Expand Up @@ -522,6 +506,10 @@ describe.skip('legacy tests', () => {
await sentinel.destroy();
sentinel = undefined;
}

stopMeasuringBlocking = true;

await frame.cleanup();
})

it('use', async function () {
Expand Down Expand Up @@ -863,7 +851,6 @@ describe.skip('legacy tests', () => {

it('shutdown sentinel node', async function () {
this.timeout(60000);

sentinel = frame.getSentinelClient();
sentinel.setTracer(tracer);
sentinel.on("error", () => { });
Expand Down Expand Up @@ -1020,7 +1007,7 @@ describe.skip('legacy tests', () => {
this.timeout(30000);
const csc = new BasicPooledClientSideCache();

sentinel = frame.getSentinelClient({nodeClientOptions: {RESP: 3}, clientSideCache: csc, masterPoolSize: 5});
sentinel = frame.getSentinelClient({nodeClientOptions: {RESP: 3 as const}, RESP: 3 as const, clientSideCache: csc, masterPoolSize: 5});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the double {RESP: 3 as const}, RESP: 3 as const,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false alarm

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the second RESP: 3 as const, I was getting Client Side Caching is only supported with RESP3 error. I couldn't figure out why it was happening. Considering that the SentinelFramework is used only for testing, I didn't want to spend too much time on it.

await sentinel.connect();

await sentinel.set('x', 1);
Expand Down
Loading
Loading