Skip to content

Commit

Permalink
Node: rework server version check and update tests (valkey-io#1993)
Browse files Browse the repository at this point in the history
* Fix IT.

Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand authored Jul 24, 2024
1 parent 0b7309c commit 9a69ac1
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 100 deletions.
3 changes: 2 additions & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"replace": "^1.2.2",
"ts-jest": "^28.0.8",
"typescript": "^4.9.5",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"semver": "^7.6.3"
},
"author": "Amazon Web Services",
"license": "Apache-2.0",
Expand Down
15 changes: 9 additions & 6 deletions node/tests/RedisClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { RedisCluster } from "../../utils/TestUtils.js";
import { FlushMode } from "../build-ts/src/commands/FlushMode.js";
import { command_request } from "../src/ProtobufMessage";
import { checkIfServerVersionLessThan, runBaseTests } from "./SharedTests";
import { runBaseTests } from "./SharedTests";
import {
checkSimple,
convertStringArrayToBuffer,
Expand Down Expand Up @@ -164,7 +164,10 @@ describe("GlideClient", () => {
getClientConfigurationOption(cluster.getAddresses(), protocol),
);
const transaction = new Transaction();
const expectedRes = await transactionTest(transaction);
const expectedRes = await transactionTest(
transaction,
cluster.getVersion(),
);
transaction.select(0);
const result = await client.exec(transaction);
expectedRes.push("OK");
Expand Down Expand Up @@ -369,7 +372,7 @@ describe("GlideClient", () => {
it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
"function load test_%p",
async (protocol) => {
if (await checkIfServerVersionLessThan("7.0.0")) return;
if (cluster.checkIfServerVersionLessThan("7.0.0")) return;

const client = await GlideClient.createClient(
getClientConfigurationOption(cluster.getAddresses(), protocol),
Expand Down Expand Up @@ -469,7 +472,7 @@ describe("GlideClient", () => {
it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
"function flush test_%p",
async (protocol) => {
if (await checkIfServerVersionLessThan("7.0.0")) return;
if (cluster.checkIfServerVersionLessThan("7.0.0")) return;

const client = await GlideClient.createClient(
getClientConfigurationOption(cluster.getAddresses(), protocol),
Expand Down Expand Up @@ -528,7 +531,7 @@ describe("GlideClient", () => {
it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
"function delete test_%p",
async (protocol) => {
if (await checkIfServerVersionLessThan("7.0.0")) return;
if (cluster.checkIfServerVersionLessThan("7.0.0")) return;

const client = await GlideClient.createClient(
getClientConfigurationOption(cluster.getAddresses(), protocol),
Expand Down Expand Up @@ -667,7 +670,7 @@ describe("GlideClient", () => {
options.clientName = clientName;
testsFailed += 1;
client = await GlideClient.createClient(options);
return { client, context: { client } };
return { client, context: { client }, cluster };
},
close: (context: Context, testSucceeded: boolean) => {
if (testSucceeded) {
Expand Down
39 changes: 22 additions & 17 deletions node/tests/RedisClusterClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
expect,
it,
} from "@jest/globals";
import { gte } from "semver";
import { v4 as uuidv4 } from "uuid";

import {
ClusterClientConfiguration,
ClusterTransaction,
Expand All @@ -23,7 +23,7 @@ import {
} from "..";
import { RedisCluster } from "../../utils/TestUtils.js";
import { FlushMode } from "../build-ts/src/commands/FlushMode";
import { checkIfServerVersionLessThan, runBaseTests } from "./SharedTests";
import { runBaseTests } from "./SharedTests";
import {
checkClusterResponse,
checkSimple,
Expand Down Expand Up @@ -83,6 +83,7 @@ describe("GlideClusterClient", () => {
client,
},
client,
cluster,
};
},
close: (context: Context, testSucceeded: boolean) => {
Expand Down Expand Up @@ -241,7 +242,10 @@ describe("GlideClusterClient", () => {
getClientConfigurationOption(cluster.getAddresses(), protocol),
);
const transaction = new ClusterTransaction();
const expectedRes = await transactionTest(transaction);
const expectedRes = await transactionTest(
transaction,
cluster.getVersion(),
);
const result = await client.exec(transaction);
expect(intoString(result)).toEqual(intoString(expectedRes));
},
Expand Down Expand Up @@ -298,33 +302,34 @@ describe("GlideClusterClient", () => {
getClientConfigurationOption(cluster.getAddresses(), protocol),
);

const versionLessThan7 =
await checkIfServerVersionLessThan("7.0.0");

const promises: Promise<unknown>[] = [
client.blpop(["abc", "zxy", "lkn"], 0.1),
client.rename("abc", "zxy"),
client.brpop(["abc", "zxy", "lkn"], 0.1),
client.smove("abc", "zxy", "value"),
client.renamenx("abc", "zxy"),
client.sinter(["abc", "zxy", "lkn"]),
client.sintercard(["abc", "zxy", "lkn"]),
client.sinterstore("abc", ["zxy", "lkn"]),
client.zinterstore("abc", ["zxy", "lkn"]),
client.zdiff(["abc", "zxy", "lkn"]),
client.zdiffWithScores(["abc", "zxy", "lkn"]),
client.zdiffstore("abc", ["zxy", "lkn"]),
client.sunionstore("abc", ["zxy", "lkn"]),
client.sunion(["abc", "zxy", "lkn"]),
client.pfcount(["abc", "zxy", "lkn"]),
client.sdiff(["abc", "zxy", "lkn"]),
client.sdiffstore("abc", ["zxy", "lkn"]),
// TODO all rest multi-key commands except ones tested below
];

if (!versionLessThan7) {
promises.push(client.zintercard(["abc", "zxy", "lkn"]));
if (gte(cluster.getVersion(), "6.2.0")) {
promises.push(
client.zdiff(["abc", "zxy", "lkn"]),
client.zdiffWithScores(["abc", "zxy", "lkn"]),
client.zdiffstore("abc", ["zxy", "lkn"]),
);
}

if (gte(cluster.getVersion(), "7.0.0")) {
promises.push(
client.sintercard(["abc", "zxy", "lkn"]),
client.zintercard(["abc", "zxy", "lkn"]),
client.zmpop(["abc", "zxy", "lkn"], ScoreFilter.MAX),
);
}
Expand Down Expand Up @@ -566,7 +571,7 @@ describe("GlideClusterClient", () => {
it(
"function load",
async () => {
if (await checkIfServerVersionLessThan("7.0.0"))
if (cluster.checkIfServerVersionLessThan("7.0.0"))
return;

const client =
Expand Down Expand Up @@ -701,7 +706,7 @@ describe("GlideClusterClient", () => {
it(
"function flush",
async () => {
if (await checkIfServerVersionLessThan("7.0.0"))
if (cluster.checkIfServerVersionLessThan("7.0.0"))
return;

const client =
Expand Down Expand Up @@ -810,7 +815,7 @@ describe("GlideClusterClient", () => {
it(
"function delete",
async () => {
if (await checkIfServerVersionLessThan("7.0.0"))
if (cluster.checkIfServerVersionLessThan("7.0.0"))
return;

const client =
Expand Down Expand Up @@ -897,7 +902,7 @@ describe("GlideClusterClient", () => {
[true, ProtocolVersion.RESP3],
[false, ProtocolVersion.RESP3],
])("simple pubsub test", async (sharded, protocol) => {
if (sharded && (await checkIfServerVersionLessThan("7.2.0"))) {
if (sharded && cluster.checkIfServerVersionLessThan("7.2.0")) {
return;
}

Expand Down
Loading

0 comments on commit 9a69ac1

Please sign in to comment.