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 2764cf0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
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()
{
s_previousPoolConfig.Reset();
SnowflakeDbConnectionPool.ClearAllPools();
}

[TearDown]
public void AfterTest()
{
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()
{
previousPoolConfig.Reset();
s_previousPoolConfig.Reset();
SnowflakeDbConnectionPool.SetPooling(true);
SnowflakeDbConnectionPool.ClearAllPools();
}

[TearDown]
public void AfterTest()
{
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()
{
previousPoolConfig.Reset();
s_previousPoolConfigRestorer.Reset();
SnowflakeDbConnectionPool.SetPooling(true);
SnowflakeDbConnectionPool.ClearAllPools();
}

[TearDown]
public void AfterTest()
{
previousPoolConfig.Reset();
s_previousPoolConfigRestorer.Reset();
}

[OneTimeTearDown]
Expand Down

0 comments on commit 2764cf0

Please sign in to comment.