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

Method testWithProxiedClient

packages/test-utils/lib/index.ts:579–617  ·  view source on GitHub ↗
(
    title: string,
    // eslint-disable-next-line @typescript-eslint/no-explicit-any -- variance markers for client generics
    fn: (proxiedClient: RedisClientType<any, any, any, any, any>, proxy: RedisProxy) => unknown,
    // eslint-disable-next-line @typescript-eslint/no-explicit-any -- variance markers for client generics
    options: ClientTestOptions<any, any, any, any, any>
  )

Source from the content-addressed store, hash-verified

577 }
578
579 testWithProxiedClient(
580 title: string,
581 // eslint-disable-next-line @typescript-eslint/no-explicit-any -- variance markers for client generics
582 fn: (proxiedClient: RedisClientType<any, any, any, any, any>, proxy: RedisProxy) => unknown,
583 // eslint-disable-next-line @typescript-eslint/no-explicit-any -- variance markers for client generics
584 options: ClientTestOptions<any, any, any, any, any>
585 ) {
586
587 this.testWithClient(title, async (client) => {
588 const freePort = await getFreePortNumber()
589 const socketOptions = client?.options?.socket;
590 const proxy = new RedisProxy({
591 listenHost: '127.0.0.1',
592 listenPort: freePort,
593 // @ts-expect-error -- proxy tests target TCP-only socket options
594 targetPort: socketOptions.port,
595 // @ts-expect-error -- proxy tests target TCP-only socket options
596 targetHost: socketOptions.host ?? '127.0.0.1',
597 enableLogging: true
598 });
599
600 await proxy.start();
601 const proxyClient = client.duplicate({
602 socket: {
603 port: proxy.config.listenPort,
604 host: proxy.config.listenHost
605 },
606 });
607
608 await proxyClient.connect();
609
610 try {
611 await fn(proxyClient, proxy);
612 } finally {
613 await proxyClient.destroy();
614 await proxy.stop()
615 }
616 }, options);
617 }
618 testWithClientSentinel<
619 M extends RedisModules = {},
620 F extends RedisFunctions = {},

Callers 1

Calls 7

testWithClientMethod · 0.95
startMethod · 0.95
stopMethod · 0.95
getFreePortNumberFunction · 0.90
destroyMethod · 0.65
duplicateMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected