Skip to content

Commit 55ce829

Browse files
test: run tests against a Redis cluster
1 parent d6737ef commit 55ce829

File tree

8 files changed

+687
-490
lines changed

8 files changed

+687
-490
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ jobs:
3030
ports:
3131
- 6379:6379
3232

33+
redis-cluster:
34+
image: grokzen/redis-cluster:7.0.10
35+
options: >-
36+
--health-cmd "redis-cli -p 7005 ping"
37+
--health-interval 10s
38+
--health-timeout 5s
39+
--health-retries 5
40+
ports:
41+
- "7000-7005:7000-7005"
42+
3343
steps:
3444
- name: Checkout repository
3545
uses: actions/checkout@v3

docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ services:
33
image: redis:7
44
ports:
55
- "6379:6379"
6+
7+
redis-cluster:
8+
image: grokzen/redis-cluster:7.0.10
9+
ports:
10+
- "7000-7005:7000-7005"

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
"main": "./dist/index.js",
1414
"types": "./dist/index.d.ts",
1515
"scripts": {
16-
"test": "npm run format:check && tsc && npm run test:default && npm run test:redis-v4-specific-channel && npm run test:redis-v3 && npm run test:ioredis && npm run test:sharded",
17-
"test:default": "nyc mocha --bail --require ts-node/register test/*.ts",
18-
"test:redis-v4-specific-channel": "SPECIFIC_CHANNEL=1 npm run test:default",
19-
"test:redis-v3": "REDIS_CLIENT=redis-v3 npm run test:default",
20-
"test:ioredis": "REDIS_CLIENT=ioredis npm run test:default",
21-
"test:sharded": "SHARDED=1 npm run test:default",
16+
"test": "npm run format:check && tsc && nyc mocha --bail --require ts-node/register test/test-runner.ts",
2217
"format:check": "prettier --parser typescript --check 'lib/**/*.ts' 'test/**/*.ts'",
2318
"format:fix": "prettier --parser typescript --write 'lib/**/*.ts' 'test/**/*.ts'",
2419
"prepack": "tsc"

test/custom-parser.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,37 @@ import type { Server } from "socket.io";
22
import type { Socket as ClientSocket } from "socket.io-client";
33
import { setup, times } from "./util";
44
import expect = require("expect.js");
5+
import { createClient } from "redis";
6+
import { createAdapter } from "../lib";
57

68
describe("custom parser", () => {
79
let servers: Server[];
810
let clientSockets: ClientSocket[];
911
let cleanup: () => void;
1012

1113
beforeEach(async () => {
12-
const testContext = await setup({
13-
parser: {
14-
decode(msg) {
15-
return JSON.parse(msg);
16-
},
17-
encode(msg) {
18-
return JSON.stringify(msg);
14+
const testContext = await setup(async () => {
15+
const pubClient = createClient();
16+
const subClient = pubClient.duplicate();
17+
18+
await Promise.all([pubClient.connect(), subClient.connect()]);
19+
20+
return [
21+
createAdapter(pubClient, subClient, {
22+
parser: {
23+
decode(msg) {
24+
return JSON.parse(msg);
25+
},
26+
encode(msg) {
27+
return JSON.stringify(msg);
28+
},
29+
},
30+
}),
31+
() => {
32+
pubClient.disconnect();
33+
subClient.disconnect();
1934
},
20-
},
35+
];
2136
});
2237
servers = testContext.servers;
2338
clientSockets = testContext.clientSockets;

0 commit comments

Comments
 (0)