Skip to content

Commit

Permalink
Addressed review comment - added OBJECT FREQ standalone test
Browse files Browse the repository at this point in the history
  • Loading branch information
yipin-chen committed Jun 10, 2024
1 parent b4b9c70 commit 6f7aab0
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion node/tests/RedisClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import { RedisCluster } from "../../utils/TestUtils.js";
import { redis_request } from "../src/ProtobufMessage";
import { runBaseTests } from "./SharedTests";
import {
convertStringArrayToBuffer,
flushAndCloseClient,
getClientConfigurationOption,
parseCommandLineArgs,
parseEndpoints,
transactionTest,
convertStringArrayToBuffer,
} from "./TestUtilities";

/* eslint-disable @typescript-eslint/no-var-requires */
Expand Down Expand Up @@ -180,6 +180,47 @@ describe("RedisClient", () => {
},
);

it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
"object freq transaction test_%p",
async (protocol) => {
const client = await RedisClient.createClient(
getClientConfigurationOption(cluster.getAddresses(), protocol),
);

const key = uuidv4();
const maxmemoryPolicyKey = "maxmemory-policy";
const config = await client.configGet([maxmemoryPolicyKey]);
const maxmemoryPolicy = String(config[maxmemoryPolicyKey]);

try {
const transaction = new Transaction();
transaction.configSet({
[maxmemoryPolicyKey]: "allkeys-lfu",
});
transaction.set(key, "foo");
transaction.object_freq(key);

const response = await client.exec(transaction);
expect(response).not.toBeNull();

if (response != null) {
expect(response.length).toEqual(3);
expect(response[0]).toEqual("OK");
expect(response[1]).toEqual("OK");
expect(response[2]).toBeGreaterThanOrEqual(0);
}
} finally {
expect(
await client.configSet({
[maxmemoryPolicyKey]: maxmemoryPolicy,
}),
).toEqual("OK");
}

client.close();
},
);

runBaseTests<Context>({
init: async (protocol, clientName?) => {
const options = getClientConfigurationOption(
Expand Down

0 comments on commit 6f7aab0

Please sign in to comment.