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

Method testWithClientPool

packages/test-utils/lib/index.ts:738–784  ·  view source on GitHub ↗
(
    title: string,
    fn: (client: RedisClientPoolType<M, F, S, RESP, TYPE_MAPPING>) => unknown,
    options: ClientPoolTestOptions<M, F, S, RESP, TYPE_MAPPING>
  )

Source from the content-addressed store, hash-verified

736 }
737
738 testWithClientPool<
739 M extends RedisModules = {},
740 F extends RedisFunctions = {},
741 S extends RedisScripts = {},
742 RESP extends RespVersions = 2,
743 TYPE_MAPPING extends TypeMapping = {}
744 >(
745 title: string,
746 fn: (client: RedisClientPoolType<M, F, S, RESP, TYPE_MAPPING>) => unknown,
747 options: ClientPoolTestOptions<M, F, S, RESP, TYPE_MAPPING>
748 ): void {
749 let dockerPromise: ReturnType<typeof spawnRedisServer>;
750 if (this.isVersionGreaterThan(options.minimumDockerVersion)) {
751 const dockerImage = this.#DOCKER_IMAGE;
752 before(function () {
753 this.timeout(30000);
754
755 dockerPromise = spawnRedisServer(dockerImage, options.serverArguments);
756 return dockerPromise;
757 });
758 }
759
760 it(title, async function () {
761 if (options.skipTest) return this.skip();
762 if (!dockerPromise) return this.skip();
763
764 const pool = createClientPool({
765 ...options.clientOptions,
766 socket: {
767 ...options.clientOptions?.socket,
768 port: (await dockerPromise).port
769 }
770 }, options.poolOptions);
771
772 await pool.connect();
773
774 try {
775 await pool.flushAll();
776 await fn(pool);
777 } finally {
778 if (pool.isOpen) {
779 await pool.flushAll();
780 pool.destroy();
781 }
782 }
783 });
784 }
785
786 static async #clusterFlushAll<
787 M extends RedisModules,

Callers 4

pool.spec.tsFile · 0.80
cache.spec.tsFile · 0.80
key-prefix.spec.tsFile · 0.80
metrics.spec.tsFile · 0.80

Calls 6

isVersionGreaterThanMethod · 0.95
spawnRedisServerFunction · 0.90
createClientPoolFunction · 0.90
flushAllMethod · 0.80
destroyMethod · 0.65
connectMethod · 0.45

Tested by

no test coverage detected