diff --git a/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs index 232de654b..0801d7ba2 100644 --- a/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs @@ -584,50 +584,6 @@ public void TestEnableLoginRetryOn404() } } - - [Test] - public void TestNonRetryableHttpExceptionThrowsError() - { - var handler = new Mock(); - handler.Protected() - .Setup>( - "SendAsync", - ItExpr.Is(req => req.RequestUri.ToString().Contains("https://authenticationexceptiontest.com/")), - ItExpr.IsAny()) - .ThrowsAsync(new HttpRequestException("", new AuthenticationException())); - - var httpClient = HttpUtil.Instance.GetHttpClient( - new HttpClientConfig(false, "fakeHost", "fakePort", "user", "password", "fakeProxyList", false, false, 7), - handler.Object); - - var mockRestRequester = new MockInfiniteTimeout(httpClient); - - using (var conn = new MockSnowflakeDbConnection(mockRestRequester)) - { - string invalidConnectionString = "host=authenticationexceptiontest.com;" - + "account=account;user=user;password=password;"; - conn.ConnectionString = invalidConnectionString; - - Assert.AreEqual(conn.State, ConnectionState.Closed); - try - { - conn.Open(); - Assert.Fail(); - } - catch (AggregateException e) - { - Assert.IsInstanceOf(e.InnerException); - Assert.IsInstanceOf(e.InnerException.InnerException); - } - catch (Exception unexpected) - { - Assert.Fail($"Unexpected {unexpected.GetType()} exception occurred"); - } - - Assert.AreEqual(ConnectionState.Closed, conn.State); - } - } - [Test] public void TestValidateDefaultParameters() { diff --git a/Snowflake.Data.Tests/Mock/MockInfiniteTimeout.cs b/Snowflake.Data.Tests/Mock/MockInfiniteTimeout.cs deleted file mode 100644 index 4ab7661cd..000000000 --- a/Snowflake.Data.Tests/Mock/MockInfiniteTimeout.cs +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2024 Snowflake Computing Inc. All rights reserved. - */ - -using Snowflake.Data.Core; -using System; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Snowflake.Data.Tests.Mock -{ - - class MockInfiniteTimeout : RestRequester, IMockRestRequester - { - HttpClient mockHttpClient; - - public MockInfiniteTimeout(HttpClient mockHttpClient = null) : base(null) - { - this.mockHttpClient = mockHttpClient; - } - - public void setHttpClient(HttpClient httpClient) - { - if (mockHttpClient != null) - { - base._HttpClient = mockHttpClient; - } - else - { - base._HttpClient = httpClient; - } - } - - protected override async Task SendAsync(HttpRequestMessage message, - TimeSpan restTimeout, - CancellationToken externalCancellationToken, - string sid = "") - { - // Disable warning as this is the way to be compliant with netstandard2.0 - // API reference: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestmessage?view=netstandard-2.0 -#pragma warning disable CS0618 // Type or member is obsolete - message.Properties[BaseRestRequest.HTTP_REQUEST_TIMEOUT_KEY] = Timeout.InfiniteTimeSpan; -#pragma warning restore CS0618 // Type or member is obsolete - return await (base.SendAsync(message, restTimeout, externalCancellationToken).ConfigureAwait(false)); - } - } -} - diff --git a/Snowflake.Data.Tests/UnitTests/HttpUtilTest.cs b/Snowflake.Data.Tests/UnitTests/HttpUtilTest.cs index 668db5f91..879fb26d2 100644 --- a/Snowflake.Data.Tests/UnitTests/HttpUtilTest.cs +++ b/Snowflake.Data.Tests/UnitTests/HttpUtilTest.cs @@ -9,13 +9,55 @@ namespace Snowflake.Data.Tests.UnitTests using NUnit.Framework; using Snowflake.Data.Core; using RichardSzalay.MockHttp; + using System.Threading; using System.Threading.Tasks; using System.Net; using System; + using System.Security.Authentication; + using Moq; + using Moq.Protected; [TestFixture] class HttpUtilTest { + [Test] + public async Task TestNonRetryableHttpExceptionThrowsError() + { + var request = new HttpRequestMessage(HttpMethod.Post, new Uri("https://authenticationexceptiontest.com/")); + // Disable warning as this is the way to be compliant with netstandard2.0 + // API reference: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestmessage?view=netstandard-2.0 +#pragma warning disable CS0618 // Type or member is obsolete + request.Properties[BaseRestRequest.HTTP_REQUEST_TIMEOUT_KEY] = Timeout.InfiniteTimeSpan; + request.Properties[BaseRestRequest.REST_REQUEST_TIMEOUT_KEY] = Timeout.InfiniteTimeSpan; +#pragma warning restore CS0618 // Type or member is obsolete + + var handler = new Mock(); + handler.Protected() + .Setup>( + "SendAsync", + ItExpr.Is(req => req.RequestUri.ToString().Contains("https://authenticationexceptiontest.com/")), + ItExpr.IsAny()) + .ThrowsAsync(new HttpRequestException("", new AuthenticationException())); + + var httpClient = HttpUtil.Instance.GetHttpClient( + new HttpClientConfig(false, "fakeHost", "fakePort", "user", "password", "fakeProxyList", false, false, 7), + handler.Object); + + try + { + await httpClient.SendAsync(request, CancellationToken.None).ConfigureAwait(false); + Assert.Fail(); + } + catch (HttpRequestException e) + { + Assert.IsInstanceOf(e.InnerException); + } + catch (Exception unexpected) + { + Assert.Fail($"Unexpected {unexpected.GetType()} exception occurred"); + } + } + [Test] // Parameters: status code, force retry on 404, expected retryable value [TestCase(HttpStatusCode.OK, false, false)]