MCPcopy
hub / github.com/redis/node-redis / testWithCluster

Method testWithCluster

packages/test-utils/lib/index.ts:803–863  ·  view source on GitHub ↗
(
    title: string,
    fn: (cluster: RedisClusterType<M, F, S, RESP, TYPE_MAPPING/*, POLICIES*/>) => unknown,
    options: ClusterTestOptions<M, F, S, RESP, TYPE_MAPPING/*, POLICIES*/>
  )

Source from the content-addressed store, hash-verified

801 }
802
803 testWithCluster<
804 M extends RedisModules = {},
805 F extends RedisFunctions = {},
806 S extends RedisScripts = {},
807 RESP extends RespVersions = 2,
808 TYPE_MAPPING extends TypeMapping = {}
809 // POLICIES extends CommandPolicies = {}
810 >(
811 title: string,
812 fn: (cluster: RedisClusterType<M, F, S, RESP, TYPE_MAPPING/*, POLICIES*/>) => unknown,
813 options: ClusterTestOptions<M, F, S, RESP, TYPE_MAPPING/*, POLICIES*/>
814 ): void {
815 let dockersPromise: ReturnType<typeof spawnRedisCluster>;
816 if (this.isVersionGreaterThan(options.minimumDockerVersion)) {
817 const dockerImage = this.#DOCKER_IMAGE;
818 before(function () {
819 this.timeout(30000);
820
821 dockersPromise = spawnRedisCluster({
822 ...dockerImage,
823 numberOfMasters: options.numberOfMasters,
824 numberOfReplicas: options.numberOfReplicas
825 }, options.serverArguments,
826 options.clusterConfiguration?.defaults);
827 return dockersPromise;
828 });
829 }
830
831 it(title, async function () {
832 if (options.skipTest) return this.skip();
833 if (!dockersPromise) return this.skip();
834 const RESP = (options.clusterConfiguration?.RESP ?? DEFAULT_RESP) as RESP;
835 const { RESP: _RESP, ...clusterConfiguration } = options.clusterConfiguration ?? {};
836
837 const dockers = await dockersPromise,
838 cluster = createCluster({
839 rootNodes: dockers.map(({ port }) => ({
840 socket: {
841 port
842 }
843 })),
844 RESP,
845 minimizeConnections: options.clusterConfiguration?.minimizeConnections ?? true,
846 ...clusterConfiguration
847 }) as RedisClusterType<M, F, S, RESP, TYPE_MAPPING>;
848
849 if(options.disableClusterSetup) {
850 return fn(cluster);
851 }
852
853 await cluster.connect();
854
855 try {
856 await TestUtils.#clusterFlushAll(cluster);
857 await fn(cluster);
858 } finally {
859 await TestUtils.#clusterFlushAll(cluster);
860 cluster.destroy();

Callers 15

testAllMethod · 0.95
testAllAutoMethod · 0.95
cache.spec.tsFile · 0.80
key-prefix.spec.tsFile · 0.80
index.spec.tsFile · 0.80

Calls 6

isVersionGreaterThanMethod · 0.95
spawnRedisClusterFunction · 0.90
createClusterFunction · 0.90
#clusterFlushAllMethod · 0.80
destroyMethod · 0.65
connectMethod · 0.45

Tested by

no test coverage detected