Skip to content

Commit

Permalink
Enable tests for NetCore and enable all traces
Browse files Browse the repository at this point in the history
  • Loading branch information
cheenamalhotra committed Mar 24, 2020
1 parent e08b7ee commit 4ef7d68
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,35 @@ internal class SqlClientEventSource : EventSource
/// </summary>
private const int AdvancedTraceBinId = 15;

/// <summary>
/// Defines EventId for AdvancedTraceError() events
/// </summary>
private const int AdvancedTraceErrorId = 16;

/// <summary>
/// Defines EventId for CorrelationTrace() events
/// </summary>
private const int CorrelationTraceId = 16;
private const int CorrelationTraceId = 17;

/// <summary>
/// Defines EventId for StateDump() events
/// </summary>
private const int StateDumpEventId = 17;
private const int StateDumpEventId = 18;

/// <summary>
/// Defines EventId for SNITrace() events
/// </summary>
private const int SNITraceEventId = 18;
private const int SNITraceEventId = 19;

/// <summary>
/// Defines EventId for SNIEnterScope() events
/// </summary>
private const int SNIScopeEnterId = 19;
private const int SNIScopeEnterId = 20;

/// <summary>
/// Defines EventId for SNIExitScope() events
/// </summary>
private const int SNIScopeExitId = 20;
private const int SNIScopeExitId = 21;
#endregion

/// <summary>
Expand Down Expand Up @@ -873,13 +878,13 @@ internal long PoolerScopeEnter(string message)
[Event(PoolerScopeExitId, Level = EventLevel.Informational, Opcode = EventOpcode.Stop, Keywords = Keywords.PoolerScope)]
internal void PoolerScopeLeave(long scopeId)
{
WriteEvent(ScopeExitId, scopeId);
WriteEvent(PoolerScopeExitId, scopeId);
}

[Event(AdvancedTraceId, Level = EventLevel.Verbose, Keywords = Keywords.AdvancedTrace)]
internal void AdvancedTrace(string message)
{
WriteEvent(TraceEventId, message);
WriteEvent(AdvancedTraceId, message);
}

[Event(AdvancedScopeEnterId, Level = EventLevel.Verbose, Opcode = EventOpcode.Start, Keywords = Keywords.AdvancedTrace)]
Expand All @@ -902,10 +907,10 @@ internal void AdvancedTraceBin(string message)
WriteEvent(AdvancedTraceBinId, message);
}

[Event(AdvancedTraceId, Level = EventLevel.Error, Keywords = Keywords.AdvancedTrace)]
[Event(AdvancedTraceErrorId, Level = EventLevel.Error, Keywords = Keywords.AdvancedTrace)]
internal void AdvancedTraceError(string message)
{
WriteEvent(TraceEventId, message);
WriteEvent(AdvancedTraceErrorId, message);
}

[Event(CorrelationTraceId, Level = EventLevel.Informational, Keywords = Keywords.CorrelationTrace, Opcode = EventOpcode.Start)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,13 @@ internal long PoolerScopeEnter(string message)
[Event(PoolerScopeExitId, Level = EventLevel.Informational, Opcode = EventOpcode.Stop, Keywords = Keywords.PoolerScope)]
internal void PoolerScopeLeave(long scopeId)
{
WriteEvent(ScopeExitId, scopeId);
WriteEvent(PoolerScopeExitId, scopeId);
}

[Event(AdvancedTraceId, Level = EventLevel.Verbose, Keywords = Keywords.AdvancedTrace)]
internal void AdvancedTrace(string message)
{
WriteEvent(TraceEventId, message);
WriteEvent(AdvancedTraceId, message);
}

[Event(AdvancedScopeEnterId, Level = EventLevel.Verbose, Opcode = EventOpcode.Start, Keywords = Keywords.AdvancedTrace)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,56 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Linq;
using Xunit;

namespace Microsoft.Data.SqlClient.ManualTesting.Tests
{
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp, "Not Implemented")]
public class EventSourceTest
{
List<int> ids = new List<int>();

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
public void EventTraceTests()
{
GetIds();
//Trace EventKeyword is 3.
//We did not want to break the SqlEventSource for BeginExexute and EndExecute
// BeginExexute and EndExecute are Enabled when any kind of Event logging is enabled, so we check for those values as well.
Assert.All(ids, item => { Assert.True(3 == item || 1 == item || item == 2); });
}

private void GetIds()
public void EventSourceTestAll()
{
using (var TraceListener = new TraceEventListener())
{
using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand("SELECT * From [Customers]", connection))
using (SqlDataReader reader = command.ExecuteReader())
{
command.ExecuteNonQuery();
while (reader.Read())
{
// Flush data
}
}
ids = TraceListener.IDs;
}
ids = TraceListener.IDs;
// Need to investigate better way of collecting traces in sequential runs,
// For now we're collecting all traces to improve code coverage.
#if NETCOREAPP
Assert.True(TraceListener.IDs.Count == 226);
#else
Assert.True(TraceListener.IDs.Count == 250);
#endif
Assert.All(TraceListener.IDs, item => { Assert.Contains(item, Enumerable.Range(1, 21)); });
}
}
}

[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp, "Not Implemented")]
public class TraceEventListener : EventListener
{
public List<int> IDs = new List<int>();

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

This comment has been minimized.

Copy link
@JRahnama

JRahnama Mar 24, 2020

Contributor

If you want to capture all the keywords, it should be EventKeywords.All.

}
}

Expand Down

0 comments on commit 4ef7d68

Please sign in to comment.