Skip to content

Commit

Permalink
add test to prove that old bug is gone, fixes microsoft#461
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed Jan 23, 2018
1 parent 10d1f92 commit b30552e
Showing 1 changed file with 47 additions and 18 deletions.
65 changes: 47 additions & 18 deletions src/TraceEvent/TraceEvent.Tests/EventPipeParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,33 @@ public void Basic(string eventPipeFileName)

Output.WriteLine(string.Format("Processing the file {0}, Making ETLX and scanning.", Path.GetFullPath(eventPipeFilePath)));

var traceSource = new TraceLog(TraceLog.CreateFromEventPipeDataFile(eventPipeFilePath)).Events.GetSource();
var eventStatistics = new SortedDictionary<string, EventRecord>(StringComparer.Ordinal);
traceSource.AllEvents += delegate (TraceEvent data)

using (var traceLog = new TraceLog(TraceLog.CreateFromEventPipeDataFile(eventPipeFilePath)))
{
string eventName = data.ProviderName + "/" + data.EventName;
var traceSource = traceLog.Events.GetSource();

if (eventStatistics.ContainsKey(eventName))
{
eventStatistics[eventName].TotalCount++;
}
else
traceSource.AllEvents += delegate (TraceEvent data)
{
eventStatistics[eventName] = new EventRecord()
{
TotalCount = 1,
FirstSeriazliedSample = new String(data.ToString().Replace("\n", "\\n").Replace("\r", "\\r").Take(1000).ToArray())
};
}
};

// Process
traceSource.Process();
string eventName = data.ProviderName + "/" + data.EventName;

if (eventStatistics.ContainsKey(eventName))
{
eventStatistics[eventName].TotalCount++;
}
else
{
eventStatistics[eventName] = new EventRecord()
{
TotalCount = 1,
FirstSeriazliedSample = new String(data.ToString().Replace("\n", "\\n").Replace("\r", "\\r").Take(1000).ToArray())
};
}
};

// Process
traceSource.Process();
}
// Validate
ValidateEventStatistics(eventStatistics, eventPipeFileName);
}
Expand Down Expand Up @@ -108,6 +112,31 @@ public void CanParseHeaderOfV3EventPipeFile()
}
}

[Fact]
public void AllEventsLeavesNoUnhandledEvents()
{
PrepareTestData();

const string eventPipeFileName = "eventpipe-dotnetcore2.1-win-x86-objver3.netperf";

string eventPipeFilePath = Path.Combine(UnZippedDataDir, eventPipeFileName);

using (var traceSource = new TraceLog(TraceLog.CreateFromEventPipeDataFile(eventPipeFilePath)).Events.GetSource())
{
int dynamicAllInvocationCount = 0;
int unhandledEvents = 0;

traceSource.AllEvents += _ => dynamicAllInvocationCount++;

traceSource.UnhandledEvents += _ => unhandledEvents++;

traceSource.Process();

Assert.NotEqual(0, dynamicAllInvocationCount);
Assert.Equal(0, unhandledEvents);
}
}

private void ValidateEventStatistics(SortedDictionary<string, EventRecord> eventStatistics, string eventPipeFileName)
{
StringBuilder sb = new StringBuilder(1024 * 1024);
Expand Down

0 comments on commit b30552e

Please sign in to comment.