Skip to content

Commit

Permalink
chore: scanStream TYPE test requires redis 6 (#1469)
Browse files Browse the repository at this point in the history
See https://redis.io/commands/scan

When this test fails in local development
it stops the rest of the tests from running.
Some OSes have redis 5 or older installed.
  • Loading branch information
TysonAndre committed Nov 28, 2021
1 parent b817747 commit d1ead14
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
17 changes: 12 additions & 5 deletions test/functional/scan_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from "chai";
import { Readable } from "stream";
import * as sinon from "sinon";
import MockServer from "../helpers/mock_server";
import { getRedisVersion } from "../helpers/util";
import { Cluster } from "../../lib";

describe("*scanStream", function () {
Expand Down Expand Up @@ -77,9 +78,13 @@ describe("*scanStream", function () {
);
});

it("should recognize `TYPE`", function (done) {
it("should recognize `TYPE`", async function () {
let keys = [];
const redis = new Redis();
const [major] = await getRedisVersion(redis);
if (major < 6) {
return;
}
redis.set("foo1", "bar");
redis.set("foo2", "bar");
redis.set("foo3", "bar");
Expand All @@ -92,10 +97,12 @@ describe("*scanStream", function () {
stream.on("data", function (data) {
keys = keys.concat(data);
});
stream.on("end", function () {
expect(keys.sort()).to.eql(["loo1", "loo2", "loo3"]);
redis.disconnect();
done();
return new Promise((resolve) => {
stream.on("end", function () {
expect(keys.sort()).to.eql(["loo1", "loo2", "loo3"]);
redis.disconnect();
resolve();
});
});
});

Expand Down
12 changes: 12 additions & 0 deletions test/helpers/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const VERSION_REGEX = /\bredis_version:(\d+)\.(\d+)\.(\d+)/;

export async function getRedisVersion(redis: Redis) {
const raw = await redis.info("server");
const match = VERSION_REGEX.exec(raw);
if (match) {
return [match[1], match[2], match[3]];
}
throw new Error(
"Could not determine redis version from: " + JSON.stringify(raw)
);
}

0 comments on commit d1ead14

Please sign in to comment.