Skip to content

Commit

Permalink
test: run tests against a Redis cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed May 12, 2023
1 parent d6737ef commit 55ce829
Show file tree
Hide file tree
Showing 8 changed files with 687 additions and 490 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ jobs:
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
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ services:
image: redis:7
ports:
- "6379:6379"

redis-cluster:
image: grokzen/redis-cluster:7.0.10
ports:
- "7000-7005:7000-7005"
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"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",
"test:default": "nyc mocha --bail --require ts-node/register test/*.ts",
"test:redis-v4-specific-channel": "SPECIFIC_CHANNEL=1 npm run test:default",
"test:redis-v3": "REDIS_CLIENT=redis-v3 npm run test:default",
"test:ioredis": "REDIS_CLIENT=ioredis npm run test:default",
"test:sharded": "SHARDED=1 npm run test:default",
"test": "npm run format:check && tsc && nyc mocha --bail --require ts-node/register test/test-runner.ts",
"format:check": "prettier --parser typescript --check 'lib/**/*.ts' 'test/**/*.ts'",
"format:fix": "prettier --parser typescript --write 'lib/**/*.ts' 'test/**/*.ts'",
"prepack": "tsc"
Expand Down
31 changes: 23 additions & 8 deletions test/custom-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,37 @@ import type { Server } from "socket.io";
import type { Socket as ClientSocket } from "socket.io-client";
import { setup, times } from "./util";
import expect = require("expect.js");
import { createClient } from "redis";
import { createAdapter } from "../lib";

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

beforeEach(async () => {
const testContext = await setup({
parser: {
decode(msg) {
return JSON.parse(msg);
},
encode(msg) {
return JSON.stringify(msg);
const testContext = await setup(async () => {
const pubClient = createClient();
const subClient = pubClient.duplicate();

await Promise.all([pubClient.connect(), subClient.connect()]);

return [
createAdapter(pubClient, subClient, {
parser: {
decode(msg) {
return JSON.parse(msg);
},
encode(msg) {
return JSON.stringify(msg);
},
},
}),
() => {
pubClient.disconnect();
subClient.disconnect();
},
},
];
});
servers = testContext.servers;
clientSockets = testContext.clientSockets;
Expand Down
Loading

0 comments on commit 55ce829

Please sign in to comment.