Skip to content

Commit

Permalink
edited typos and fix some logics
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jy committed Oct 24, 2023
1 parent 3512bbc commit 1b4e12c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/connection/connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ function createParameters()
},
{
name: PARAM_RETRY_SF_MAX_SLEEP_TIME,
defaultValue: 16,
defaultValue: 108,
validate: isNonNegativeNumber
}
];
Expand Down
2 changes: 1 addition & 1 deletion lib/services/sf.js
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ StateConnecting.prototype.continue = function ()
totalTimeout < maxLoginTimeout)
{
numRetries++;
const jitter = Util.jitteredSleepTime(numRetries, sleep, cap, totalTimeout, maxLoginTimeout);
const jitter = Util.jitteredSleepTime(numRetries, sleep, totalTimeout, maxLoginTimeout);
sleep = jitter.sleep;
totalTimeout = jitter.totalTimeout;
setTimeout(sendRequest, sleep * 1000);
Expand Down
18 changes: 6 additions & 12 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,16 +429,10 @@ exports.nextSleepTime = function (
* @param {Number} maxSleepTime
* @returns {JSON} return next sleep Time and totalTime.
*/
exports.jitteredSleepTime = function (numofRetries, currentSleepTime, maxSleepTime, totalTimeout = 0, maxLoginTimeout = 300) {
const nextSleepTime = Math.min(maxSleepTime, 2 ** numofRetries);
let sleep = nextSleepTime + getJitter(currentSleepTime);
if (totalTimeout + sleep > maxLoginTimeout) {
sleep = maxLoginTimeout - totalTimeout;
totalTimeout = maxLoginTimeout;
}
else {
totalTimeout += sleep
}
exports.jitteredSleepTime = function (numofRetries, currentSleepTime, totalTimeout, maxLoginTimeout) {
const nextSleepTime = Math.min(maxLoginTimeout - totalTimeout, 4 * numofRetries);
const sleep = nextSleepTime + getJitter(currentSleepTime);
totalTimeout += sleep

return {sleep, totalTimeout}
}
Expand Down Expand Up @@ -479,8 +473,8 @@ exports.chooseRandom = chooseRandom;
*/
function getJitter (curWaitTime) {
const multiplicationFactor = chooseRandom(1, -1);
const jitterAmmount = 0.5 * curWaitTime * multiplicationFactor;
return jitterAmmount;
const jitterAmount = 0.5 * curWaitTime * multiplicationFactor;
return jitterAmount;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions test/unit/util_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,14 @@ describe('Util', function ()
},
];

const maxSleepTime = 16;
const maxLoginTimeout = 300;
let currentSleepTime = 1;
let currentSleepTime = 4;
let retryCount = 1;
let totalTimeout = 1;
for (const response of errorCodes) {
assert.strictEqual(Util.isRetryableHttpError(response,true), true);

const result = Util.jitteredSleepTime(retryCount, currentSleepTime, maxSleepTime, totalTimeout, maxLoginTimeout);
const result = Util.jitteredSleepTime(retryCount, currentSleepTime, totalTimeout, maxLoginTimeout);
const jitter = currentSleepTime / 2
const nextSleep = 2 ** retryCount;
currentSleepTime = result.sleep;
Expand All @@ -624,6 +623,7 @@ describe('Util', function ()
assert.ok(currentSleepTime <= nextSleep + jitter || currentSleepTime >= nextSleep - jitter)
retryCount++;
}

assert.strictEqual(retryCount, 8);
assert.ok(totalTimeout <= maxLoginTimeout);
});
Expand Down

0 comments on commit 1b4e12c

Please sign in to comment.