From b30552ea1e6b60c2e8c215d9d5023b1d18f3201e Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Tue, 23 Jan 2018 23:37:18 +0100 Subject: [PATCH] add test to prove that old bug is gone, fixes #461 --- .../TraceEvent.Tests/EventPipeParsing.cs | 65 ++++++++++++++----- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/src/TraceEvent/TraceEvent.Tests/EventPipeParsing.cs b/src/TraceEvent/TraceEvent.Tests/EventPipeParsing.cs index 5183f8658..16001e7da 100644 --- a/src/TraceEvent/TraceEvent.Tests/EventPipeParsing.cs +++ b/src/TraceEvent/TraceEvent.Tests/EventPipeParsing.cs @@ -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(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); } @@ -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 eventStatistics, string eventPipeFileName) { StringBuilder sb = new StringBuilder(1024 * 1024);