Skip to content

Commit 3855ae8

Browse files
committed
add test template for the new cluster events
1 parent 1875813 commit 3855ae8

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,30 @@ describe('Cluster', () => {
339339
minimumDockerVersion: [7]
340340
});
341341
});
342+
343+
describe('clusterEvents', () => {
344+
testUtils.testWithCluster('should fire events', async (cluster) => {
345+
const log: string[] = [];
346+
cluster
347+
.on('connect', () => log.push('connect'))
348+
.on('disconnect', () => log.push('disconnect'))
349+
.on('error', () => log.push('error'))
350+
.on('node-error', () => log.push('node-error'))
351+
.on('node-reconnecting', () => log.push('node-reconnecting'))
352+
.on('node-ready', () => log.push('node-ready'))
353+
.on('node-connect', () => log.push('node-connect'))
354+
.on('node-disconnect', () => log.push('node-disconnect'))
355+
356+
357+
await cluster.connect();
358+
cluster.destroy();
359+
360+
/* assertions on the log */
361+
362+
}, {
363+
...GLOBAL.CLUSTERS.OPEN,
364+
disableClusterSetup: true
365+
})
366+
});
367+
342368
});

packages/test-utils/lib/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ interface ClusterTestOptions<
116116
clusterConfiguration?: Partial<RedisClusterOptions<M, F, S, RESP, TYPE_MAPPING/*, POLICIES*/>>;
117117
numberOfMasters?: number;
118118
numberOfReplicas?: number;
119+
disableClusterSetup?: boolean;
119120
}
120121

121122
interface AllTestOptions<
@@ -558,6 +559,10 @@ export default class TestUtils {
558559
...options.clusterConfiguration
559560
});
560561

562+
if(options.disableClusterSetup) {
563+
return fn(cluster);
564+
}
565+
561566
await cluster.connect();
562567

563568
try {

0 commit comments

Comments
 (0)