(
title: string,
fn: (cluster: RedisClusterType<M, F, S, RESP, TYPE_MAPPING/*, POLICIES*/>) => unknown,
options: ClusterTestOptions<M, F, S, RESP, TYPE_MAPPING/*, POLICIES*/>
)
| 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(); |
no test coverage detected