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

Unit tests for Microsoft.Data.SqlClient.SqlClientEventSource #2

Merged
merged 14 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal abstract partial class DbConnectionFactory
private static int _objectTypeCount; // EventSource counter
internal int ObjectID { get; } = Interlocked.Increment(ref _objectTypeCount);

// s_pendingOpenNonPooled is an array of tasks used to throttle creation of non-pooled connections to
// s_pendingOpenNonPooled is an array of tasks used to throttle creation of non-pooled connections to
// a maximum of Environment.ProcessorCount at a time.
private static uint s_pendingOpenNonPooledNext = 0;
private static Task<DbConnectionInternal>[] s_pendingOpenNonPooled = new Task<DbConnectionInternal>[Environment.ProcessorCount];
Expand Down Expand Up @@ -307,7 +307,7 @@ private void PruneConnectionPoolGroups(object state)
{
// when debugging this method, expect multiple threads at the same time
SqlClientEventSource.Log.TryAdvancedTraceEvent("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}", ObjectID);

// First, walk the pool release list and attempt to clear each
// pool, when the pool is finally empty, we dispose of it. If the
// pool isn't empty, it's because there are active connections or
Expand Down Expand Up @@ -377,8 +377,8 @@ private void PruneConnectionPoolGroups(object state)
// move idle entries from last prune pass to a queue for pending release
// otherwise process entry which may move it from active to idle
if (entry.Value.Prune())
{ // may add entries to _poolsToRelease
SqlClientEventSource.Log.ActiveConnectionPoolGroupRequest(false);
{
// may add entries to _poolsToRelease
QueuePoolGroupForRelease(entry.Value);
}
else
Expand Down Expand Up @@ -411,6 +411,7 @@ internal void QueuePoolForRelease(DbConnectionPool pool, bool clearing)
}
_poolsToRelease.Add(pool);
}
SqlClientEventSource.Log.ActiveConnectionPoolRequest(false);
SqlClientEventSource.Log.InactiveConnectionPoolRequest();
}

Expand All @@ -423,6 +424,7 @@ internal void QueuePoolGroupForRelease(DbConnectionPoolGroup poolGroup)
{
_poolGroupsToRelease.Add(poolGroup);
}
SqlClientEventSource.Log.ActiveConnectionPoolGroupRequest(false);
SqlClientEventSource.Log.InactiveConnectionPoolGroupRequest();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ internal int Clear()
if (pool != null)
{
DbConnectionFactory connectionFactory = pool.ConnectionFactory;
SqlClientEventSource.Log.ActiveConnectionPoolRequest(false);
connectionFactory.QueuePoolForRelease(pool, true);
}
}
Expand Down Expand Up @@ -196,8 +195,8 @@ internal DbConnectionPool GetConnectionPool(DbConnectionFactory connectionFactor
// else pool entry has been disabled so don't create new pools
Debug.Assert(PoolGroupStateDisabled == _state, "state should be disabled");

// don't need to call connectionFactory.QueuePoolForRelease(newPool) because
// pool callbacks were delayed and no risk of connections being created
// don't need to call connectionFactory.QueuePoolForRelease(newPool) because
// pool callbacks were delayed and no risk of connections being created
newPool.Shutdown();
}
}
Expand Down Expand Up @@ -264,9 +263,8 @@ internal bool Prune()
// pool into a list of pools to be released when they
// are completely empty.
DbConnectionFactory connectionFactory = pool.ConnectionFactory;

connectionFactory.QueuePoolForRelease(pool, false);
SqlClientEventSource.Log.ActiveConnectionPoolRequest(false);

}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static class DataTestUtility
private const string ManagedNetworkingAppContextSwitch = "Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows";

private static Dictionary<string, bool> AvailableDatabases;
private static TraceEventListener TraceListener;

static DataTestUtility()
{
Expand Down Expand Up @@ -86,11 +85,6 @@ static DataTestUtility()

System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;

if (TracingEnabled)
{
TraceListener = new TraceEventListener();
karinazhou marked this conversation as resolved.
Show resolved Hide resolved
}

if (UseManagedSNIOnWindows)
{
AppContext.SetSwitch(ManagedNetworkingAppContextSwitch, true);
Expand Down Expand Up @@ -689,14 +683,23 @@ public static string RetrieveValueFromConnStr(string connStr, string[] keywords)

public class TraceEventListener : EventListener
{
private IList<EventSource> _eventSources = new List<EventSource>();
karinazhou marked this conversation as resolved.
Show resolved Hide resolved
public List<int> IDs = new List<int>();

public override void Dispose()
{
foreach (EventSource eventSource in _eventSources)
DisableEvents(eventSource);
base.Dispose();
}

protected override void OnEventSourceCreated(EventSource eventSource)
{
if (eventSource.Name.Equals("Microsoft.Data.SqlClient.EventSource"))
{
//// Collect all traces for better code coverage
EnableEvents(eventSource, EventLevel.Informational, EventKeywords.All);
_eventSources.Add(eventSource);
}
}

Expand Down
Loading