From 65d0539eb7eb9649845ee744a4de4e0646fa194e Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 13 Feb 2024 15:06:34 +0100 Subject: [PATCH] test: run tests against a Redis cluster Related: - https://github.com/socketio/socket.io-redis-streams-adapter/issues/3 - https://github.com/socketio/socket.io-redis-streams-adapter/issues/10 --- .github/workflows/ci.yml | 10 +++- compose.yaml | 10 ++++ docker-compose.yml | 5 -- package-lock.json | 98 ++++++++++++++++++++-------------------- package.json | 4 +- test/util.ts | 49 ++++++++++++++++++-- 6 files changed, 116 insertions(+), 60 deletions(-) create mode 100644 compose.yaml delete mode 100644 docker-compose.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eab5ee5..566a07a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,15 @@ jobs: --health-retries 5 ports: - 6379:6379 - + redis-cluster: + image: grokzen/redis-cluster:7.0.10 + options: >- + --health-cmd "redis-cli -p 7005 ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - "7000-7005:7000-7005" steps: - name: Checkout repository uses: actions/checkout@v3 diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..e0b0417 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,10 @@ +services: + redis: + image: redis:5 + ports: + - "6379:6379" + + redis-cluster: + image: grokzen/redis-cluster:7.0.10 + ports: + - "7000-7005:7000-7005" diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index fdf5d8e..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,5 +0,0 @@ -services: - redis: - image: redis:5 - ports: - - "6379:6379" diff --git a/package-lock.json b/package-lock.json index b0cd291..d32e21c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@socket.io/redis-streams-adapter", - "version": "0.0.1", + "version": "0.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@socket.io/redis-streams-adapter", - "version": "0.0.1", + "version": "0.1.0", "license": "MIT", "dependencies": { "@msgpack/msgpack": "~2.8.0", @@ -27,7 +27,7 @@ "typescript": "^4.9.5" }, "engines": { - "node": ">=12.0.0" + "node": ">=14.0.0" }, "peerDependencies": { "socket.io-adapter": "^2.5.2" @@ -346,9 +346,9 @@ } }, "node_modules/@redis/client": { - "version": "1.5.6", - "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.6.tgz", - "integrity": "sha512-dFD1S6je+A47Lj22jN/upVU2fj4huR7S9APd7/ziUXsIXDL+11GPYti4Suv5y8FuXaN+0ZG4JF+y1houEJ7ToA==", + "version": "1.5.14", + "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.14.tgz", + "integrity": "sha512-YGn0GqsRBFUQxklhY7v562VMOP0DcmlrHHs3IV1mFE3cbxe31IITUkqhBcIhVSI/2JqtWAJXg5mjV4aU+zD0HA==", "dev": true, "dependencies": { "cluster-key-slot": "1.1.2", @@ -360,36 +360,36 @@ } }, "node_modules/@redis/graph": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@redis/graph/-/graph-1.1.0.tgz", - "integrity": "sha512-16yZWngxyXPd+MJxeSr0dqh2AIOi8j9yXKcKCwVaKDbH3HTuETpDVPcLujhFYVPtYrngSco31BUcSa9TH31Gqg==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@redis/graph/-/graph-1.1.1.tgz", + "integrity": "sha512-FEMTcTHZozZciLRl6GiiIB4zGm5z5F3F6a6FZCyrfxdKOhFlGkiAqlexWMBzCi4DcRoyiOsuLfW+cjlGWyExOw==", "dev": true, "peerDependencies": { "@redis/client": "^1.0.0" } }, "node_modules/@redis/json": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.4.tgz", - "integrity": "sha512-LUZE2Gdrhg0Rx7AN+cZkb1e6HjoSKaeeW8rYnt89Tly13GBI5eP4CwDVr+MY8BAYfCg4/N15OUrtLoona9uSgw==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.6.tgz", + "integrity": "sha512-rcZO3bfQbm2zPRpqo82XbW8zg4G/w4W3tI7X8Mqleq9goQjAGLL7q/1n1ZX4dXEAmORVZ4s1+uKLaUOg7LrUhw==", "dev": true, "peerDependencies": { "@redis/client": "^1.0.0" } }, "node_modules/@redis/search": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@redis/search/-/search-1.1.2.tgz", - "integrity": "sha512-/cMfstG/fOh/SsE+4/BQGeuH/JJloeWuH+qJzM8dbxuWvdWibWAOAHHCZTMPhV3xIlH4/cUEIA8OV5QnYpaVoA==", + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@redis/search/-/search-1.1.6.tgz", + "integrity": "sha512-mZXCxbTYKBQ3M2lZnEddwEAks0Kc7nauire8q20oA0oA/LoA+E/b5Y5KZn232ztPb1FkIGqo12vh3Lf+Vw5iTw==", "dev": true, "peerDependencies": { "@redis/client": "^1.0.0" } }, "node_modules/@redis/time-series": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.0.4.tgz", - "integrity": "sha512-ThUIgo2U/g7cCuZavucQTQzA9g9JbDDY2f64u3AbAoz/8vE2lt2U37LamDUVChhaDA3IRT9R6VvJwqnUfTJzng==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.0.5.tgz", + "integrity": "sha512-IFjIgTusQym2B5IZJG3XKr5llka7ey84fw/NOYqESP5WUfQs9zz1ww/9+qoz4ka/S6KcGBodzlCeZ5UImKbscg==", "dev": true, "peerDependencies": { "@redis/client": "^1.0.0" @@ -2201,17 +2201,17 @@ } }, "node_modules/redis": { - "version": "4.6.5", - "resolved": "https://registry.npmjs.org/redis/-/redis-4.6.5.tgz", - "integrity": "sha512-O0OWA36gDQbswOdUuAhRL6mTZpHFN525HlgZgDaVNgCJIAZR3ya06NTESb0R+TUZ+BFaDpz6NnnVvoMx9meUFg==", + "version": "4.6.13", + "resolved": "https://registry.npmjs.org/redis/-/redis-4.6.13.tgz", + "integrity": "sha512-MHgkS4B+sPjCXpf+HfdetBwbRz6vCtsceTmw1pHNYJAsYxrfpOP6dz+piJWGos8wqG7qb3vj/Rrc5qOlmInUuA==", "dev": true, "dependencies": { "@redis/bloom": "1.2.0", - "@redis/client": "1.5.6", - "@redis/graph": "1.1.0", - "@redis/json": "1.0.4", - "@redis/search": "1.1.2", - "@redis/time-series": "1.0.4" + "@redis/client": "1.5.14", + "@redis/graph": "1.1.1", + "@redis/json": "1.0.6", + "@redis/search": "1.1.6", + "@redis/time-series": "1.0.5" } }, "node_modules/release-zalgo": { @@ -3137,9 +3137,9 @@ "requires": {} }, "@redis/client": { - "version": "1.5.6", - "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.6.tgz", - "integrity": "sha512-dFD1S6je+A47Lj22jN/upVU2fj4huR7S9APd7/ziUXsIXDL+11GPYti4Suv5y8FuXaN+0ZG4JF+y1houEJ7ToA==", + "version": "1.5.14", + "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.14.tgz", + "integrity": "sha512-YGn0GqsRBFUQxklhY7v562VMOP0DcmlrHHs3IV1mFE3cbxe31IITUkqhBcIhVSI/2JqtWAJXg5mjV4aU+zD0HA==", "dev": true, "requires": { "cluster-key-slot": "1.1.2", @@ -3148,30 +3148,30 @@ } }, "@redis/graph": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@redis/graph/-/graph-1.1.0.tgz", - "integrity": "sha512-16yZWngxyXPd+MJxeSr0dqh2AIOi8j9yXKcKCwVaKDbH3HTuETpDVPcLujhFYVPtYrngSco31BUcSa9TH31Gqg==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@redis/graph/-/graph-1.1.1.tgz", + "integrity": "sha512-FEMTcTHZozZciLRl6GiiIB4zGm5z5F3F6a6FZCyrfxdKOhFlGkiAqlexWMBzCi4DcRoyiOsuLfW+cjlGWyExOw==", "dev": true, "requires": {} }, "@redis/json": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.4.tgz", - "integrity": "sha512-LUZE2Gdrhg0Rx7AN+cZkb1e6HjoSKaeeW8rYnt89Tly13GBI5eP4CwDVr+MY8BAYfCg4/N15OUrtLoona9uSgw==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.6.tgz", + "integrity": "sha512-rcZO3bfQbm2zPRpqo82XbW8zg4G/w4W3tI7X8Mqleq9goQjAGLL7q/1n1ZX4dXEAmORVZ4s1+uKLaUOg7LrUhw==", "dev": true, "requires": {} }, "@redis/search": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@redis/search/-/search-1.1.2.tgz", - "integrity": "sha512-/cMfstG/fOh/SsE+4/BQGeuH/JJloeWuH+qJzM8dbxuWvdWibWAOAHHCZTMPhV3xIlH4/cUEIA8OV5QnYpaVoA==", + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@redis/search/-/search-1.1.6.tgz", + "integrity": "sha512-mZXCxbTYKBQ3M2lZnEddwEAks0Kc7nauire8q20oA0oA/LoA+E/b5Y5KZn232ztPb1FkIGqo12vh3Lf+Vw5iTw==", "dev": true, "requires": {} }, "@redis/time-series": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.0.4.tgz", - "integrity": "sha512-ThUIgo2U/g7cCuZavucQTQzA9g9JbDDY2f64u3AbAoz/8vE2lt2U37LamDUVChhaDA3IRT9R6VvJwqnUfTJzng==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.0.5.tgz", + "integrity": "sha512-IFjIgTusQym2B5IZJG3XKr5llka7ey84fw/NOYqESP5WUfQs9zz1ww/9+qoz4ka/S6KcGBodzlCeZ5UImKbscg==", "dev": true, "requires": {} }, @@ -4528,17 +4528,17 @@ } }, "redis": { - "version": "4.6.5", - "resolved": "https://registry.npmjs.org/redis/-/redis-4.6.5.tgz", - "integrity": "sha512-O0OWA36gDQbswOdUuAhRL6mTZpHFN525HlgZgDaVNgCJIAZR3ya06NTESb0R+TUZ+BFaDpz6NnnVvoMx9meUFg==", + "version": "4.6.13", + "resolved": "https://registry.npmjs.org/redis/-/redis-4.6.13.tgz", + "integrity": "sha512-MHgkS4B+sPjCXpf+HfdetBwbRz6vCtsceTmw1pHNYJAsYxrfpOP6dz+piJWGos8wqG7qb3vj/Rrc5qOlmInUuA==", "dev": true, "requires": { "@redis/bloom": "1.2.0", - "@redis/client": "1.5.6", - "@redis/graph": "1.1.0", - "@redis/json": "1.0.4", - "@redis/search": "1.1.2", - "@redis/time-series": "1.0.4" + "@redis/client": "1.5.14", + "@redis/graph": "1.1.1", + "@redis/json": "1.0.6", + "@redis/search": "1.1.6", + "@redis/time-series": "1.0.5" } }, "release-zalgo": { diff --git a/package.json b/package.json index 7bcf204..dbca8b4 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,9 @@ "format:check": "prettier --parser typescript --check lib/**/*.ts test/**/*.ts", "format:fix": "prettier --parser typescript --write lib/**/*.ts test/**/*.ts", "prepack": "npm run compile", - "test": "npm run format:check && npm run compile && nyc mocha --bail --require ts-node/register test/**/*.ts" + "test": "npm run format:check && npm run compile && npm run test:redis-standalone && npm run test:redis-cluster", + "test:redis-standalone": "nyc mocha --require ts-node/register test/**/*.ts", + "test:redis-cluster": "REDIS_CLUSTER=1 mocha --require ts-node/register test/**/*.ts" }, "dependencies": { "@msgpack/msgpack": "~2.8.0", diff --git a/test/util.ts b/test/util.ts index 1cdcef0..82f018a 100644 --- a/test/util.ts +++ b/test/util.ts @@ -1,7 +1,7 @@ import { Server } from "socket.io"; import { Socket as ServerSocket } from "socket.io/dist/socket"; import { io as ioc, Socket as ClientSocket } from "socket.io-client"; -import { createClient } from "redis"; +import { createClient, createCluster } from "redis"; import { createServer } from "http"; import { createAdapter } from "../lib"; import { AddressInfo } from "net"; @@ -31,6 +31,49 @@ interface TestContext { cleanup: () => void; } +if (process.env.REDIS_CLUSTER === "1") { + console.log("[INFO] testing in cluster mode"); +} else { + console.log("[INFO] testing in standalone mode"); +} + +async function initRedisClient() { + if (process.env.REDIS_CLUSTER === "1") { + const redisClient = createCluster({ + rootNodes: [ + { + url: "redis://localhost:7000", + }, + { + url: "redis://localhost:7001", + }, + { + url: "redis://localhost:7002", + }, + { + url: "redis://localhost:7003", + }, + { + url: "redis://localhost:7004", + }, + { + url: "redis://localhost:7005", + }, + ], + }); + + await redisClient.connect(); + + return redisClient; + } else { + const redisClient = createClient(); + + await redisClient.connect(); + + return redisClient; + } +} + export function setup() { const servers = []; const serverSockets = []; @@ -39,9 +82,7 @@ export function setup() { return new Promise(async (resolve) => { for (let i = 1; i <= NODES_COUNT; i++) { - const redisClient = createClient(); - - await redisClient.connect(); + const redisClient = await initRedisClient(); const httpServer = createServer(); const io = new Server(httpServer, {