diff --git a/node/tests/GlideClient.test.ts b/node/tests/GlideClient.test.ts index e0ac65e169..20af49ca21 100644 --- a/node/tests/GlideClient.test.ts +++ b/node/tests/GlideClient.test.ts @@ -34,9 +34,7 @@ import { convertStringArrayToBuffer, createLongRunningLuaScript, createLuaLibWithLongRunningFunction, - DumpAndRestureTest, encodableTransactionTest, - encodedTransactionTest, flushAndCloseClient, generateLuaLibCode, getClientConfigurationOption, @@ -240,53 +238,32 @@ describe("GlideClient", () => { ); it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])( - `can get Bytes decoded transactions_%p`, + `dump and restore transactions_%p`, async (protocol) => { client = await GlideClient.createClient( getClientConfigurationOption(cluster.getAddresses(), protocol), ); - const transaction = new Transaction(); - const expectedRes = await encodedTransactionTest(transaction); - transaction.select(0); - const result = await client.exec(transaction, { - decoder: Decoder.Bytes, - }); - expectedRes.push(["select(0)", "OK"]); + const key1 = uuidv4(); + const key2 = uuidv4(); + const value = uuidv4(); - validateTransactionResponse(result, expectedRes); - client.close(); - }, - ); + const transaction1 = new Transaction().set(key1, value).dump(key1); - it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])( - `dump and restore transactions_%p`, - async (protocol) => { - client = await GlideClient.createClient( - getClientConfigurationOption(cluster.getAddresses(), protocol), - ); - const bytesTransaction = new Transaction(); - const expectedBytesRes = await DumpAndRestureTest( - bytesTransaction, - Buffer.from("value"), - ); - bytesTransaction.select(0); - const result = await client.exec(bytesTransaction, { + // Since DUMP gets binary results, we cannot use the string decoder here, so we expected to get an error. + await expect( + client.exec(transaction1, { decoder: Decoder.String }), + ).rejects.toThrow("invalid utf-8 sequence of"); + + const result = await client.exec(transaction1, { decoder: Decoder.Bytes, }); - expectedBytesRes.push(["select(0)", "OK"]); - - validateTransactionResponse(result, expectedBytesRes); + expect(result?.[0]).toEqual("OK"); + const dump = result?.[1] as Buffer; - const stringTransaction = new Transaction(); - await DumpAndRestureTest(stringTransaction, "value"); - stringTransaction.select(0); + const transaction2 = new Transaction().restore(key2, 0, dump); + expect(await client.exec(transaction2)).toEqual(["OK"]); - // Since DUMP gets binary results, we cannot use the string decoder here, so we expected to get an error. - await expect( - client.exec(stringTransaction, { decoder: Decoder.String }), - ).rejects.toThrowError( - "invalid utf-8 sequence of 1 bytes from index 9", - ); + expect(value).toEqual(await client.get(key2)); client.close(); }, diff --git a/node/tests/GlideClusterClient.test.ts b/node/tests/GlideClusterClient.test.ts index 6f29f99884..aae9434018 100644 --- a/node/tests/GlideClusterClient.test.ts +++ b/node/tests/GlideClusterClient.test.ts @@ -246,7 +246,7 @@ describe("GlideClusterClient", () => { expect(await client.set(key, value)).toEqual("OK"); // Since DUMP gets binary results, we cannot use the default decoder (string) here, so we expected to get an error. await expect(client.customCommand(["DUMP", key])).rejects.toThrow( - "invalid utf-8 sequence of 1 bytes from index 9", + "invalid utf-8 sequence of", ); const dumpResult = await client.customCommand(["DUMP", key], { @@ -391,10 +391,6 @@ describe("GlideClusterClient", () => { client.sdiffstore("abc", ["zxy", "lkn"]), client.sortStore("abc", "zyx"), client.sortStore("abc", "zyx", { isAlpha: true }), - client.lmpop(["abc", "def"], ListDirection.LEFT, { count: 1 }), - client.blmpop(["abc", "def"], ListDirection.RIGHT, 0.1, { - count: 1, - }), client.bzpopmax(["abc", "def"], 0.5), client.bzpopmin(["abc", "def"], 0.5), client.xread({ abc: "0-0", zxy: "0-0", lkn: "0-0" }), @@ -437,6 +433,12 @@ describe("GlideClusterClient", () => { client.lcs("abc", "xyz"), client.lcsLen("abc", "xyz"), client.lcsIdx("abc", "xyz"), + client.lmpop(["abc", "def"], ListDirection.LEFT, { + count: 1, + }), + client.blmpop(["abc", "def"], ListDirection.RIGHT, 0.1, { + count: 1, + }), ); } diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 7b1af14ed1..7a78c5c058 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -6433,7 +6433,7 @@ export function runBaseTests(config: { expect( await client.bzpopmax( [key3], - cluster.checkIfServerVersionLessThan("6.0.0") + cluster.checkIfServerVersionLessThan("7.0.0") ? 1.0 : 0.001, ), @@ -6483,7 +6483,7 @@ export function runBaseTests(config: { expect( await client.bzpopmin( [key3], - cluster.checkIfServerVersionLessThan("6.0.0") + cluster.checkIfServerVersionLessThan("7.0.0") ? 1.0 : 0.001, ), @@ -7526,7 +7526,7 @@ export function runBaseTests(config: { it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])( `xinfo stream xinfosream test_%p`, async (protocol) => { - await runTest(async (client: BaseClient) => { + await runTest(async (client: BaseClient, cluster) => { const key = uuidv4(); const groupName = `group-${uuidv4()}`; const consumerName = `consumer-${uuidv4()}`; @@ -7642,9 +7642,12 @@ export function runBaseTests(config: { // ] // } expect(fullResult.length).toEqual(2); - expect(fullResult["recorded-first-entry-id"]).toEqual( - streamId1_0, - ); + + if (!cluster.checkIfServerVersionLessThan("7.0.0")) { + expect(fullResult["recorded-first-entry-id"]).toEqual( + streamId1_0, + ); + } // Only the first entry will be returned since we passed count: 1 expect(fullResult.entries).toEqual([expectedFirstEntry]); @@ -10660,7 +10663,7 @@ export function runBaseTests(config: { expect(result[0].pending).toEqual(1); expect(result[0].idle).toBeGreaterThan(0); - if (cluster.checkIfServerVersionLessThan("7.2.0")) { + if (!cluster.checkIfServerVersionLessThan("7.2.0")) { expect(result[0].inactive).toBeGreaterThan(0); } diff --git a/node/tests/TestUtilities.ts b/node/tests/TestUtilities.ts index 0b64b31a04..eeec096b15 100644 --- a/node/tests/TestUtilities.ts +++ b/node/tests/TestUtilities.ts @@ -600,90 +600,6 @@ export async function encodableTransactionTest( return responseData; } -/** - * Populates a transaction with commands to test the decoded response. - * @param baseTransaction - A transaction. - * @returns Array of tuples, where first element is a test name/description, second - expected return value. - */ -export async function encodedTransactionTest( - baseTransaction: Transaction | ClusterTransaction, -): Promise<[string, GlideReturnType][]> { - const key1 = "{key}" + uuidv4(); // string - const key2 = "{key}" + uuidv4(); // string - const key = "dumpKey"; - const dumpResult = Buffer.from([ - 0, 5, 118, 97, 108, 117, 101, 11, 0, 232, 41, 124, 75, 60, 53, 114, 231, - ]); - const value = "value"; - const valueEncoded = Buffer.from(value); - // array of tuples - first element is test name/description, second - expected return value - const responseData: [string, GlideReturnType][] = []; - - baseTransaction.set(key1, value); - responseData.push(["set(key1, value)", "OK"]); - baseTransaction.set(key2, value); - responseData.push(["set(key2, value)", "OK"]); - baseTransaction.get(key1); - responseData.push(["get(key1)", valueEncoded]); - baseTransaction.get(key2); - responseData.push(["get(key2)", valueEncoded]); - - baseTransaction.set(key, value); - responseData.push(["set(key, value)", "OK"]); - baseTransaction.customCommand(["DUMP", key]); - responseData.push(['customCommand(["DUMP", key])', dumpResult]); - baseTransaction.del([key]); - responseData.push(["del(key)", 1]); - baseTransaction.get(key); - responseData.push(["get(key)", null]); - baseTransaction.customCommand(["RESTORE", key, "0", dumpResult]); - responseData.push([ - 'customCommand(["RESTORE", key, "0", dumpResult])', - "OK", - ]); - baseTransaction.get(key); - responseData.push(["get(key)", valueEncoded]); - - return responseData; -} - -/** Populates a transaction with dump and restore commands - * - * @param baseTransaction - A transaction - * @param valueResponse - Represents the encoded response of "value" to compare - * @returns Array of tuples, where first element is a test name/description, second - expected return value. - */ -export async function DumpAndRestureTest( - baseTransaction: Transaction, - valueResponse: GlideString, -): Promise<[string, GlideReturnType][]> { - const key = "dumpKey"; - const dumpResult = Buffer.from([ - 0, 5, 118, 97, 108, 117, 101, 11, 0, 232, 41, 124, 75, 60, 53, 114, 231, - ]); - const value = "value"; - // array of tuples - first element is test name/description, second - expected return value - const responseData: [string, GlideReturnType][] = []; - - baseTransaction.set(key, value); - responseData.push(["set(key, value)", "OK"]); - baseTransaction.customCommand(["DUMP", key]); - responseData.push(['customCommand(["DUMP", key])', dumpResult]); - baseTransaction.del([key]); - responseData.push(["del(key)", 1]); - baseTransaction.get(key); - responseData.push(["get(key)", null]); - baseTransaction.customCommand(["RESTORE", key, "0", dumpResult]); - responseData.push([ - 'customCommand(["RESTORE", key, "0", dumpResult])', - "OK", - ]); - baseTransaction.get(key); - responseData.push(["get(key)", valueResponse]); - - return responseData; -} - /** * Populates a transaction with commands to test. * @param baseTransaction - A transaction. @@ -874,20 +790,20 @@ export async function transactionTest( ]); responseData.push(["lpush(key5, [1, 2, 3, 4])", 4]); - if (gte("7.0.0", version)) { + if (gte(version, "7.0.0")) { baseTransaction.lpush(key24, [field + "1", field + "2"]); responseData.push(["lpush(key22, [1, 2])", 2]); baseTransaction.lmpop([key24], ListDirection.LEFT); responseData.push([ "lmpop([key22], ListDirection.LEFT)", - { [key24]: [field + "2"] }, + convertRecordToGlideRecord({ [key24]: [field + "2"] }), ]); baseTransaction.lpush(key24, [field + "2"]); responseData.push(["lpush(key22, [2])", 2]); baseTransaction.blmpop([key24], ListDirection.LEFT, 0.1, 1); responseData.push([ "blmpop([key22], ListDirection.LEFT, 0.1, 1)", - { [key24]: [field + "2"] }, + convertRecordToGlideRecord({ [key24]: [field + "2"] }), ]); } @@ -1758,7 +1674,7 @@ export async function transactionTest( } baseTransaction.wait(1, 200); - responseData.push(["wait(1, 200)", 1]); + responseData.push(["wait(1, 200)", gte(version, "7.0.0") ? 1 : 0]); return responseData; }