Skip to content

Commit

Permalink
SNOW-878067: Check maxHttpRetries before creating the HttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lf committed Feb 28, 2024
1 parent 4988ba1 commit 0fbe932
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public void TestLoginWithMaxRetryReached()
{
using (IDbConnection conn = new MockSnowflakeDbConnection())
{
string maxRetryConnStr = ConnectionString + "maxHttpRetries=5";
string maxRetryConnStr = ConnectionString + "maxHttpRetries=5"; // Will be set to the minimum allowed value of 7

conn.ConnectionString = maxRetryConnStr;

Expand All @@ -436,9 +436,9 @@ public void TestLoginWithMaxRetryReached()
stopwatch.Stop();

// retry 5 times with starting backoff of 1 second
// but should not delay more than the max possible seconds after 5 retries
// and should not take less time than the minimum possible seconds after 5 retries
Assert.Less(stopwatch.ElapsedMilliseconds, 79 * 1000);
// but should not delay more than the max possible seconds after 7 retries
// and should not take less time than the minimum possible seconds after 7 retries
Assert.Less(stopwatch.ElapsedMilliseconds, 164 * 1000);
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 1 * 1000);
}
}
Expand Down
16 changes: 8 additions & 8 deletions Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void TestExecuteAsyncWithMaxRetryReached()

using (DbConnection conn = new MockSnowflakeDbConnection(mockRestRequester))
{
string maxRetryConnStr = ConnectionString + "maxHttpRetries=5";
string maxRetryConnStr = ConnectionString + "maxHttpRetries=5"; // Will be set to the minimum allowed value of 7

conn.ConnectionString = maxRetryConnStr;
conn.Open();
Expand All @@ -169,10 +169,10 @@ public void TestExecuteAsyncWithMaxRetryReached()
}
stopwatch.Stop();

// retry 5 times with backoff 1, 2, 4, 8, 16 seconds
// retry 7 times with backoff 1, 2, 4, 8, 16, 16, 16 seconds
// but should not delay more than another 16 seconds
Assert.Less(stopwatch.ElapsedMilliseconds, 51 * 1000);
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 30 * 1000);
Assert.Less(stopwatch.ElapsedMilliseconds, 83 * 1000);
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 54 * 1000);
}
}
}
Expand Down Expand Up @@ -639,7 +639,7 @@ public void TestExecuteWithMaxRetryReached()

using (IDbConnection conn = new MockSnowflakeDbConnection(mockRestRequester))
{
string maxRetryConnStr = ConnectionString + "maxHttpRetries=5";
string maxRetryConnStr = ConnectionString + "maxHttpRetries=5"; // Will be set to the minimum allowed value of 7

conn.ConnectionString = maxRetryConnStr;
conn.Open();
Expand All @@ -660,10 +660,10 @@ public void TestExecuteWithMaxRetryReached()
}
stopwatch.Stop();

// retry 5 times with backoff 1, 2, 4, 8, 16 seconds
// retry 7 times with backoff 1, 2, 4, 8, 16, 16, 16 seconds
// but should not delay more than another 16 seconds
Assert.Less(stopwatch.ElapsedMilliseconds, 51 * 1000);
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 30 * 1000);
Assert.Less(stopwatch.ElapsedMilliseconds, 83 * 1000);
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 54 * 1000);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data/Core/Session/SFSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ internal SFSession(
try
{
var extractedProperties = propertiesExtractor.ExtractProperties(properties);
extractedProperties.CheckPropertiesAreValid();
var httpClientConfig = extractedProperties.BuildHttpClientConfig();
ParameterMap = extractedProperties.ToParameterMap();
InsecureMode = extractedProperties.insecureMode;
_HttpClient = HttpUtil.Instance.GetHttpClient(httpClientConfig);
restRequester = new RestRequester(_HttpClient);
extractedProperties.CheckPropertiesAreValid();
connectionTimeout = extractedProperties.TimeoutDuration();
properties.TryGetValue(SFSessionProperty.CLIENT_CONFIG_FILE, out var easyLoggingConfigFile);
_easyLoggingStarter.Init(easyLoggingConfigFile);
Expand Down

0 comments on commit 0fbe932

Please sign in to comment.