Skip to content

Commit

Permalink
SNOW-1629635 allow forcing old connection pool version
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mhofman committed Sep 16, 2024
1 parent 4afccf2 commit 587cd50
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ConnectionMultiplePoolsAsyncIT: SFBaseTestAsync
[SetUp]
public new void BeforeTest()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SnowflakeDbConnectionPool.ClearAllPools();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ConnectionMultiplePoolsIT: SFBaseTest
[SetUp]
public new void BeforeTest()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SnowflakeDbConnectionPool.ClearAllPools();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ConnectionPoolChangedSessionIT : SFBaseTest
public static void BeforeAllTests()
{
s_previousPoolConfigRestorer = new PoolConfig();
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
}

[SetUp]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ConnectionPoolCommonIT(ConnectionPoolType connectionPoolTypeUnderTest)
[SetUp]
public new void BeforeTest()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(_connectionPoolTypeUnderTest);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(_connectionPoolTypeUnderTest);
SnowflakeDbConnectionPool.ClearAllPools();
if (_connectionPoolTypeUnderTest == ConnectionPoolType.SingleConnectionCache)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ConnectionSinglePoolCacheAsyncIT: SFBaseTestAsync
[SetUp]
public new void BeforeTest()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
SnowflakeDbConnectionPool.ClearAllPools();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ConnectionSinglePoolCacheIT: SFBaseTest
[SetUp]
public new void BeforeTest()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
SnowflakeDbConnectionPool.ClearAllPools();
SnowflakeDbConnectionPool.SetPooling(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ConnectionCacheManagerTest
public static void BeforeAllTests()
{
s_poolConfig = new PoolConfig();
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
SessionPool.SessionFactory = new MockSessionFactory();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ConnectionPoolManagerTest
public static void BeforeAllTests()
{
s_poolConfig = new PoolConfig();
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SessionPool.SessionFactory = new MockSessionFactory();
}

Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data.Tests/Util/PoolConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public PoolConfig()

public void Reset()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(_connectionPoolType);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(_connectionPoolType);
if (_connectionPoolType == ConnectionPoolType.MultipleConnectionPool)
return; // for multiple connection pool setting parameters for all the pools doesn't work by design
SnowflakeDbConnectionPool.SetMaxPoolSize(_maxPoolSize);
Expand Down
13 changes: 9 additions & 4 deletions Snowflake.Data/Client/SnowflakeDbConnectionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static IConnectionManager ConnectionManager
{
if (s_connectionManager != null)
return s_connectionManager;
SetConnectionPoolVersion(DefaultConnectionPoolType);
SetConnectionPoolVersion(DefaultConnectionPoolType, false);
return s_connectionManager;
}
}
Expand Down Expand Up @@ -123,14 +123,14 @@ public static bool GetPooling()

public static void SetOldConnectionPoolVersion()
{
SetConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
ForceConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
}

internal static void SetConnectionPoolVersion(ConnectionPoolType requestedPoolType)
private static void SetConnectionPoolVersion(ConnectionPoolType requestedPoolType, bool force)
{
lock (s_connectionManagerInstanceLock)
{
if (s_connectionManager != null)
if (s_connectionManager != null && !force)
return;

Check warning on line 134 in Snowflake.Data/Client/SnowflakeDbConnectionPool.cs

View check run for this annotation

Codecov / codecov/patch

Snowflake.Data/Client/SnowflakeDbConnectionPool.cs#L134

Added line #L134 was not covered by tests
Diagnostics.LogDiagnostics();
s_connectionManager?.ClearAllPools();
Expand All @@ -147,6 +147,11 @@ internal static void SetConnectionPoolVersion(ConnectionPoolType requestedPoolTy
}
}

internal static void ForceConnectionPoolVersion(ConnectionPoolType requestedPoolType)
{
SetConnectionPoolVersion(requestedPoolType, true);
}

internal static ConnectionPoolType GetConnectionPoolVersion()
{
if (ConnectionManager != null)
Expand Down

0 comments on commit 587cd50

Please sign in to comment.