diff --git a/src/tests/CommonTestRunner/Debuggees/EventPipeTracee/Program.cs b/src/tests/CommonTestRunner/Debuggees/EventPipeTracee/Program.cs index a8251d4406..bc1afbf44a 100644 --- a/src/tests/CommonTestRunner/Debuggees/EventPipeTracee/Program.cs +++ b/src/tests/CommonTestRunner/Debuggees/EventPipeTracee/Program.cs @@ -42,11 +42,13 @@ public static async Task Main(string[] args) Console.WriteLine($"{pid} EventPipeTracee: start process"); Console.Out.Flush(); - // Workaround for https://github.com/dotnet/runtime/issues/127681 - // LoggingEventSource has a static initialization order bug fields are declared after the singleton instance. + // Workaround for https://github.com/dotnet/runtime/issues/127681. + // LoggingEventSource has a static initialization order bug: fields are declared after the singleton instance. // If EventPipe enables the source during or before the LoggingEventSource.Instance constructor, ParseFilterSpec - // produces wrong rules. Force the type initializer to complete before connecting to the pipe (which signals - // the test harness that EventPipe can be enabled). + // produces wrong rules. The pipe connection signals that the test harness can enable EventPipe, so fully + // construct the logger factory and loggers first. This also ensures its filter options monitor is subscribed + // before EventPipe updates the filter specification; otherwise that update can be missed and the application + // filters remain active, dropping the LoggerRemoteTest records. ServiceCollection serviceCollection = new(); serviceCollection.AddLogging(builder => { builder.AddEventSourceLogger(); @@ -55,6 +57,10 @@ public static async Task Main(string[] args) builder.AddFilter(AppLoggerCategoryName, LogLevel.Warning); }); + using ILoggerFactory loggerFactory = serviceCollection.BuildServiceProvider().GetService(); + ILogger customCategoryLogger = loggerFactory.CreateLogger(loggerCategory); + ILogger appCategoryLogger = loggerFactory.CreateLogger(AppLoggerCategoryName); + // Signal that the tracee has started Console.WriteLine($"{pid} EventPipeTracee: connecting to pipe"); Console.Out.Flush(); @@ -62,11 +68,6 @@ public static async Task Main(string[] args) Console.WriteLine($"{pid} EventPipeTracee: connected to pipe"); Console.Out.Flush(); - - using ILoggerFactory loggerFactory = serviceCollection.BuildServiceProvider().GetService(); - ILogger customCategoryLogger = loggerFactory.CreateLogger(loggerCategory); - ILogger appCategoryLogger = loggerFactory.CreateLogger(AppLoggerCategoryName); - using ActivitySource activitySource = useActivitySource ? new ActivitySource("EventPipeTracee.ActivitySource", version: "1.0.0") : null; diff --git a/src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/EventLogsPipelineUnitTests.cs b/src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/EventLogsPipelineUnitTests.cs index 1b1d00e0e8..280a3528d1 100644 --- a/src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/EventLogsPipelineUnitTests.cs +++ b/src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/EventLogsPipelineUnitTests.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -43,11 +42,6 @@ public EventLogsPipelineUnitTests(ITestOutputHelper output) [SkippableTheory, MemberData(nameof(Configurations))] public async Task TestLogsAllCategoriesAllLevels(TestConfiguration config) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - throw new SkipTestException("https://github.com/dotnet/diagnostics/issues/2541"); - } - using Stream outputStream = await GetLogsAsync(config, settings => { settings.UseAppFilters = false; }); @@ -68,7 +62,7 @@ public async Task TestLogsAllCategoriesAllLevels(TestConfiguration config) /// /// Test that log events at or above the default level are collected. /// - [SkippableTheory(Skip = "https://github.com/dotnet/diagnostics/issues/2541"), MemberData(nameof(Configurations))] + [SkippableTheory, MemberData(nameof(Configurations))] public async Task TestLogsAllCategoriesDefaultLevel(TestConfiguration config) { using Stream outputStream = await GetLogsAsync(config, settings => { @@ -90,14 +84,9 @@ public async Task TestLogsAllCategoriesDefaultLevel(TestConfiguration config) /// /// Test that log events at the default level are collected for categories without a specified level. /// - [SkippableTheory(Skip = "Unreliable test https://github.com/dotnet/diagnostics/issues/3143"), MemberData(nameof(Configurations))] + [SkippableTheory, MemberData(nameof(Configurations))] public async Task TestLogsAllCategoriesDefaultLevelFallback(TestConfiguration config) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - throw new SkipTestException("https://github.com/dotnet/diagnostics/issues/2541"); - } - using Stream outputStream = await GetLogsAsync(config, settings => { settings.UseAppFilters = false; settings.LogLevel = LogLevel.Error; @@ -143,11 +132,6 @@ public async Task TestLogsAllCategoriesDefaultLevelNoneNotSupported(TestConfigur [SkippableTheory, MemberData(nameof(Configurations))] public async Task TestLogsUseAppFilters(TestConfiguration config) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - throw new SkipTestException("https://github.com/dotnet/diagnostics/issues/2541"); - } - using Stream outputStream = await GetLogsAsync(config); Assert.True(outputStream.Length > 0, "No data written by logging process."); @@ -164,7 +148,7 @@ public async Task TestLogsUseAppFilters(TestConfiguration config) /// Test that log events are collected for the categories and levels specified by the application /// and for the categories and levels specified in the filter specs. /// - [SkippableTheory(Skip = "https://github.com/dotnet/diagnostics/issues/2541"), MemberData(nameof(Configurations))] + [SkippableTheory, MemberData(nameof(Configurations))] public async Task TestLogsUseAppFiltersAndFilterSpecs(TestConfiguration config) { using Stream outputStream = await GetLogsAsync(config, settings => { @@ -191,11 +175,6 @@ public async Task TestLogsUseAppFiltersAndFilterSpecs(TestConfiguration config) [SkippableTheory, MemberData(nameof(Configurations))] public async Task TestLogsWildcardCategory(TestConfiguration config) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - throw new SkipTestException("https://github.com/dotnet/diagnostics/issues/2541"); - } - using Stream outputStream = await GetLogsAsync(config, settings => { settings.UseAppFilters = false; settings.LogLevel = LogLevel.Critical;