Add UseShutdownTimeout Extension (#1086)
This commit is contained in:
parent
419ec53d07
commit
03bdb40f8a
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
|
|
@ -158,6 +159,17 @@ namespace Microsoft.AspNetCore.Hosting
|
|||
return hostBuilder.UseSetting(WebHostDefaults.PreferHostingUrlsKey, preferHostingUrls ? "true" : "false");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specify the amount of time to wait for the web host to shutdown.
|
||||
/// </summary>
|
||||
/// <param name="hostBuilder">The <see cref="IWebHostBuilder"/> to configure.</param>
|
||||
/// <param name="timeout">The amount of time to wait for server shutdown.</param>
|
||||
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
|
||||
public static IWebHostBuilder UseShutdownTimeout(this IWebHostBuilder hostBuilder, TimeSpan timeout)
|
||||
{
|
||||
return hostBuilder.UseSetting(WebHostDefaults.ShutdownTimeoutKey, ((int)timeout.TotalSeconds).ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the web host and listen on the specified urls.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1036,6 +1036,21 @@ namespace Microsoft.AspNetCore.Hosting
|
|||
Assert.Throws<ArgumentException>(() => new HostingStartupAttribute(typeof(WebHostTests)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UseShutdownTimeoutConfiguresShutdownTimeout()
|
||||
{
|
||||
var builder = CreateWebHostBuilder()
|
||||
.CaptureStartupErrors(false)
|
||||
.UseShutdownTimeout(TimeSpan.FromSeconds(102))
|
||||
.Configure(app => { })
|
||||
.UseServer(new TestServer());
|
||||
|
||||
using (var host = (WebHost)builder.Build())
|
||||
{
|
||||
Assert.Equal(TimeSpan.FromSeconds(102), host.Options.ShutdownTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
private static void StaticConfigureMethod(IApplicationBuilder app) { }
|
||||
|
||||
private IWebHostBuilder CreateWebHostBuilder()
|
||||
|
|
|
|||
Loading…
Reference in New Issue