Skip to content
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

Pool/SNOW-902610 min pool size #879

Closed
wants to merge 11 commits into from
Closed
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: DotNet Build and Test
# Triggers the workflow on push or pull request events but only for the master branch
on:
push:
branches: [ master ]
branches: [ master, pool/SNOW-860872-connection-pool ]
pull_request:
branches: [ master ]
branches: [ master, pool/SNOW-860872-connection-pool ]
workflow_dispatch:
inputs:
logLevel:
Expand Down
12 changes: 12 additions & 0 deletions CodingConventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ public class ExampleClass
}
```

#### Property

Use PascalCase, eg. `SomeProperty`.

```csharp
public ExampleProperty
{
get;
set;
}
```

### Local variables

Use camelCase, eg. `someVariable`.
Expand Down
362 changes: 362 additions & 0 deletions Snowflake.Data.Tests/IntegrationTests/ConnectionMultiplePoolsIT.cs

Large diffs are not rendered by default.

122 changes: 122 additions & 0 deletions Snowflake.Data.Tests/IntegrationTests/ConnectionPoolCommonIT.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
*/

using System.Data;
using System.Threading;
using NUnit.Framework;
using Snowflake.Data.Core;
using Snowflake.Data.Client;
using Snowflake.Data.Core.Session;
using Snowflake.Data.Log;
using Snowflake.Data.Tests.Util;

namespace Snowflake.Data.Tests.IntegrationTests
{
[TestFixture(ConnectionPoolType.SingleConnectionCache)]
[TestFixture(ConnectionPoolType.MultipleConnectionPool)]
[NonParallelizable]
class ConnectionPoolCommonIT : SFBaseTest
{
private readonly ConnectionPoolType _connectionPoolTypeUnderTest;
private static readonly SFLogger s_logger = SFLoggerFactory.GetLogger<ConnectionPoolManager>();
private readonly PoolConfig _previousPoolConfig;

public ConnectionPoolCommonIT(ConnectionPoolType connectionPoolTypeUnderTest)
{
_connectionPoolTypeUnderTest = connectionPoolTypeUnderTest;
_previousPoolConfig = new PoolConfig();
}

[SetUp]
public new void BeforeTest()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(_connectionPoolTypeUnderTest);
SnowflakeDbConnectionPool.ClearAllPools();
SnowflakeDbConnectionPool.SetPooling(true);
s_logger.Debug($"---------------- BeforeTest ---------------------");
s_logger.Debug($"Testing Pool Type: {SnowflakeDbConnectionPool.GetConnectionPoolVersion()}");
}

[TearDown]
public new void AfterTest()
{
_previousPoolConfig.Reset();
}

[OneTimeTearDown]
public static void AfterAllTests()
{
SnowflakeDbConnectionPool.ClearAllPools();
}

[Test]
public void TestBasicConnectionPool()
{
SnowflakeDbConnectionPool.SetMaxPoolSize(1);

var conn1 = new SnowflakeDbConnection(ConnectionString);
conn1.Open();
Assert.AreEqual(ConnectionState.Open, conn1.State);
conn1.Close();

Assert.AreEqual(ConnectionState.Closed, conn1.State);
Assert.AreEqual(1, SnowflakeDbConnectionPool.GetPool(ConnectionString).GetCurrentPoolSize());
}

[Test]
public void TestConnectionPoolMultiThreading()
{
Thread t1 = new Thread(() => ThreadProcess1(ConnectionString));
Thread t2 = new Thread(() => ThreadProcess2(ConnectionString));

t1.Start();
t2.Start();

t1.Join();
t2.Join();
}

void ThreadProcess1(string connstr)
{
var conn1 = new SnowflakeDbConnection();
conn1.ConnectionString = connstr;
conn1.Open();
Thread.Sleep(1000);
conn1.Close();
Thread.Sleep(4000);
Assert.AreEqual(ConnectionState.Closed, conn1.State);
}

void ThreadProcess2(string connstr)
{
var conn1 = new SnowflakeDbConnection();
conn1.ConnectionString = connstr;
conn1.Open();

Thread.Sleep(5000);
SFStatement statement = new SFStatement(conn1.SfSession);
SFBaseResultSet resultSet = statement.Execute(0, "select 1", null, false);
Assert.AreEqual(true, resultSet.Next());
Assert.AreEqual("1", resultSet.GetString(0));
conn1.Close();
SnowflakeDbConnectionPool.ClearAllPools();
SnowflakeDbConnectionPool.SetMaxPoolSize(0);
SnowflakeDbConnectionPool.SetPooling(true);
}

[Test]
public void TestConnectionPoolWithDispose()
{
SnowflakeDbConnectionPool.SetMaxPoolSize(1);

var conn1 = new SnowflakeDbConnection();
conn1.ConnectionString = "bad connection string";
Assert.Throws<SnowflakeDbException>(() => conn1.Open());
conn1.Close();

Assert.AreEqual(ConnectionState.Closed, conn1.State);
Assert.AreEqual(0, SnowflakeDbConnectionPool.GetPool(conn1.ConnectionString).GetCurrentPoolSize());
}
}
}
Loading
Loading