Skip to content

Commit

Permalink
Switch back to libuv as the default transport (#2257)
Browse files Browse the repository at this point in the history
* Switch back to libuv as the default transport
  • Loading branch information
halter73 committed Jan 19, 2018
1 parent 040ea2e commit 526dfdb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Kestrel/WebHostBuilderKestrelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
Expand All @@ -30,7 +29,7 @@ public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder)
return hostBuilder.ConfigureServices(services =>
{
// Don't override an already-configured transport
services.TryAddSingleton<ITransportFactory, SocketTransportFactory>();
services.TryAddSingleton<ITransportFactory, LibuvTransportFactory>();
services.AddTransient<IConfigureOptions<KestrelServerOptions>, KestrelServerOptionsSetup>();
services.AddSingleton<IServer, KestrelServer>();
Expand Down
49 changes: 49 additions & 0 deletions test/Kestrel.Tests/WebHostBuilderKestrelExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

Expand Down Expand Up @@ -46,5 +49,51 @@ public void ApplicationServicesNotNullDuringUseKestrelWithOptions()
// Act
hostBuilder.Build();
}

[Fact]
public void LibuvIsTheDefaultTransport()
{
var hostBuilder = new WebHostBuilder()
.UseKestrel()
.Configure(app => { });

Assert.IsType<LibuvTransportFactory>(hostBuilder.Build().Services.GetService<ITransportFactory>());
}

[Fact]
public void LibuvTransportCanBeManuallySelectedIndependentOfOrder()
{
var hostBuilder = new WebHostBuilder()
.UseKestrel()
.UseLibuv()
.Configure(app => { });

Assert.IsType<LibuvTransportFactory>(hostBuilder.Build().Services.GetService<ITransportFactory>());

var hostBuilderReversed = new WebHostBuilder()
.UseLibuv()
.UseKestrel()
.Configure(app => { });

Assert.IsType<LibuvTransportFactory>(hostBuilderReversed.Build().Services.GetService<ITransportFactory>());
}

[Fact]
public void SocketsTransportCanBeManuallySelectedIndependentOfOrder()
{
var hostBuilder = new WebHostBuilder()
.UseKestrel()
.UseSockets()
.Configure(app => { });

Assert.IsType<SocketTransportFactory>(hostBuilder.Build().Services.GetService<ITransportFactory>());

var hostBuilderReversed = new WebHostBuilder()
.UseSockets()
.UseKestrel()
.Configure(app => { });

Assert.IsType<SocketTransportFactory>(hostBuilderReversed.Build().Services.GetService<ITransportFactory>());
}
}
}

0 comments on commit 526dfdb

Please sign in to comment.