Skip to content

Commit

Permalink
SNOW-902611 teardown of pool settings changes in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mhofman committed Oct 9, 2023
1 parent 1616fed commit 2b09dea
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Snowflake.Data.Tests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Copyright (c) 2012-2017 Snowflake Computing Inc. All rights reserved.
</layout>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] [%-5level] [%ClassName:%line] - %message%newline" />
<conversionPattern value="%date [%thread] [%-5level] [%classname:%line] - %message%newline" />
</layout>
</appender>
</appender>
Expand All @@ -31,7 +31,7 @@ Copyright (c) 2012-2017 Snowflake Computing Inc. All rights reserved.
<appender-ref ref="RollingFileAppender" />
</root>
<root>
<level value="WARN" />
<level value="ALL" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
Expand Down
26 changes: 26 additions & 0 deletions Snowflake.Data.Tests/IntegrationTests/PoolConfigRestorer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Snowflake.Data.Client;

namespace Snowflake.Data.Tests.IntegrationTests
{
class PoolConfigRestorer {
private readonly bool _pooling;
private readonly long _timeout;
private readonly int _maxPoolSize;

public PoolConfigRestorer()
{
_maxPoolSize = SnowflakeDbConnectionPool.GetMaxPoolSize();
_timeout = SnowflakeDbConnectionPool.GetTimeout();
_pooling = SnowflakeDbConnectionPool.GetPooling();
}

public void Reset()
{
SnowflakeDbConnectionPool.SetMaxPoolSize(_maxPoolSize);
SnowflakeDbConnectionPool.SetTimeout(_timeout);
SnowflakeDbConnectionPool.SetPooling(_pooling);
}
}


}
16 changes: 13 additions & 3 deletions Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@ namespace Snowflake.Data.Tests.IntegrationTests
class SFConnectionIT : SFBaseTest
{
private static readonly SFLogger s_logger = SFLoggerFactory.GetLogger<SFConnectionIT>();
private static readonly PoolConfigRestorer s_previousPoolConfig = new PoolConfigRestorer();

[SetUp]
public void BeforeTest()

Check warning on line 28 in Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

'SFConnectionIT.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 28 in Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

'SFConnectionIT.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 28 in Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

'SFConnectionIT.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 28 in Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

'SFConnectionIT.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 28 in Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

'SFConnectionIT.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 28 in Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

'SFConnectionIT.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.
{
s_previousPoolConfig.Reset();
SnowflakeDbConnectionPool.ClearAllPools();
}

[TearDown]
public void AfterTest()

Check warning on line 35 in Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

'SFConnectionIT.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 35 in Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

'SFConnectionIT.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 35 in Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

'SFConnectionIT.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 35 in Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

'SFConnectionIT.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 35 in Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

'SFConnectionIT.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 35 in Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

'SFConnectionIT.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.
{
s_previousPoolConfig.Reset();
}
[Test]
public void TestBasicConnection()
{
using (IDbConnection conn = new SnowflakeDbConnection())
{
bool pooling = SnowflakeDbConnectionPool.GetPooling();
SnowflakeDbConnectionPool.SetPooling(false);
conn.ConnectionString = ConnectionString;
conn.Open();
Expand All @@ -47,7 +59,6 @@ public void TestBasicConnection()

conn.Close();
Assert.AreEqual(ConnectionState.Closed, conn.State);
SnowflakeDbConnectionPool.SetPooling(pooling);
}
}

Expand Down Expand Up @@ -1755,7 +1766,6 @@ public void TestAsyncLoginTimeout()
[Test, NonParallelizable]
public void TestAsyncDefaultLoginTimeout()
{
SnowflakeDbConnectionPool.SetPooling(false);
using (var conn = new MockSnowflakeDbConnection())
{
// unlimited retry count to trigger the timeout
Expand Down
33 changes: 6 additions & 27 deletions Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,24 @@ namespace Snowflake.Data.Tests.IntegrationTests
using Snowflake.Data.Tests.Mock;
using System.Data.Common;
using Moq;

class PoolConfig {
private readonly bool _pooling;
private readonly long _timeout;
private readonly int _maxPoolSize;

public PoolConfig()
{
_maxPoolSize = SnowflakeDbConnectionPool.GetMaxPoolSize();
_timeout = SnowflakeDbConnectionPool.GetTimeout();
_pooling = SnowflakeDbConnectionPool.GetPooling();
}

public void Reset()
{
SnowflakeDbConnectionPool.SetMaxPoolSize(_maxPoolSize);
SnowflakeDbConnectionPool.SetTimeout(_timeout);
SnowflakeDbConnectionPool.SetPooling(_pooling);
}
}

[TestFixture, NonParallelizable]
class SFConnectionPoolT : SFBaseTest
{
private static SFLogger logger = SFLoggerFactory.GetLogger<SFConnectionPoolT>();
private static readonly PoolConfig previousPoolConfig = new PoolConfig();
private static readonly PoolConfigRestorer s_previousPoolConfig = new PoolConfigRestorer();

[SetUp]
public void BeforeTest()

Check warning on line 25 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

'SFConnectionPoolT.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 25 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

'SFConnectionPoolT.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 25 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

'SFConnectionPoolT.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 25 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

'SFConnectionPoolT.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 25 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

'SFConnectionPoolT.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 25 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

'SFConnectionPoolT.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.
{
previousPoolConfig.Reset();
s_previousPoolConfig.Reset();
SnowflakeDbConnectionPool.SetPooling(true);
SnowflakeDbConnectionPool.ClearAllPools();
}

[TearDown]
public void AfterTest()

Check warning on line 33 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

'SFConnectionPoolT.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 33 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

'SFConnectionPoolT.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 33 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

'SFConnectionPoolT.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 33 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

'SFConnectionPoolT.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 33 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

'SFConnectionPoolT.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 33 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

'SFConnectionPoolT.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.
{
previousPoolConfig.Reset();
s_previousPoolConfig.Reset();
}

[OneTimeTearDown]
Expand Down Expand Up @@ -435,20 +414,20 @@ public void TestConnectionPoolTurnOff()
class SFConnectionPoolITAsync : SFBaseTestAsync
{
private static SFLogger logger = SFLoggerFactory.GetLogger<SFConnectionPoolITAsync>();
private static readonly PoolConfig previousPoolConfig = new PoolConfig();
private static readonly PoolConfigRestorer s_previousPoolConfigRestorer = new PoolConfigRestorer();

[SetUp]
public void BeforeTest()

Check warning on line 420 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

'SFConnectionPoolITAsync.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 420 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

'SFConnectionPoolITAsync.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 420 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

'SFConnectionPoolITAsync.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 420 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

'SFConnectionPoolITAsync.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 420 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

'SFConnectionPoolITAsync.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.

Check warning on line 420 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

'SFConnectionPoolITAsync.BeforeTest()' hides inherited member 'SFBaseTestAsync.BeforeTest()'. Use the new keyword if hiding was intended.
{
previousPoolConfig.Reset();
s_previousPoolConfigRestorer.Reset();
SnowflakeDbConnectionPool.SetPooling(true);
SnowflakeDbConnectionPool.ClearAllPools();
}

[TearDown]
public void AfterTest()

Check warning on line 428 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

'SFConnectionPoolITAsync.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 428 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

'SFConnectionPoolITAsync.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 428 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

'SFConnectionPoolITAsync.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 428 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

'SFConnectionPoolITAsync.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 428 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

'SFConnectionPoolITAsync.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.

Check warning on line 428 in Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

'SFConnectionPoolITAsync.AfterTest()' hides inherited member 'SFBaseTestAsync.AfterTest()'. Use the new keyword if hiding was intended.
{
previousPoolConfig.Reset();
s_previousPoolConfigRestorer.Reset();
}

[OneTimeTearDown]
Expand Down

0 comments on commit 2b09dea

Please sign in to comment.