1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00
This commit is contained in:
Leibale
2023-06-07 11:45:48 -04:00
parent 05f9f0ee0d
commit cf79a806c5
22 changed files with 1761 additions and 7268 deletions

View File

@@ -1,7 +1,7 @@
import { createConnection } from 'net';
import { once } from 'events';
import RedisClient from '@redis/client/dist/lib/client';
import { promiseTimeout } from '@redis/client/dist/lib/utils';
import { createClient } from '@redis/client';
import { setTimeout } from 'timers/promises';
// import { ClusterSlotsReply } from '@redis/client/dist/lib/commands/CLUSTER_SLOTS';
import * as path from 'path';
import { promisify } from 'util';
@@ -46,8 +46,8 @@ export interface RedisServerDocker {
dockerId: string;
}
// ".." cause it'll be in `./dist`
const DOCKER_FODLER_PATH = path.join(__dirname, '../docker');
// extrea ".." cause it'll be in `./dist`
const DOCKER_FODLER_PATH = path.join(__dirname, '../../docker');
async function spawnRedisServerDocker({ image, version }: RedisServerDockerConfig, serverArguments: Array<string>): Promise<RedisServerDocker> {
const port = (await portIterator.next()).value,
@@ -64,7 +64,7 @@ async function spawnRedisServerDocker({ image, version }: RedisServerDockerConfi
}
while (await isPortAvailable(port)) {
await promiseTimeout(50);
await setTimeout(50);
}
return {
@@ -139,7 +139,7 @@ async function spawnRedisClusterNodeDockers(
await replica.client.clusterMeet('127.0.0.1', master.docker.port);
while ((await replica.client.clusterSlots()).length === 0) {
await promiseTimeout(50);
await setTimeout(50);
}
await replica.client.clusterReplicate(
@@ -162,13 +162,13 @@ async function spawnRedisClusterNodeDocker(
serverArguments: Array<string>
) {
const docker = await spawnRedisServerDocker(dockersConfig, [
...serverArguments,
'--cluster-enabled',
'yes',
'--cluster-node-timeout',
'5000'
]),
client = RedisClient.create({
...serverArguments,
'--cluster-enabled',
'yes',
'--cluster-node-timeout',
'5000'
]),
client = createClient({
socket: {
port: docker.port
}
@@ -220,10 +220,10 @@ async function spawnRedisClusterDockers(
totalNodes(await client.clusterSlots()) !== nodes.length ||
!(await client.sendCommand<string>(['CLUSTER', 'INFO'])).startsWith('cluster_state:ok') // TODO
) {
await promiseTimeout(50);
await setTimeout(50);
}
return client.disconnect();
client.destroy();
})
);

View File

@@ -1,7 +1,3 @@
// import { RedisModules, RedisFunctions, RedisScripts } from '@redis/client/lib/commands';
// import RedisClient, { RedisClientOptions, RedisClientType } from '@redis/client/lib/client';
// import RedisCluster, { RedisClusterOptions, RedisClusterType } from '@redis/client/lib/cluster';
// import { RedisSocketCommonOptions } from '@redis/client/lib/client/socket';
import {
RedisModules,
RedisFunctions,
@@ -13,7 +9,7 @@ import {
createCluster,
RedisClusterOptions,
RedisClusterType
} from '@redis/client/index';
} from '@redis/client';
import { RedisServerDockerConfig, spawnRedisServer, spawnRedisCluster } from './dockers';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
@@ -136,10 +132,10 @@ export default class TestUtils {
}
testWithClient<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts,
RESP extends RespVersions
M extends RedisModules = {},
F extends RedisFunctions = {},
S extends RedisScripts = {},
RESP extends RespVersions = 2
>(
title: string,
fn: (client: RedisClientType<M, F, S, RESP>) => unknown,
@@ -181,7 +177,7 @@ export default class TestUtils {
} finally {
if (client.isOpen) {
await client.flushAll();
await client.disconnect();
client.destroy();
}
}
});
@@ -203,10 +199,10 @@ export default class TestUtils {
}
testWithCluster<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts,
RESP extends RespVersions
M extends RedisModules = {},
F extends RedisFunctions = {},
S extends RedisScripts = {},
RESP extends RespVersions = 2
>(
title: string,
fn: (cluster: RedisClusterType<M, F, S, RESP>) => unknown,
@@ -254,10 +250,10 @@ export default class TestUtils {
}
testAll<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts,
RESP extends RespVersions
M extends RedisModules = {},
F extends RedisFunctions = {},
S extends RedisScripts = {},
RESP extends RespVersions = 2
>(
title: string,
fn: (client: RedisClientType<M, F, S, RESP> | RedisClusterType<M, F, S, RESP>) => unknown,

View File

@@ -1,24 +1,13 @@
{
"name": "@redis/test-utils",
"private": true,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc"
},
"main": "./dist/lib/index.js",
"types": "./dist/lib/index.d.ts",
"peerDependencies": {
"@redis/client": "^1.0.0"
"@redis/client": "*"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/mocha": "^10.0.1",
"@types/node": "^18.16.1",
"@types/yargs": "^17.0.24",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
"typescript": "^5.0.4",
"yargs": "^17.7.1"
"yargs": "^17.7.2"
}
}