diff --git a/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs index fe9419939..a01439125 100644 --- a/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs @@ -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; @@ -435,11 +435,11 @@ 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); - Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 1 * 1000); + // retry 7 times with starting backoff of 1 second + // 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.9 * 1000); } } diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs index 6e92c0aac..cdc6baeb1 100755 --- a/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs @@ -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(); @@ -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, 62 * 1000); } } } @@ -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(); @@ -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, 62 * 1000); } } diff --git a/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs b/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs index 72421f588..f1d0ba5f1 100644 --- a/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs +++ b/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs @@ -282,7 +282,7 @@ public static IEnumerable PropertiesProvider() { validateDefaultParameters = true, clientSessionKeepAlive = false, - timeoutInSec = 0, + timeoutInSec = SFSessionHttpClientProperties.s_retryTimeoutDefault, insecureMode = false, disableRetry = false, forceRetryOn404 = false, diff --git a/Snowflake.Data/Core/Session/SFSession.cs b/Snowflake.Data/Core/Session/SFSession.cs index e39370f19..ae8e19286 100755 --- a/Snowflake.Data/Core/Session/SFSession.cs +++ b/Snowflake.Data/Core/Session/SFSession.cs @@ -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); diff --git a/Snowflake.Data/Core/Session/SFSessionHttpClientProperties.cs b/Snowflake.Data/Core/Session/SFSessionHttpClientProperties.cs index f129de25a..41f75f5b3 100644 --- a/Snowflake.Data/Core/Session/SFSessionHttpClientProperties.cs +++ b/Snowflake.Data/Core/Session/SFSessionHttpClientProperties.cs @@ -49,7 +49,8 @@ internal void CheckPropertiesAreValid() } // Use the shorter timeout between CONNECTION_TIMEOUT and RETRY_TIMEOUT - if (retryTimeout < timeoutInSec) + // but only if retry timeout is not set to infinite + if (retryTimeout < timeoutInSec && retryTimeout > 0) { timeoutInSec = retryTimeout; }