diff --git a/src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs b/src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs index cefdd3d65282..6bcede93dbea 100644 --- a/src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs +++ b/src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs @@ -39,8 +39,9 @@ public KestrelServerImpl( IEnumerable multiplexedFactories, IHttpsConfigurationService httpsConfigurationService, ILoggerFactory loggerFactory, + DiagnosticSource? diagnosticSource, KestrelMetrics metrics) - : this(transportFactories, multiplexedFactories, httpsConfigurationService, CreateServiceContext(options, loggerFactory, diagnosticSource: null, metrics)) + : this(transportFactories, multiplexedFactories, httpsConfigurationService, CreateServiceContext(options, loggerFactory, diagnosticSource, metrics)) { } @@ -111,7 +112,8 @@ private static ServiceContext CreateServiceContext(IOptions ServiceContext.ServerOptions; - private ServiceContext ServiceContext { get; } + // Internal for testing + internal ServiceContext ServiceContext { get; } private KestrelTrace Trace => ServiceContext.Log; diff --git a/src/Servers/Kestrel/Core/src/KestrelServer.cs b/src/Servers/Kestrel/Core/src/KestrelServer.cs index 75cec0130767..7f2909c77cf6 100644 --- a/src/Servers/Kestrel/Core/src/KestrelServer.cs +++ b/src/Servers/Kestrel/Core/src/KestrelServer.cs @@ -36,6 +36,7 @@ public KestrelServer(IOptions options, IConnectionListener Array.Empty(), new SimpleHttpsConfigurationService(), loggerFactory, + diagnosticSource: null, new KestrelMetrics(new DummyMeterFactory())); } diff --git a/src/Servers/Kestrel/Core/test/KestrelServerTests.cs b/src/Servers/Kestrel/Core/test/KestrelServerTests.cs index a0709d00ad19..e688812a6075 100644 --- a/src/Servers/Kestrel/Core/test/KestrelServerTests.cs +++ b/src/Servers/Kestrel/Core/test/KestrelServerTests.cs @@ -309,6 +309,7 @@ private static KestrelServerImpl CreateKestrelServer( multiplexedFactories, httpsConfigurationService, loggerFactory ?? new LoggerFactory(new[] { new KestrelTestLoggerProvider() }), + diagnosticSource: null, metrics ?? new KestrelMetrics(new TestMeterFactory())); } diff --git a/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs b/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs index 759d074a6d82..b24da893ab53 100644 --- a/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs +++ b/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs @@ -2,10 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections; +using System.IO.Pipelines; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; using Microsoft.Extensions.DependencyInjection; @@ -107,6 +109,11 @@ public void ServerIsKestrelServerImpl() .UseKestrel() .Configure(app => { }); - Assert.IsType(hostBuilder.Build().Services.GetService()); + var server = Assert.IsType(hostBuilder.Build().Services.GetService()); + + Assert.NotNull(server.ServiceContext.DiagnosticSource); + Assert.IsType(server.ServiceContext.Metrics); + Assert.Equal(PipeScheduler.ThreadPool, server.ServiceContext.Scheduler); + Assert.Equal(TimeProvider.System, server.ServiceContext.TimeProvider); } }