Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node: update transactions binary args returns #2193

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5523,7 +5523,7 @@ export class BaseClient {
* ```
*/
public async xinfoGroups(
key: string,
key: GlideString,
options?: DecoderOption,
): Promise<Record<string, GlideString | number | null>[]> {
return this.createWritePromise<
Expand Down
2 changes: 1 addition & 1 deletion node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2694,7 +2694,7 @@ export function createXInfoStream(
}

/** @internal */
export function createXInfoGroups(key: string): command_request.Command {
export function createXInfoGroups(key: GlideString): command_request.Command {
return createCommand(RequestType.XInfoGroups, [key]);
}

Expand Down
4 changes: 2 additions & 2 deletions node/src/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ export class BaseTransaction<T extends BaseTransaction<T>> {
* Command Response - the number of the removed elements.
* If `key` does not exist, 0 is returned.
*/
public lrem(key: GlideString, count: number, element: string): T {
public lrem(key: GlideString, count: number, element: GlideString): T {
return this.addAndReturn(createLRem(key, count, element));
}

Expand Down Expand Up @@ -2651,7 +2651,7 @@ export class BaseTransaction<T extends BaseTransaction<T>> {
* attributes of a consumer group for the stream at `key`.
* The response comes in format `GlideRecord<GlideString | number | null>[]`, see {@link GlideRecord}.
*/
public xinfoGroups(key: string): T {
public xinfoGroups(key: GlideString): T {
return this.addAndReturn(createXInfoGroups(key));
}

Expand Down
75 changes: 36 additions & 39 deletions node/tests/GlideClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ import {
convertStringArrayToBuffer,
createLongRunningLuaScript,
createLuaLibWithLongRunningFunction,
DumpAndRestureTest,
DumpAndRestoreTest,
encodableTransactionTest,
encodedTransactionTest,
flushAndCloseClient,
generateLuaLibCode,
getClientConfigurationOption,
Expand Down Expand Up @@ -219,42 +218,40 @@ describe("GlideClient", () => {
},
);

it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
`can send transactions_%p`,
async (protocol) => {
client = await GlideClient.createClient(
getClientConfigurationOption(cluster.getAddresses(), protocol),
);
const transaction = new Transaction();
const expectedRes = await transactionTest(
transaction,
cluster.getVersion(),
);
transaction.select(0);
const result = await client.exec(transaction);
expectedRes.push(["select(0)", "OK"]);

validateTransactionResponse(result, expectedRes);
client.close();
},
);

it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
`can get Bytes decoded transactions_%p`,
async (protocol) => {
client = await GlideClient.createClient(
getClientConfigurationOption(cluster.getAddresses(), protocol),
describe.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
"Protocol is RESP2 = %s",
(protocol) => {
describe.each([Decoder.String, Decoder.Bytes])(
"Decoder String = %s",
(decoder) => {
it(
"can send transactions",
async () => {
client = await GlideClient.createClient(
getClientConfigurationOption(
cluster.getAddresses(),
protocol,
),
);
const transaction = new Transaction();
const expectedRes = await transactionTest(
transaction,
cluster.getVersion(),
decoder,
);
transaction.select(0);
const result = await client.exec(transaction, {
decoder: Decoder.String,
});
expectedRes.push(["select(0)", "OK"]);

validateTransactionResponse(result, expectedRes);
client.close();
},
TIMEOUT,
);
},
);
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"]);

validateTransactionResponse(result, expectedRes);
client.close();
},
);

Expand All @@ -265,7 +262,7 @@ describe("GlideClient", () => {
getClientConfigurationOption(cluster.getAddresses(), protocol),
);
const bytesTransaction = new Transaction();
const expectedBytesRes = await DumpAndRestureTest(
const expectedBytesRes = await DumpAndRestoreTest(
bytesTransaction,
Buffer.from("value"),
);
Expand All @@ -278,7 +275,7 @@ describe("GlideClient", () => {
validateTransactionResponse(result, expectedBytesRes);

const stringTransaction = new Transaction();
await DumpAndRestureTest(stringTransaction, "value");
await DumpAndRestoreTest(stringTransaction, "value");
stringTransaction.select(0);

// Since DUMP gets binary results, we cannot use the string decoder here, so we expected to get an error.
Expand Down
68 changes: 45 additions & 23 deletions node/tests/GlideClusterClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
SlotKeyTypes,
SortOrder,
} from "..";
import { ValkeyCluster } from "../../utils/TestUtils.js";
import { ValkeyCluster } from "../../utils/TestUtils";
import { runBaseTests } from "./SharedTests";
import {
checkClusterResponse,
Expand Down Expand Up @@ -291,33 +291,55 @@ describe("GlideClusterClient", () => {
TIMEOUT,
);

it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
`can send transactions_%p`,
async (protocol) => {
client = await GlideClusterClient.createClient(
getClientConfigurationOption(cluster.getAddresses(), protocol),
);
const transaction = new ClusterTransaction();
describe.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
"Protocol is RESP2 = %s",
(protocol) => {
describe.each([Decoder.String, Decoder.Bytes])(
"Decoder String = %s",
(decoder) => {
it(
"can send transactions",
async () => {
client = await GlideClusterClient.createClient(
getClientConfigurationOption(
cluster.getAddresses(),
protocol,
),
);

const expectedRes = await transactionTest(
transaction,
cluster.getVersion(),
);
const transaction = new ClusterTransaction();

if (!cluster.checkIfServerVersionLessThan("7.0.0")) {
transaction.publish("message", "key", true);
expectedRes.push(['publish("message", "key", true)', 0]);
const expectedRes = await transactionTest(
transaction,
cluster.getVersion(),
decoder,
);

transaction.pubsubShardChannels();
expectedRes.push(["pubsubShardChannels()", []]);
transaction.pubsubShardNumSub([]);
expectedRes.push(["pubsubShardNumSub()", []]);
}
if (
!cluster.checkIfServerVersionLessThan("7.0.0")
) {
transaction.publish("message", "key", true);
expectedRes.push([
'publish("message", "key", true)',
0,
]);

const result = await client.exec(transaction);
validateTransactionResponse(result, expectedRes);
transaction.pubsubShardChannels();
expectedRes.push(["pubsubShardChannels()", []]);
transaction.pubsubShardNumSub([]);
expectedRes.push(["pubsubShardNumSub()", []]);
}

const result = await client.exec(transaction, {
decoder: Decoder.String,
});
validateTransactionResponse(result, expectedRes);
},
TIMEOUT,
);
},
);
},
TIMEOUT,
);

it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
Expand Down
2 changes: 1 addition & 1 deletion node/tests/SharedTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10757,7 +10757,7 @@ export function runBaseTests(config: {
).toEqual("OK");

// one empty group exists
expect(await client.xinfoGroups(key)).toEqual(
expect(await client.xinfoGroups(Buffer.from(key))).toEqual(
cluster.checkIfServerVersionLessThan("7.0.0")
? [
{
Expand Down
Loading
Loading