Skip to content

Commit 3ad7b0b

Browse files
authored
test: Run tests against latest Redis (#1711)
1 parent 6285e80 commit 3ad7b0b

File tree

5 files changed

+16
-59
lines changed

5 files changed

+16
-59
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ jobs:
88
fail-fast: false
99
matrix:
1010
node: [12.x, 14.x, 16.x, 18.x]
11-
redis: ['2', '6']
1211
steps:
1312
- name: Git checkout
1413
uses: actions/checkout@v2
@@ -21,19 +20,19 @@ jobs:
2120
- name: Start Redis
2221
uses: supercharge/[email protected]
2322
with:
24-
redis-version: ${{ matrix.redis }}
23+
redis-version: latest
2524

2625
- run: npm install
2726
- run: npm run lint
2827
- run: npm run build
2928
- run: npm run test:tsd
3029
- run: npm run test:cov || npm run test:cov || npm run test:cov
3130
- name: Coveralls
32-
if: matrix.node == '18.x' && matrix.redis == '6'
31+
if: matrix.node == '18.x'
3332
uses: coverallsapp/github-action@master
3433
with:
3534
github-token: ${{ secrets.GITHUB_TOKEN }}
36-
flag-name: redis-${{matrix.redis}}-node-${{matrix.node}}
35+
flag-name: node-${{matrix.node}}
3736
parallel: true
3837

3938
test-cluster:
@@ -47,8 +46,8 @@ jobs:
4746
needs: test
4847
runs-on: ubuntu-latest
4948
steps:
50-
- name: Coveralls
51-
uses: coverallsapp/github-action@master
52-
with:
53-
github-token: ${{ secrets.GITHUB_TOKEN }}
54-
parallel-finished: true
49+
- name: Coveralls
50+
uses: coverallsapp/github-action@master
51+
with:
52+
github-token: ${{ secrets.GITHUB_TOKEN }}
53+
parallel-finished: true

test/functional/monitor.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Redis from "../../lib/Redis";
22
import { expect, use } from "chai";
33
import * as sinon from "sinon";
4-
import { getRedisVersion, waitForMonitorReady } from "../helpers/util";
4+
import { waitForMonitorReady } from "../helpers/util";
55

66
use(require("chai-as-promised"));
77

@@ -22,7 +22,7 @@ describe("monitor", () => {
2222
done();
2323
});
2424

25-
await waitForMonitorReady(monitor);
25+
await waitForMonitorReady();
2626
redis.get("foo");
2727
});
2828
});
@@ -31,7 +31,7 @@ describe("monitor", () => {
3131
it("should reject processing commands", (done) => {
3232
const redis = new Redis();
3333
redis.monitor(async (err, monitor) => {
34-
await waitForMonitorReady(monitor);
34+
await waitForMonitorReady();
3535
monitor.get("foo", function (err) {
3636
expect(err.message).to.match(/Connection is in monitoring mode/);
3737
redis.disconnect();
@@ -44,7 +44,7 @@ describe("monitor", () => {
4444
it("should report being in 'monitor' mode", (done) => {
4545
const redis = new Redis();
4646
redis.monitor(async (err, monitor) => {
47-
await waitForMonitorReady(monitor);
47+
await waitForMonitorReady();
4848
expect(redis.mode).to.equal("normal");
4949
expect(monitor.mode).to.equal("monitor");
5050
redis.disconnect();
@@ -69,7 +69,7 @@ describe("monitor", () => {
6969
});
7070
monitor.disconnect(true);
7171
monitor.on("ready", async () => {
72-
await waitForMonitorReady(monitor);
72+
await waitForMonitorReady();
7373
redis.set("foo", "bar");
7474
});
7575
});
@@ -91,11 +91,6 @@ describe("monitor", () => {
9191

9292
it("rejects when monitor is disabled", async () => {
9393
const redis = new Redis();
94-
const [major] = await getRedisVersion(redis);
95-
if (major < 6) {
96-
return;
97-
}
98-
9994
await redis.acl("SETUSER", "nomonitor", "reset", "+info", ">123456", "on");
10095

10196
await expect(

test/functional/scan_stream.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { expect } from "chai";
33
import { Readable } from "stream";
44
import * as sinon from "sinon";
55
import MockServer from "../helpers/mock_server";
6-
import { getRedisVersion } from "../helpers/util";
76
import { Cluster } from "../../lib";
87

98
describe("*scanStream", () => {
@@ -51,10 +50,6 @@ describe("*scanStream", () => {
5150
it("should recognize `TYPE`", async () => {
5251
let keys = [];
5352
const redis = new Redis();
54-
const [major] = await getRedisVersion(redis);
55-
if (major < 6) {
56-
return;
57-
}
5853
redis.set("foo1", "bar");
5954
redis.set("foo2", "bar");
6055
redis.set("foo3", "bar");

test/functional/transformer.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Redis from "../../lib/Redis";
2-
import { getRedisVersion } from "../helpers/util";
32
import { expect } from "chai";
43

54
describe("transformer", () => {
@@ -135,11 +134,6 @@ describe("transformer", () => {
135134
describe("hset", () => {
136135
it("should support object", async () => {
137136
const redis = new Redis();
138-
const [major] = await getRedisVersion(redis);
139-
if (major < 4) {
140-
// Skip if redis is too outdated to hset multiple pairs at once.
141-
return;
142-
}
143137
// NOTE: could simplify these tests using await redis.hset instead,
144138
// but not sure if this is deliberately testing the transformers with callbacks
145139
return new Promise((resolve, reject) => {
@@ -157,11 +151,6 @@ describe("transformer", () => {
157151
});
158152
it("should support Map", async () => {
159153
const redis = new Redis();
160-
const [major] = await getRedisVersion(redis);
161-
if (major < 4) {
162-
// Skip if redis is too outdated to hset multiple pairs at once.
163-
return;
164-
}
165154
const map = new Map();
166155
map.set("a", 1);
167156
map.set("b", "e");
@@ -183,12 +172,6 @@ describe("transformer", () => {
183172
});
184173
it("should affect the old way", async () => {
185174
const redis = new Redis();
186-
const [major] = await getRedisVersion(redis);
187-
if (major < 4) {
188-
// Skip if redis is too outdated to hset multiple pairs at once.
189-
return;
190-
}
191-
192175
return new Promise((resolve) => {
193176
redis.hset("foo", "a", 1, "b", "e", function (err, result) {
194177
expect(result).to.eql(2);

test/helpers/util.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
1-
const VERSION_REGEX = /\bredis_version:(\d+)\.(\d+)\.(\d+)/;
2-
3-
export function waitForMonitorReady(redis) {
1+
export function waitForMonitorReady() {
42
// It takes a while for the monitor to be ready.
53
// This is a hack to wait for it because the monitor command
64
// does not have a response
75
return new Promise((resolve) => setTimeout(resolve, 150));
86
}
97

10-
export async function getRedisVersion(
11-
redis: any
12-
): Promise<[number, number, number]> {
13-
const raw = await redis.info("server");
14-
const match = VERSION_REGEX.exec(raw);
15-
if (match) {
16-
return [Number(match[1]), Number(match[2]), Number(match[3])];
17-
}
18-
throw new Error(
19-
"Could not determine redis version from: " + JSON.stringify(raw)
20-
);
21-
}
22-
238
export async function getCommandsFromMonitor(
249
redis: any,
2510
count: number,
2611
exec: Function
2712
): Promise<[any]> {
28-
const arr = [];
13+
const arr: string[] = [];
2914
const monitor = await redis.monitor();
30-
await waitForMonitorReady(monitor);
15+
await waitForMonitorReady();
3116
const promise = new Promise((resolve, reject) => {
3217
setTimeout(reject, 1000, new Error("Monitor timed out"));
3318
monitor.on("monitor", (_, command) => {

0 commit comments

Comments
 (0)