Skip to content

Commit

Permalink
Implemented tests for Microsoft.Data.SqlClient.SqlClientEventSource
Browse files Browse the repository at this point in the history
  • Loading branch information
winseros committed Jan 5, 2021
1 parent 377fb33 commit 0954f2d
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 58 deletions.
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();
}

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>();
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

0 comments on commit 0954f2d

Please sign in to comment.