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-937190 max pool size reached #839

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
159 changes: 159 additions & 0 deletions Snowflake.Data.Tests/IntegrationTests/ConnectingThreads.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Snowflake.Data.Client;

namespace Snowflake.Data.Tests.IntegrationTests
{
class ConnectingThreads
{
private string _connectionString;

private ConcurrentQueue<ThreadEvent> _events = new ConcurrentQueue<ThreadEvent>();

private List<Thread> threads = new List<Thread>();

public ConnectingThreads(string connectionString)
{
_connectionString = connectionString;
}

public ConnectingThreads NewThread(string name,
long waitBeforeConnectMillis,
long waitAfterConnectMillis,
bool closeOnExit)
{
var thread = new ConnectingThread(
name,
_events,
_connectionString,
waitBeforeConnectMillis,
waitAfterConnectMillis,
closeOnExit).Build();
threads.Add(thread);
return this;
}

public ConnectingThreads StartAll()
{
threads.ForEach(thread => thread.Start());
return this;
}

public ConnectingThreads JoinAll()
{
threads.ForEach(thread => thread.Join());
return this;
}

public IEnumerable<ThreadEvent> Events() => _events.ToArray().OfType<ThreadEvent>();
}

class ConnectingThread
{
private string _name;

private ConcurrentQueue<ThreadEvent> _events;

private string _connectionString;

private long _waitBeforeConnectMillis;

private long _waitAfterConnectMillis;

private bool _closeOnExit;

public ConnectingThread(
string name,
ConcurrentQueue<ThreadEvent> events,
string connectionString,
long waitBeforeConnectMillis,
long waitAfterConnectMillis,
bool closeOnExit)
{
_name = name;
_events = events;
_connectionString = connectionString;
_waitBeforeConnectMillis = waitBeforeConnectMillis;
_waitAfterConnectMillis = waitAfterConnectMillis;
_closeOnExit = closeOnExit;
}

public Thread Build()
{
var thread = new Thread(Execute);
thread.Name = "thread_" + _name;
return thread;
}

private void Execute()
{
var connection = new SnowflakeDbConnection();
connection.ConnectionString = _connectionString;
Sleep(_waitBeforeConnectMillis);
var watch = new Stopwatch();
watch.Start();
var connected = false;
try
{
connection.Open();
connected = true;
}
catch (Exception exception)
{
watch.Stop();
_events.Enqueue(ThreadEvent.EventConnectingFailed(_name, exception, watch.ElapsedMilliseconds));
}
if (connected)
{
watch.Stop();
_events.Enqueue(ThreadEvent.EventConnected(_name, watch.ElapsedMilliseconds));
}
Sleep(_waitAfterConnectMillis);
if (_closeOnExit)
{
connection.Close();
}
}

private void Sleep(long millis)
{
if (millis <= 0)
{
return;
}
System.Threading.Thread.Sleep((int) millis);
}
}

class ThreadEvent
{
public string ThreadName { get; set; }

public string EventName { get; set; }

public Exception Error { get; set; }

public long Timestamp { get; set; }

public long Duration { get; set; }

public ThreadEvent(string threadName, string eventName, Exception error, long duration)
{
ThreadName = threadName;
EventName = eventName;
Error = error;
Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
Duration = duration;
}

public static ThreadEvent EventConnected(string threadName, long duration) =>
new ThreadEvent(threadName, "CONNECTED", null, duration);

public static ThreadEvent EventConnectingFailed(string threadName, Exception exception, long duration) =>
new ThreadEvent(threadName, "FAILED_TO_CONNECT", exception, duration);
}
}
Loading
Loading