Skip to content

Commit

Permalink
Add option to set client timeout explicitly (#97)
Browse files Browse the repository at this point in the history
* Add option to set client timeout explicitly

* fix

* order _getClientTimeout
  • Loading branch information
amshalev authored Oct 18, 2020
1 parent 5530022 commit e0fd2c7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion azure-kusto-data/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion azure-kusto-data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-kusto-data",
"version": "1.0.1",
"version": "1.0.2",
"description": "Azure Data Explorer Query SDK",
"main": "index.js",
"engines": {
Expand Down
16 changes: 10 additions & 6 deletions azure-kusto-data/source/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,19 @@ module.exports = class KustoClient {
}

_getClientTimeout(endpoint, properties) {
let timeout = null;
if (properties != null) {
var serverTimeout = properties instanceof ClientRequestProperties ? properties.getTimeout() : properties.timeout;
if (serverTimeout != null) {
if (properties != null && properties instanceof ClientRequestProperties) {
const clientTimeout = properties.getClientTimeout();
if(clientTimeout){
return clientTimeout;
}

const serverTimeout = properties.getTimeout();
if(serverTimeout){
return serverTimeout + CLIENT_SERVER_DELTA_IN_MILLISECS;
}
}

timeout = endpoint == this.endpoints.query ? QUERY_TIMEOUT_IN_MILLISECS : COMMAND_TIMEOUT_IN_MILLISECS;
return timeout;
const defaultTimeout = endpoint == this.endpoints.query ? QUERY_TIMEOUT_IN_MILLISECS : COMMAND_TIMEOUT_IN_MILLISECS;
return defaultTimeout;
}
};
8 changes: 8 additions & 0 deletions azure-kusto-data/source/clientRequestProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ module.exports = class ClientRequestProperties {
return this.getOption("servertimeout");
}

setClientTimeout(timeoutMillis) {
this._clientTimeOut = timeoutMillis;
}

getClientTimeout() {
return this._clientTimeOut;
}

clearOptions() {
this._options = {};
}
Expand Down
16 changes: 16 additions & 0 deletions azure-kusto-data/test/clientTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ describe("KustoClient", function () {
await client.execute("Database", "Table | count", clientRequestProps);
});

it("setClientTimout for request", async function () {
let url = "https://cluster.kusto.windows.net";
let client = new KustoClient(url);

let clientRequestProps = new KustoClientRequestProperties();
let timeoutMs = moment.duration(2.51, "minutes").asMilliseconds();
clientRequestProps.setClientTimeout(timeoutMs);
client.aadHelper._getAuthHeader = () => { return "MockToken" };
client._doRequest = (endpoint, headers, payload, timeout, properties) => {
let payloadObj = JSON.parse(payload);
assert.equal(timeout, timeoutMs);
};

await client.execute("Database", "Table | count", clientRequestProps);
});

it("default timeout for query", async function () {
let url = "https://cluster.kusto.windows.net";
let client = new KustoClient(url);
Expand Down

0 comments on commit e0fd2c7

Please sign in to comment.