From 1b4e12c9800551fc5b0dcc887a1c43f2733fc333 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-jy Date: Mon, 23 Oct 2023 18:29:00 -0700 Subject: [PATCH] edited typos and fix some logics --- lib/connection/connection_config.js | 2 +- lib/services/sf.js | 2 +- lib/util.js | 18 ++++++------------ test/unit/util_test.js | 6 +++--- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/connection/connection_config.js b/lib/connection/connection_config.js index 3adb3eaa2..d8280c007 100644 --- a/lib/connection/connection_config.js +++ b/lib/connection/connection_config.js @@ -982,7 +982,7 @@ function createParameters() }, { name: PARAM_RETRY_SF_MAX_SLEEP_TIME, - defaultValue: 16, + defaultValue: 108, validate: isNonNegativeNumber } ]; diff --git a/lib/services/sf.js b/lib/services/sf.js index ec3ee4564..6334b86b6 100644 --- a/lib/services/sf.js +++ b/lib/services/sf.js @@ -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); diff --git a/lib/util.js b/lib/util.js index 284310f17..c0ec546e3 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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} } @@ -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; } /** diff --git a/test/unit/util_test.js b/test/unit/util_test.js index eace486bd..7ef205aaa 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -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; @@ -624,6 +623,7 @@ describe('Util', function () assert.ok(currentSleepTime <= nextSleep + jitter || currentSleepTime >= nextSleep - jitter) retryCount++; } + assert.strictEqual(retryCount, 8); assert.ok(totalTimeout <= maxLoginTimeout); });