From d1a1897fff4b5a3b4374402c6de3d0e345ccff52 Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Mon, 19 Feb 2018 11:55:09 +0000 Subject: [PATCH] added configuration for start and stop timeout --- .../Configuration_Specs.cs | 46 ++++++++++++++++++ .../ConfigurationExtensions.cs | 8 ++++ .../Options/StartTimeoutOption.cs | 47 +++++++++++++++++++ .../Options/StopTimeoutOption.cs | 47 +++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 src/Topshelf.Extensions.Configuration/Options/StartTimeoutOption.cs create mode 100644 src/Topshelf.Extensions.Configuration/Options/StopTimeoutOption.cs diff --git a/src/Topshelf.Extensions.Configuration.Tests/Configuration_Specs.cs b/src/Topshelf.Extensions.Configuration.Tests/Configuration_Specs.cs index 1ba7944f..c0903118 100644 --- a/src/Topshelf.Extensions.Configuration.Tests/Configuration_Specs.cs +++ b/src/Topshelf.Extensions.Configuration.Tests/Configuration_Specs.cs @@ -410,6 +410,52 @@ public void Should_create_a_service_that_runs_as_network_service() Assert.AreEqual("", installHost.InstallSettings.Credentials.Password); } + [Test] + public void Should_create_a_service_that_has_start_timeout() + { + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "topshelf:StartTimeout", "123" }, + }) + .Build() + .GetSection("topshelf"); + + Host host = HostFactory.New(x => + { + x.Service(); + x.ApplyConfiguration(configuration); + x.ApplyCommandLine("install"); + }); + + Assert.IsInstanceOf(host); + var installHost = (InstallHost)host; + Assert.AreEqual(TimeSpan.FromSeconds(123), installHost.InstallSettings.StartTimeOut); + } + + [Test] + public void Should_create_a_service_that_has_stopt_timeout() + { + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "topshelf:StopTimeout", "123" }, + }) + .Build() + .GetSection("topshelf"); + + Host host = HostFactory.New(x => + { + x.Service(); + x.ApplyConfiguration(configuration); + x.ApplyCommandLine("install"); + }); + + Assert.IsInstanceOf(host); + var installHost = (InstallHost)host; + Assert.AreEqual(TimeSpan.FromSeconds(123), installHost.InstallSettings.StopTimeOut); + } + [Test] public void Should_create_a_service_with_recovery_options() { diff --git a/src/Topshelf.Extensions.Configuration/ConfigurationExtensions.cs b/src/Topshelf.Extensions.Configuration/ConfigurationExtensions.cs index ed7d0fb5..bb1aef05 100644 --- a/src/Topshelf.Extensions.Configuration/ConfigurationExtensions.cs +++ b/src/Topshelf.Extensions.Configuration/ConfigurationExtensions.cs @@ -87,6 +87,14 @@ public static IEnumerable