From 38662546d527a8198b87873b8f38fcc640d3e0a5 Mon Sep 17 00:00:00 2001 From: AsafMah Date: Mon, 25 Apr 2022 07:20:35 +0300 Subject: [PATCH] Fixed ToJSON accidental mutation (#191) --- .../source/clientRequestProperties.ts | 4 ++-- packages/azure-kusto-data/test/clientTest.ts | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/azure-kusto-data/source/clientRequestProperties.ts b/packages/azure-kusto-data/source/clientRequestProperties.ts index 5a7fd90..6a433dc 100644 --- a/packages/azure-kusto-data/source/clientRequestProperties.ts +++ b/packages/azure-kusto-data/source/clientRequestProperties.ts @@ -78,14 +78,14 @@ export class ClientRequestProperties { } = {}; if (Object.keys(this._options).length !== 0) { - json.Options = this._options; + json.Options = { ...this._options }; if (json.Options.servertimeout) { json.Options.servertimeout = this._msToTimespan(json.Options.servertimeout as number); } } if (Object.keys(this._parameters).length !== 0) { - json.Parameters = this._parameters; + json.Parameters = { ...this._parameters }; } return Object.keys(json).length !== 0 ? json : null; diff --git a/packages/azure-kusto-data/test/clientTest.ts b/packages/azure-kusto-data/test/clientTest.ts index 28c743e..dbeb530 100644 --- a/packages/azure-kusto-data/test/clientTest.ts +++ b/packages/azure-kusto-data/test/clientTest.ts @@ -53,6 +53,29 @@ describe("KustoClient", () => { }); }); + describe("timeout", () => { + it("ClientRequestProperties.ToJSON doesn't affect results", () => { + const url = "https://cluster.kusto.windows.net"; + const client = new KustoClient(url); + const clientRequestProps = new ClientRequestProperties(); + const timeout = moment.duration(3.53, "minutes"); + const clientServerDelta = moment.duration(0.5, "minutes"); + const totalTimeout = timeout.clone().add(clientServerDelta); + + clientRequestProps.setTimeout(timeout.asMilliseconds()); + assert.strictEqual(client._getClientTimeout(ExecutionType.Query, clientRequestProps), totalTimeout.asMilliseconds()); + + const json = clientRequestProps.toJSON(); + assert.strictEqual(json?.Options?.servertimeout, "00:03:31.8"); + + client._getClientTimeout(ExecutionType.Query, clientRequestProps); + assert.strictEqual(client._getClientTimeout(ExecutionType.Query, clientRequestProps), totalTimeout.asMilliseconds()); + + const json2 = clientRequestProps.toJSON(); + assert.strictEqual(json2?.Options?.servertimeout, "00:03:31.8"); + }); + }); + describe("#_parseResponse()", () => { it("valid v1", () => { const url = "https://cluster.kusto.windows.net";