From e18d8ebc2aba25acd5607d1c856cd45c86ae569b Mon Sep 17 00:00:00 2001 From: Krzysztof Nozderko Date: Fri, 2 Aug 2024 17:02:27 +0000 Subject: [PATCH] fix failing tests --- .../IntegrationTests/SFConnectionIT.cs | 4 +++- Snowflake.Data/Core/HttpUtil.cs | 17 ++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs index ea48aab1f..019d4311e 100644 --- a/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs @@ -2284,7 +2284,9 @@ public void TestOpenAsyncThrowExceptionWhenConnectToUnreachableHost() var thrown = Assert.Throws(() => connection.OpenAsync().Wait()); // assert - SnowflakeDbExceptionAssert.HasErrorCode(thrown.InnerException, SFError.INTERNAL_ERROR); + Assert.IsTrue(thrown.InnerException is TaskCanceledException || thrown.InnerException is SnowflakeDbException); + if (thrown.InnerException is SnowflakeDbException) + SnowflakeDbExceptionAssert.HasErrorCode(thrown.InnerException, SFError.INTERNAL_ERROR); Assert.AreEqual(ConnectionState.Closed, connection.State); } } diff --git a/Snowflake.Data/Core/HttpUtil.cs b/Snowflake.Data/Core/HttpUtil.cs index 5e401783f..531e76fd7 100755 --- a/Snowflake.Data/Core/HttpUtil.cs +++ b/Snowflake.Data/Core/HttpUtil.cs @@ -13,7 +13,6 @@ using System.Web; using System.Security.Authentication; using System.Linq; -using Snowflake.Data.Client; using Snowflake.Data.Core.Authenticator; namespace Snowflake.Data.Core @@ -88,7 +87,7 @@ public sealed class HttpUtil private HttpUtil() { - // This value is used by AWS SDK and can cause deadlock, + // This value is used by AWS SDK and can cause deadlock, // so we need to increase the default value of 2 // See: https://github.com/aws/aws-sdk-net/issues/152 ServicePointManager.DefaultConnectionLimit = 50; @@ -182,15 +181,15 @@ internal HttpMessageHandler SetupCustomHttpHandler(HttpClientConfig config) { // Get the original entry entry = bypassList[i].Trim(); - // . -> [.] because . means any char + // . -> [.] because . means any char entry = entry.Replace(".", "[.]"); // * -> .* because * is a quantifier and need a char or group to apply to entry = entry.Replace("*", ".*"); - + entry = entry.StartsWith("^") ? entry : $"^{entry}"; - + entry = entry.EndsWith("$") ? entry : $"{entry}$"; - + // Replace with the valid entry syntax bypassList[i] = entry; @@ -374,6 +373,7 @@ protected override async Task SendAsync(HttpRequestMessage while (true) { + try { childCts = null; @@ -384,7 +384,7 @@ protected override async Task SendAsync(HttpRequestMessage if (httpTimeout.Ticks == 0) childCts.Cancel(); else - childCts.CancelAfter(httpTimeout); + childCts.CancelAfter(httpTimeout); } response = await base.SendAsync(requestMessage, childCts == null ? cancellationToken : childCts.Token).ConfigureAwait(false); @@ -454,8 +454,7 @@ protected override async Task SendAsync(HttpRequestMessage { return response; } - throw new SnowflakeDbException(new OperationCanceledException($"http request failed and max retry {maxRetryCount} reached"), - SFError.INTERNAL_ERROR, "Unable to connect"); + throw new OperationCanceledException($"http request failed and max retry {maxRetryCount} reached"); } // Disposing of the response if not null now that we don't need it anymore