Skip to content

Commit

Permalink
SNOW-834781: Refactor/add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lf committed Nov 9, 2024
1 parent 650bb43 commit f0484f6
Show file tree
Hide file tree
Showing 22 changed files with 321 additions and 1,177 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using Snowflake.Data.Client;
Expand All @@ -17,7 +18,7 @@ namespace Snowflake.Data.Tests.IntegrationTests
public class ConnectionMultiplePoolsAsyncIT: SFBaseTestAsync
{
private readonly PoolConfig _previousPoolConfig = new PoolConfig();
private readonly SFLogger logger = SFLoggerFactory.GetLogger<SFConnectionIT>();
private readonly ILogger logger = SFLoggerFactory.GetLogger<SFConnectionIT>();

[SetUp]
public new void BeforeTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Snowflake.Data.Core.Session;
using Snowflake.Data.Log;
using Snowflake.Data.Tests.Util;
using Microsoft.Extensions.Logging;

namespace Snowflake.Data.Tests.IntegrationTests
{
Expand All @@ -20,7 +21,7 @@ namespace Snowflake.Data.Tests.IntegrationTests
class ConnectionPoolCommonIT : SFBaseTest
{
private readonly ConnectionPoolType _connectionPoolTypeUnderTest;
private static readonly SFLogger s_logger = SFLoggerFactory.GetLogger<ConnectionPoolManager>();
private static readonly ILogger s_logger = SFLoggerFactory.GetLogger<ConnectionPoolManager>();
private readonly PoolConfig _previousPoolConfig;

public ConnectionPoolCommonIT(ConnectionPoolType connectionPoolTypeUnderTest)
Expand All @@ -38,8 +39,8 @@ public ConnectionPoolCommonIT(ConnectionPoolType connectionPoolTypeUnderTest)
{
SnowflakeDbConnectionPool.SetPooling(true);
}
s_logger.Debug($"---------------- BeforeTest ---------------------");
s_logger.Debug($"Testing Pool Type: {SnowflakeDbConnectionPool.GetConnectionPoolVersion()}");
s_logger.LogDebug($"---------------- BeforeTest ---------------------");
s_logger.LogDebug($"Testing Pool Type: {SnowflakeDbConnectionPool.GetConnectionPoolVersion()}");
}

[TearDown]
Expand Down
124 changes: 0 additions & 124 deletions Snowflake.Data.Tests/IntegrationTests/EasyLoggingIT.cs

This file was deleted.

11 changes: 6 additions & 5 deletions Snowflake.Data.Tests/IntegrationTests/SFBindTestIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
using System.Globalization;
using System.Collections.Generic;
using Snowflake.Data.Tests.Util;
using Microsoft.Extensions.Logging;

namespace Snowflake.Data.Tests.IntegrationTests
{

[TestFixture]
class SFBindTestIT : SFBaseTest
{
private static readonly SFLogger s_logger = SFLoggerFactory.GetLogger<SFBindTestIT>();
private static readonly ILogger s_logger = SFLoggerFactory.GetLogger<SFBindTestIT>();

[Test]
public void TestArrayBind()
Expand Down Expand Up @@ -896,7 +897,7 @@ public void TestDateTimeBinding(ResultFormat resultFormat, SFTableType tableType
var bindingThreshold = 65280; // when exceeded enforces bindings via file on stage
var smallBatchRowCount = 2;
var bigBatchRowCount = bindingThreshold / 2;
s_logger.Info(testCase);
s_logger.LogInformation(testCase);

using (IDbConnection conn = new SnowflakeDbConnection(ConnectionString))
{
Expand Down Expand Up @@ -925,7 +926,7 @@ public void TestDateTimeBinding(ResultFormat resultFormat, SFTableType tableType
var row = 0;
using (var select = conn.CreateCommand($"select id, ts from {TableName} order by id"))
{
s_logger.Debug(select.CommandText);
s_logger.LogDebug(select.CommandText);
var reader = select.ExecuteReader();
while (reader.Read())
{
Expand Down Expand Up @@ -956,7 +957,7 @@ private void InsertSingleRecord(IDbConnection conn, string sqlInsert, DbType bin
}

// Act
s_logger.Info(sqlInsert);
s_logger.LogInformation(sqlInsert);
var rowsAffected = insert.ExecuteNonQuery();

// Assert
Expand All @@ -982,7 +983,7 @@ private void InsertMultipleRecords(IDbConnection conn, string sqlInsert, DbType
}

// Act
s_logger.Debug(sqlInsert);
s_logger.LogDebug(sqlInsert);
var rowsAffected = insert.ExecuteNonQuery();

// Assert
Expand Down
19 changes: 10 additions & 9 deletions Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ namespace Snowflake.Data.Tests.IntegrationTests
using Snowflake.Data.Tests.Mock;
using System.Runtime.InteropServices;
using System.Net.Http;
using Microsoft.Extensions.Logging;

[TestFixture]
class SFConnectionIT : SFBaseTest
{
private static readonly SFLogger s_logger = SFLoggerFactory.GetLogger<SFConnectionIT>();
private static readonly ILogger s_logger = SFLoggerFactory.GetLogger<SFConnectionIT>();

[Test]
public void TestBasicConnection()
Expand Down Expand Up @@ -83,14 +84,14 @@ public void TestApplicationName()
try
{
conn.Open();
s_logger.Debug("{appName}");
s_logger.LogDebug("{appName}");
Assert.Fail();

}
catch (SnowflakeDbException e)
{
// Expected
s_logger.Debug("Failed opening connection ", e);
s_logger.LogDebug("Failed opening connection ", e);
AssertIsConnectionFailure(e);
}

Expand Down Expand Up @@ -127,7 +128,7 @@ public void TestIncorrectUserOrPasswordBasicConnection()
catch (SnowflakeDbException e)
{
// Expected
s_logger.Debug("Failed opening connection ", e);
s_logger.LogDebug("Failed opening connection ", e);
AssertIsConnectionFailure(e);
}

Expand All @@ -142,7 +143,7 @@ public void TestConnectionIsNotMarkedAsOpenWhenWasNotCorrectlyOpenedBefore(bool
{
for (int i = 0; i < 2; ++i)
{
s_logger.Debug($"Running try #{i}");
s_logger.LogDebug($"Running try #{i}");
SnowflakeDbConnection snowflakeConnection = null;
try
{
Expand All @@ -168,7 +169,7 @@ public void TestConnectionIsNotMarkedAsOpenWhenWasNotCorrectlyOpenedWithUsingCla
{
for (int i = 0; i < 2; ++i)
{
s_logger.Debug($"Running try #{i}");
s_logger.LogDebug($"Running try #{i}");
SnowflakeDbConnection snowflakeConnection = null;
try
{
Expand Down Expand Up @@ -1559,7 +1560,7 @@ public void TestInvalidProxySettingFromConnectionString()
catch (SnowflakeDbException e)
{
// Expected
s_logger.Debug("Failed opening connection ", e);
s_logger.LogDebug("Failed opening connection ", e);
Assert.AreEqual(270001, e.ErrorCode); //Internal error
AssertIsConnectionFailure(e);
}
Expand Down Expand Up @@ -1868,7 +1869,7 @@ public void TestKeepAlive()
[TestFixture]
class SFConnectionITAsync : SFBaseTestAsync
{
private static SFLogger logger = SFLoggerFactory.GetLogger<SFConnectionITAsync>();
private static ILogger logger = SFLoggerFactory.GetLogger<SFConnectionITAsync>();


[Test]
Expand Down Expand Up @@ -1898,7 +1899,7 @@ public void TestCancelLoginBeforeTimeout()

// Cancel the connection because it will never succeed since there is no
// connection_timeout defined
logger.Debug("connectionCancelToken.Cancel ");
logger.LogDebug("connectionCancelToken.Cancel ");
connectionCancelToken.Cancel();

try
Expand Down
11 changes: 6 additions & 5 deletions Snowflake.Data.Tests/Mock/MockSnowflakeDbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
using System.Data;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace Snowflake.Data.Tests.Mock
{
class MockSnowflakeDbConnection : SnowflakeDbConnection
{
private SFLogger logger = SFLoggerFactory.GetLogger<MockSnowflakeDbConnection>();
private ILogger logger = SFLoggerFactory.GetLogger<MockSnowflakeDbConnection>();

private IMockRestRequester _restRequester;

Expand All @@ -31,7 +32,7 @@ public MockSnowflakeDbConnection()

public override void Open()
{
logger.Debug("Open Connection.");
logger.LogDebug("Open Connection.");
SetMockSession();
try
{
Expand All @@ -41,7 +42,7 @@ public override void Open()
{
// Otherwise when Dispose() is called, the close request would timeout.
_connectionState = System.Data.ConnectionState.Closed;
logger.Error("Unable to connect", e);
logger.LogError("Unable to connect", e);
throw;
}
OnSessionEstablished();
Expand All @@ -61,14 +62,14 @@ public override Task OpenAsync(CancellationToken cancellationToken)
// Exception from SfSession.OpenAsync
Exception sfSessionEx = previousTask.Exception;
_connectionState = ConnectionState.Closed;
logger.Error("Unable to connect", sfSessionEx);
logger.LogError("Unable to connect", sfSessionEx);
throw //sfSessionEx.InnerException;
new SnowflakeDbException(sfSessionEx, SFError.INTERNAL_ERROR, "Unable to connect");
}
if (previousTask.IsCanceled)
{
_connectionState = ConnectionState.Closed;
logger.Debug("Connection canceled");
logger.LogDebug("Connection canceled");
}
else
{
Expand Down
Loading

0 comments on commit f0484f6

Please sign in to comment.