diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs index 9d9dc2829d..24bb82caa7 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs @@ -22,10 +22,11 @@ using Xunit.Abstractions; namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests { - [CollectionDefinition(Name)] + // Disable running server tests in parallel so server logs can accurately be captured per test + [CollectionDefinition(Name, DisableParallelization = true)] public class HubConnectionTestsCollection : ICollectionFixture> { - public const string Name = "EndToEndTests"; + public const string Name = nameof(HubConnectionTestsCollection); } [Collection(HubConnectionTestsCollection.Name)] diff --git a/test/Microsoft.AspNetCore.SignalR.Redis.Tests/RedisEndToEnd.cs b/test/Microsoft.AspNetCore.SignalR.Redis.Tests/RedisEndToEnd.cs index 5f1ad5a929..3071d7ab91 100644 --- a/test/Microsoft.AspNetCore.SignalR.Redis.Tests/RedisEndToEnd.cs +++ b/test/Microsoft.AspNetCore.SignalR.Redis.Tests/RedisEndToEnd.cs @@ -17,13 +17,14 @@ using Xunit.Abstractions; namespace Microsoft.AspNetCore.SignalR.Redis.Tests { - [CollectionDefinition(Name)] - public class EndToEndTestsCollection : ICollectionFixture> + // Disable running server tests in parallel so server logs can accurately be captured per test + [CollectionDefinition(Name, DisableParallelization = true)] + public class RedisEndToEndTestsCollection : ICollectionFixture> { - public const string Name = "RedisEndToEndTests"; + public const string Name = nameof(RedisEndToEndTestsCollection); } - [Collection(EndToEndTestsCollection.Name)] + [Collection(RedisEndToEndTestsCollection.Name)] public class RedisEndToEndTests : VerifiableLoggedTest { private readonly RedisServerFixture _serverFixture; diff --git a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerLogScope.cs b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerLogScope.cs index ead19e80a3..6f01448bcb 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerLogScope.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerLogScope.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Concurrent; +using System.Threading.Tasks; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.SignalR.Tests @@ -12,26 +13,33 @@ namespace Microsoft.AspNetCore.SignalR.Tests private readonly ServerFixture _serverFixture; private readonly ILoggerFactory _loggerFactory; private readonly IDisposable _wrappedDisposable; - private readonly ConcurrentDictionary _loggers; + private readonly ConcurrentDictionary _serverLoggers; + private readonly ILogger _scopeLogger; public ServerLogScope(ServerFixture serverFixture, ILoggerFactory loggerFactory, IDisposable wrappedDisposable) { _serverFixture = serverFixture; _loggerFactory = loggerFactory; _wrappedDisposable = wrappedDisposable; - _loggers = new ConcurrentDictionary(StringComparer.Ordinal); + _scopeLogger = loggerFactory.CreateLogger(typeof(ServerLogScope)); + _serverLoggers = new ConcurrentDictionary(StringComparer.Ordinal); _serverFixture.ServerLogged += ServerFixtureOnServerLogged; + + _scopeLogger.LogInformation("Server log scope started."); } private void ServerFixtureOnServerLogged(LogRecord logRecord) { - var logger = _loggers.GetOrAdd(logRecord.Write.LoggerName, loggerName => _loggerFactory.CreateLogger(loggerName)); + // Create (or get) a logger with the same name as the server logger + var logger = _serverLoggers.GetOrAdd(logRecord.Write.LoggerName, loggerName => _loggerFactory.CreateLogger(loggerName)); logger.Log(logRecord.Write.LogLevel, logRecord.Write.EventId, logRecord.Write.State, logRecord.Write.Exception, logRecord.Write.Formatter); } public void Dispose() { + _scopeLogger.LogInformation("Server log scope disposing."); + _serverFixture.ServerLogged -= ServerFixtureOnServerLogged; _wrappedDisposable?.Dispose(); diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs index 3a8f03e534..da0f3e38c8 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs @@ -27,10 +27,11 @@ using HttpConnectionOptions = Microsoft.AspNetCore.Http.Connections.Client.HttpC namespace Microsoft.AspNetCore.SignalR.Tests { - [CollectionDefinition(Name)] + // Disable running server tests in parallel so server logs can accurately be captured per test + [CollectionDefinition(Name, DisableParallelization = true)] public class EndToEndTestsCollection : ICollectionFixture> { - public const string Name = "EndToEndTests"; + public const string Name = nameof(EndToEndTestsCollection); } [Collection(EndToEndTestsCollection.Name)]