Skip to content

Commit f346bad

Browse files
Adapt legacy sentinel tests to use the new test utils (#2976)
* modified legacy sentinel tests * Adapt legacy sentinel tests to use the new test utils * modify tmpdir creation * reduced sentinel config timeouts, removed unneeded comment --------- Co-authored-by: H. Temelski <hristo.temelski@redis.com>
1 parent 065eb5e commit f346bad

File tree

6 files changed

+264
-308
lines changed

6 files changed

+264
-308
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ describe('Client', () => {
8989
&& expected?.credentialsProvider?.type === 'async-credentials-provider') {
9090

9191
// Compare the actual output of the credentials functions
92-
const resultCreds = await result.credentialsProvider.credentials();
93-
const expectedCreds = await expected.credentialsProvider.credentials();
92+
const resultCreds = await result.credentialsProvider?.credentials();
93+
const expectedCreds = await expected.credentialsProvider?.credentials();
9494
assert.deepEqual(resultCreds, expectedCreds);
9595
} else {
9696
assert.fail('Credentials provider type mismatch');

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

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ describe(`test with scripts`, () => {
197197
}, GLOBAL.SENTINEL.WITH_SCRIPT)
198198
});
199199

200-
201200
describe(`test with functions`, () => {
202201
testUtils.testWithClientSentinel('with function', async sentinel => {
203202
await sentinel.functionLoad(
@@ -377,12 +376,9 @@ describe(`test with masterPoolSize 2`, () => {
377376
}, GLOBAL.SENTINEL.WITH_MASTER_POOL_SIZE_2);
378377
});
379378

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

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

442-
before(async function () {
443-
this.timeout(15000);
444-
445-
last = Date.now();
446-
447-
function deltaMeasurer() {
448-
const delta = Date.now() - last;
449-
if (delta > longestDelta) {
450-
longestDelta = delta;
451-
}
452-
if (delta > longestTestDelta) {
453-
longestTestDelta = delta;
454-
}
455-
if (!stopMeasuringBlocking) {
456-
last = Date.now();
457-
setImmediate(deltaMeasurer);
458-
}
459-
}
460-
setImmediate(deltaMeasurer);
461-
await frame.spawnRedisSentinel();
462-
});
463-
464-
after(async function () {
465-
this.timeout(15000);
466-
467-
stopMeasuringBlocking = true;
468-
469-
await frame.cleanup();
470-
})
471438

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

475442
beforeEach(async function () {
476-
this.timeout(0);
477-
443+
this.timeout(15000);
444+
445+
last = Date.now();
446+
447+
function deltaMeasurer() {
448+
const delta = Date.now() - last;
449+
if (delta > longestDelta) {
450+
longestDelta = delta;
451+
}
452+
if (delta > longestTestDelta) {
453+
longestTestDelta = delta;
454+
}
455+
if (!stopMeasuringBlocking) {
456+
last = Date.now();
457+
setImmediate(deltaMeasurer);
458+
}
459+
}
460+
setImmediate(deltaMeasurer);
461+
await frame.spawnRedisSentinel();
478462
await frame.getAllRunning();
479463
await steadyState(frame);
480464
longestTestDelta = 0;
@@ -522,6 +506,10 @@ describe.skip('legacy tests', () => {
522506
await sentinel.destroy();
523507
sentinel = undefined;
524508
}
509+
510+
stopMeasuringBlocking = true;
511+
512+
await frame.cleanup();
525513
})
526514

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

864852
it('shutdown sentinel node', async function () {
865853
this.timeout(60000);
866-
867854
sentinel = frame.getSentinelClient();
868855
sentinel.setTracer(tracer);
869856
sentinel.on("error", () => { });
@@ -1020,7 +1007,7 @@ describe.skip('legacy tests', () => {
10201007
this.timeout(30000);
10211008
const csc = new BasicPooledClientSideCache();
10221009

1023-
sentinel = frame.getSentinelClient({nodeClientOptions: {RESP: 3}, clientSideCache: csc, masterPoolSize: 5});
1010+
sentinel = frame.getSentinelClient({nodeClientOptions: {RESP: 3 as const}, RESP: 3 as const, clientSideCache: csc, masterPoolSize: 5});
10241011
await sentinel.connect();
10251012

10261013
await sentinel.set('x', 1);

0 commit comments

Comments
 (0)