From 6f7aab0585343fcb211422a3f20ede7e568c2673 Mon Sep 17 00:00:00 2001 From: Yi-Pin Chen Date: Mon, 10 Jun 2024 15:38:23 -0700 Subject: [PATCH] Addressed review comment - added OBJECT FREQ standalone test --- node/tests/RedisClient.test.ts | 43 +++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/node/tests/RedisClient.test.ts b/node/tests/RedisClient.test.ts index 5d62f0af8f..ff3f58a274 100644 --- a/node/tests/RedisClient.test.ts +++ b/node/tests/RedisClient.test.ts @@ -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 */ @@ -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({ init: async (protocol, clientName?) => { const options = getClientConfigurationOption(