Skip to content

Commit

Permalink
Added unit testings and created a function for the retry parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jy committed Sep 21, 2023
1 parent d82c852 commit e55b7e1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/connection/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -1570,12 +1570,14 @@ function sendSfRequest(statementContext, options, appendQueryParamOnRetry)
// retry, update the url
if ((numRetries > 0) && appendQueryParamOnRetry)
{
let retryUrl;
retryUrl = Util.url.appendParam(urlOrig, 'retryCount', numRetries);
if(connectionConfig.getIncludeRetryContext){
retryUrl = Util.url.appendParam(retryUrl, 'retryReason', lastStatusCodeForRetry);
const retryOption = {
url: urlOrig,
retryCount: numRetries,
retryReason: lastStatusCodeForRetry,
includeRetryContext: connectionConfig.getIncludeRetryContext()
}
options.url = retryUrl;

options.url = Util.url.appendRetryParam(retryOption);
}

sf.request(options);
Expand Down
8 changes: 8 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ exports.url =
}

return url;
},

appendRetryParam: function (option) {
let retryUrl = this.appendParam(option.url, 'retryCount', option.retryCount);
if (option.includeRetryContext) {
retryUrl = this.appendParam(retryUrl, 'retryReason', option.retryReason);
}
return retryUrl;
}
};

Expand Down
31 changes: 31 additions & 0 deletions test/unit/util_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,37 @@ describe('Util', function ()
}
});

it('Util.url.appendRetryParam()', function () {
let url;
const testCases =
[
{
option: {
url: 'http://www.something.snowflakecomputing.com',
retryCount: 3,
retryReason: 429,
includeRetryContext: true,
},
result: 'http://www.something.snowflakecomputing.com?retryCount=3&retryReason=429'
},
{
option: {
url: 'http://www.something.snowflakecomputing.com',
retryCount: 3,
retryReason: 429,
includeRetryContext: false,
},
result: 'http://www.something.snowflakecomputing.com?retryCount=3'
}
];

for (let i = 0; i < testCases.length; i++) {
testCase = testCases[i];
url = Util.url.appendRetryParam(testCase.option);
assert.strictEqual(url, testCase.result);
}
})

it('Util.apply()', function ()
{
assert.strictEqual(Util.apply(null, null), null);
Expand Down

0 comments on commit e55b7e1

Please sign in to comment.