-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SNOW-937188 pool mode where changed session gets destroyed [WIP] #934
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
using NUnit.Framework; | ||
using Snowflake.Data.Client; | ||
using Snowflake.Data.Core; | ||
using Snowflake.Data.Core.Session; | ||
using Snowflake.Data.Tests.Util; | ||
|
||
namespace Snowflake.Data.Tests.IntegrationTests | ||
{ | ||
[TestFixture] | ||
[NonParallelizable] | ||
public class ConnectionChangedSessionIT : SFBaseTest | ||
{ | ||
private readonly QueryExecResponseData _queryExecResponseChangedRole = new() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW do we want it to work for old pool as well? As I see the implementation - it would work for old pool as well. Don't we want to cover that in tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets have it only in latest pool (the least changes to prev the better) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all of the parameters that can cause not returning session to the pool should be covered in tests (so making one of them excluded from list should make some test to fail). But currently I think the situation is different. For example if the role has changed - it is only checked in the test for default pool mode which is OriginalPool, and is not covered in Destroy test. So I would add more unit tests to SFSessionTests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree but on the other side any changed is handled equally |
||
{ | ||
finalDatabaseName = TestEnvironment.TestConfig.database, | ||
finalSchemaName = TestEnvironment.TestConfig.schema, | ||
finalRoleName = "role change", | ||
finalWarehouseName = TestEnvironment.TestConfig.warehouse | ||
}; | ||
|
||
private readonly QueryExecResponseData _queryExecResponseChangedDatabase = new() | ||
{ | ||
finalDatabaseName = "database changed", | ||
finalSchemaName = TestEnvironment.TestConfig.schema, | ||
finalRoleName = TestEnvironment.TestConfig.role, | ||
finalWarehouseName = TestEnvironment.TestConfig.warehouse | ||
}; | ||
|
||
private readonly QueryExecResponseData _queryExecResponseChangedSchema = new() | ||
{ | ||
finalDatabaseName = TestEnvironment.TestConfig.database, | ||
finalSchemaName = "schema changed", | ||
finalRoleName = TestEnvironment.TestConfig.role, | ||
finalWarehouseName = TestEnvironment.TestConfig.warehouse | ||
}; | ||
|
||
private readonly QueryExecResponseData _queryExecResponseChangedWarehouse = new() | ||
{ | ||
finalDatabaseName = TestEnvironment.TestConfig.database, | ||
finalSchemaName = TestEnvironment.TestConfig.schema, | ||
finalRoleName = TestEnvironment.TestConfig.role, | ||
finalWarehouseName = "warehouse changed" | ||
}; | ||
|
||
private static PoolConfig s_previousPoolConfigRestorer; | ||
|
||
[OneTimeSetUp] | ||
public static void BeforeAllTests() | ||
{ | ||
s_previousPoolConfigRestorer = new PoolConfig(); | ||
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool); | ||
} | ||
|
||
[SetUp] | ||
public new void BeforeTest() | ||
{ | ||
SnowflakeDbConnectionPool.ClearAllPools(); | ||
} | ||
|
||
[TearDown] | ||
public new void AfterTest() | ||
{ | ||
SnowflakeDbConnectionPool.ClearAllPools(); | ||
} | ||
|
||
[OneTimeTearDown] | ||
public static void AfterAllTests() | ||
{ | ||
s_previousPoolConfigRestorer.Reset(); | ||
} | ||
|
||
[Test] | ||
public void TestPoolDestroysConnectionWhenChangedSessionProperties() | ||
{ | ||
var connectionString = ConnectionString + "application=Destroy;ChangedSession=Destroy;minPoolSize=0;maxPoolSize=3"; | ||
var pool = SnowflakeDbConnectionPool.GetPool(connectionString); | ||
|
||
var connection = new SnowflakeDbConnection(connectionString); | ||
connection.Open(); | ||
connection.SfSession.UpdateSessionProperties(_queryExecResponseChangedDatabase); | ||
connection.Close(); | ||
|
||
Assert.AreEqual(0, pool.GetCurrentPoolSize()); | ||
} | ||
|
||
[Test] | ||
public void TestPoolingWhenSessionPropertiesUnchanged() | ||
{ | ||
var connectionString = ConnectionString + "application=NoSessionChanges;ChangedSession=Destroy;minPoolSize=0;maxPoolSize=3"; | ||
var pool = SnowflakeDbConnectionPool.GetPool(connectionString); | ||
|
||
var connection = new SnowflakeDbConnection(connectionString); | ||
connection.Open(); | ||
connection.Close(); | ||
|
||
Assert.AreEqual(1, pool.GetCurrentPoolSize()); | ||
} | ||
|
||
[Test] | ||
public void TestPoolingWhenConnectionPropertiesChangedForOriginalPoolMode() | ||
{ | ||
var connectionString = ConnectionString + "application=OriginalPoolMode;ChangedSession=OriginalPool;minPoolSize=0;maxPoolSize=3"; | ||
var pool = SnowflakeDbConnectionPool.GetPool(connectionString); | ||
|
||
var connection = new SnowflakeDbConnection(connectionString); | ||
connection.Open(); | ||
connection.SfSession.UpdateSessionProperties(_queryExecResponseChangedWarehouse); | ||
var sessionId = connection.SfSession.sessionId; | ||
connection.Close(); | ||
|
||
Assert.AreEqual(1, pool.GetCurrentPoolSize()); | ||
connection.Close(); | ||
|
||
var connection2 = new SnowflakeDbConnection(connectionString); | ||
connection2.Open(); | ||
Assert.AreEqual(sessionId, connection2.SfSession.sessionId); | ||
connection2.Close(); | ||
} | ||
|
||
[Test] | ||
public void TestPoolingWhenConnectionPropertiesChangedForDefaultPoolMode() | ||
{ | ||
var connectionString = ConnectionString + "application=DefaultPoolMode;minPoolSize=0;maxPoolSize=3"; | ||
var pool = SnowflakeDbConnectionPool.GetPool(connectionString); | ||
|
||
var connection = new SnowflakeDbConnection(connectionString); | ||
connection.Open(); | ||
connection.SfSession.UpdateSessionProperties(_queryExecResponseChangedRole); | ||
var sessionId = connection.SfSession.sessionId; | ||
connection.Close(); | ||
|
||
Assert.AreEqual(1, pool.GetCurrentPoolSize()); | ||
|
||
var connection2 = new SnowflakeDbConnection(connectionString); | ||
connection2.Open(); | ||
Assert.AreEqual(sessionId, connection2.SfSession.sessionId); | ||
connection2.Close(); | ||
} | ||
|
||
[Test] | ||
public void TestPoolDestroysAndRecreatesConnection() | ||
{ | ||
var connectionString = ConnectionString + "application=DestroyRecreateSession;ChangedSession=Destroy;minPoolSize=1;maxPoolSize=3"; | ||
|
||
var connection = new SnowflakeDbConnection(connectionString); | ||
connection.Open(); | ||
var sessionId = connection.SfSession.sessionId; | ||
connection.SfSession.UpdateSessionProperties(_queryExecResponseChangedSchema); | ||
connection.Close(); | ||
|
||
var pool = SnowflakeDbConnectionPool.GetPool(connectionString); | ||
Assert.AreEqual(1, pool.GetCurrentPoolSize()); | ||
|
||
var connection2 = new SnowflakeDbConnection(connectionString); | ||
connection2.Open(); | ||
Assert.AreNotEqual(sessionId, connection2.SfSession.sessionId); | ||
connection2.Close(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe ConnectionMultiplePoolsChangedSessionIT? it would be more visible that it is a test for the new pool