diff --git a/Gigya.Microdot.Hosting/Service/ServiceHostBase.cs b/Gigya.Microdot.Hosting/Service/ServiceHostBase.cs index ea14e24e..32755110 100644 --- a/Gigya.Microdot.Hosting/Service/ServiceHostBase.cs +++ b/Gigya.Microdot.Hosting/Service/ServiceHostBase.cs @@ -179,7 +179,9 @@ public void Run(ServiceArguments argumentsOverride = null) StopEvent.WaitOne(); Console.WriteLine(" *** Shutting down... *** "); - Task.Run(() => OnStop()).Wait(Arguments.OnStopWaitTime ?? TimeSpan.FromSeconds(10)); + + + Task.Run(() => OnStop()).Wait(TimeSpan.FromSeconds(Arguments.OnStopWaitTimeSec + Arguments.ServiceDrainTimeSec ?? 0)); ServiceStartedEvent = new TaskCompletionSource(); ServiceStoppedEvent.SetResult(null); diff --git a/Gigya.Microdot.SharedLogic/ServiceArguments.cs b/Gigya.Microdot.SharedLogic/ServiceArguments.cs index 97d507f2..c599d9ea 100644 --- a/Gigya.Microdot.SharedLogic/ServiceArguments.cs +++ b/Gigya.Microdot.SharedLogic/ServiceArguments.cs @@ -74,10 +74,11 @@ public class ServiceArguments /// Specifies drain time in this time the servcie status will be 521. /// public int? ServiceDrainTimeSec { get; } + /// - /// Defines wait time before service is stoping, default is 10 seconds. + /// Defines the time to wait for the service to stop, default is 10 seconds. Only after OnStopWaitTimeSec+ServiceDrainTimeSec the service will be forcibly closed. /// - public TimeSpan? OnStopWaitTime { get; } + public int? OnStopWaitTimeSec { get; set; } /// /// An array of processor IDs the service should run on, otherwise null if none are is specified. This also affects the degree @@ -98,7 +99,7 @@ public ServiceArguments(ServiceStartupMode serviceStartupMode = ServiceStartupMo ConsoleOutputMode consoleOutputMode = ConsoleOutputMode.Unspecified, SiloClusterMode siloClusterMode = SiloClusterMode.Unspecified, int? basePortOverride = null, string instanceName = null, - int? shutdownWhenPidExits = null, int? slotNumber = null, TimeSpan? onStopWaitTimeInMs=null,int? serviceDrainTime=null) + int? shutdownWhenPidExits = null, int? slotNumber = null, int? shutdownWaitTimeSec=null,int? serviceDrainTimeSec=null) { ServiceStartupMode = serviceStartupMode; ConsoleOutputMode = consoleOutputMode; @@ -107,8 +108,8 @@ public ServiceArguments(ServiceStartupMode serviceStartupMode = ServiceStartupMo InstanceName = instanceName; ShutdownWhenPidExits = shutdownWhenPidExits; SlotNumber = slotNumber; - OnStopWaitTime = onStopWaitTimeInMs; - ServiceDrainTimeSec = serviceDrainTime; + OnStopWaitTimeSec = shutdownWaitTimeSec; + ServiceDrainTimeSec = serviceDrainTimeSec; ApplyDefaults(); } @@ -126,13 +127,12 @@ public ServiceArguments(string[] args) InstanceName = ParseStringArg(nameof(InstanceName), args); ShutdownWhenPidExits = TryParseInt(ParseStringArg(nameof(ShutdownWhenPidExits), args)); SlotNumber = TryParseInt(ParseStringArg(nameof(SlotNumber), args)); - OnStopWaitTime = TryParseTimeSpan(ParseStringArg(nameof(OnStopWaitTime), args)); + OnStopWaitTimeSec = TryParseInt(ParseStringArg(nameof(OnStopWaitTimeSec), args)); ServiceDrainTimeSec = TryParseInt(ParseStringArg(nameof(ServiceDrainTimeSec), args)); ProcessorAffinity = ParseProcessorIds(ParseStringArg(nameof(ProcessorAffinity), args)); ApplyDefaults(); } - private static TimeSpan? TryParseTimeSpan(string str) { return TimeSpan.TryParse(str, out TimeSpan val) ? (TimeSpan?)val : null; } private static int? TryParseInt(string str) { return int.TryParse(str, out int val) ? (int?)val : null; } @@ -201,6 +201,10 @@ private void ApplyDefaults() throw new ArgumentOutOfRangeException(); } } + + if (OnStopWaitTimeSec == null) + OnStopWaitTimeSec = 10; + // ReSharper restore SwitchStatementMissingSomeCases } diff --git a/Gigya.Microdot.Testing.Shared/Service/NonOrleansServiceTester.cs b/Gigya.Microdot.Testing.Shared/Service/NonOrleansServiceTester.cs index 1706ea68..229f3046 100644 --- a/Gigya.Microdot.Testing.Shared/Service/NonOrleansServiceTester.cs +++ b/Gigya.Microdot.Testing.Shared/Service/NonOrleansServiceTester.cs @@ -35,7 +35,7 @@ namespace Gigya.Microdot.Testing.Shared.Service public NonOrleansServiceTester(int basePortOverride, IResolutionRoot resolutionRoot, TimeSpan? shutdownWaitTime = null) { - var serviceArguments = GetServiceArguments(basePortOverride, false, shutdownWaitTime); + var serviceArguments = GetServiceArguments(basePortOverride, false, shutdownWaitTime.HasValue?(int?)shutdownWaitTime.Value.TotalSeconds:null); BasePort = basePortOverride; ResolutionRoot = resolutionRoot; diff --git a/Gigya.Microdot.Testing.Shared/Service/ServiceTesterBase.cs b/Gigya.Microdot.Testing.Shared/Service/ServiceTesterBase.cs index 35b44199..6b1e090b 100644 --- a/Gigya.Microdot.Testing.Shared/Service/ServiceTesterBase.cs +++ b/Gigya.Microdot.Testing.Shared/Service/ServiceTesterBase.cs @@ -112,23 +112,23 @@ public virtual ServiceProxyProvider GetServiceProxyProvider(string serviceName, return provider; } - protected virtual ServiceArguments GetServiceArguments(int? basePortOverride, bool isSecondary, TimeSpan? shutdownWaitTime) + protected virtual ServiceArguments GetServiceArguments(int? basePortOverride, bool isSecondary, int? shutdownWaitTime) { if (isSecondary && basePortOverride == null) throw new ArgumentException("You must specify a basePortOverride when running a secondary silo."); var siloClusterMode = isSecondary ? SiloClusterMode.SecondaryNode : SiloClusterMode.PrimaryNode; - ServiceArguments arguments = new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, basePortOverride: basePortOverride, siloClusterMode: siloClusterMode, onStopWaitTimeInMs: shutdownWaitTime); + ServiceArguments arguments = new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, basePortOverride: basePortOverride, siloClusterMode: siloClusterMode, shutdownWaitTimeSec: shutdownWaitTime); if (basePortOverride != null) return arguments; - var serviceArguments = new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, siloClusterMode: siloClusterMode, onStopWaitTimeInMs: shutdownWaitTime); + var serviceArguments = new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, siloClusterMode: siloClusterMode, shutdownWaitTimeSec: shutdownWaitTime); var commonConfig = new BaseCommonConfig(serviceArguments); var mapper = new OrleansServiceInterfaceMapper(new AssemblyProvider(new ApplicationDirectoryProvider(commonConfig), commonConfig, Log)); var basePort = mapper.ServiceInterfaceTypes.First().GetCustomAttribute().BasePort; - return new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, basePortOverride: basePort, onStopWaitTimeInMs: shutdownWaitTime); + return new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, basePortOverride: basePort, shutdownWaitTimeSec: shutdownWaitTime); } public abstract void Dispose(); diff --git a/Gigya.Microdot.Testing.Shared/Service/ServiceTesterExtensions.cs b/Gigya.Microdot.Testing.Shared/Service/ServiceTesterExtensions.cs index 4b6f8d18..307cabfa 100644 --- a/Gigya.Microdot.Testing.Shared/Service/ServiceTesterExtensions.cs +++ b/Gigya.Microdot.Testing.Shared/Service/ServiceTesterExtensions.cs @@ -35,8 +35,7 @@ public static NonOrleansServiceTester GetServiceTesterForNonOrlean { NonOrleansServiceTester tester = kernel.Get>( new ConstructorArgument(nameof(basePortOverride), basePortOverride), - new ConstructorArgument(nameof(shutdownWaitTime), shutdownWaitTime) - ); + new ConstructorArgument(nameof(shutdownWaitTime),shutdownWaitTime)); return tester; } diff --git a/Gigya.Microdot.Testing/Service/ServiceTester.cs b/Gigya.Microdot.Testing/Service/ServiceTester.cs index 457afc86..ebb1ab9b 100644 --- a/Gigya.Microdot.Testing/Service/ServiceTester.cs +++ b/Gigya.Microdot.Testing/Service/ServiceTester.cs @@ -55,14 +55,14 @@ namespace Gigya.Microdot.Testing.Service private HttpListener LogListener { get; set; } - public ServiceTester(int? basePortOverride, bool isSecondary, ILog log, IResolutionRoot resolutionRoot, TimeSpan? shutdownWaitTime = null, bool writeLogToFile = false,int? serviceDrainTime=null) + public ServiceTester(int? basePortOverride, bool isSecondary, ILog log, IResolutionRoot resolutionRoot, TimeSpan? shutdownWaitTime = null, bool writeLogToFile = false,int? serviceDrainTimeSec=null) { Log = log; ResolutionRoot = resolutionRoot; // ReSharper disable VirtualMemberCallInContructor InitializeInfrastructure(); - var serviceArguments = GetServiceArguments(basePortOverride, isSecondary, shutdownWaitTime,serviceDrainTime); + var serviceArguments = GetServiceArguments(basePortOverride, isSecondary, shutdownWaitTime.HasValue?(int?)shutdownWaitTime.Value.TotalSeconds:null,serviceDrainTimeSec); BasePort = serviceArguments.BasePortOverride.Value; ServiceAppDomain = Common.CreateDomain(typeof(TServiceHost).Name + BasePort); @@ -202,23 +202,23 @@ protected virtual void InitializeInfrastructure() } - protected virtual ServiceArguments GetServiceArguments(int? basePortOverride, bool isSecondary, TimeSpan? shutdownWaitTime,int? serviceDrainTime) + protected virtual ServiceArguments GetServiceArguments(int? basePortOverride, bool isSecondary, int? shutdownWaitTime,int? serviceDrainTime) { if (isSecondary && basePortOverride == null) throw new ArgumentException("You must specify a basePortOverride when running a secondary silo."); var siloClusterMode = isSecondary ? SiloClusterMode.SecondaryNode : SiloClusterMode.PrimaryNode; - ServiceArguments arguments = new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, basePortOverride: basePortOverride, siloClusterMode: siloClusterMode, onStopWaitTimeInMs: shutdownWaitTime,serviceDrainTime:serviceDrainTime); + ServiceArguments arguments = new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, basePortOverride: basePortOverride, siloClusterMode: siloClusterMode, shutdownWaitTimeSec: shutdownWaitTime,serviceDrainTimeSec:serviceDrainTime); if (basePortOverride != null) return arguments; - var serviceArguments = new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, siloClusterMode: siloClusterMode, onStopWaitTimeInMs: shutdownWaitTime,serviceDrainTime:serviceDrainTime); + var serviceArguments = new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, siloClusterMode: siloClusterMode, shutdownWaitTimeSec: shutdownWaitTime,serviceDrainTimeSec:serviceDrainTime); var commonConfig = new BaseCommonConfig(serviceArguments); var mapper = new OrleansServiceInterfaceMapper(new AssemblyProvider(new ApplicationDirectoryProvider(commonConfig), commonConfig, Log)); var basePort = mapper.ServiceInterfaceTypes.First().GetCustomAttribute().BasePort; - return new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, basePortOverride: basePort, onStopWaitTimeInMs: shutdownWaitTime,serviceDrainTime:serviceDrainTime); + return new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive, basePortOverride: basePort, shutdownWaitTimeSec: shutdownWaitTime,serviceDrainTimeSec:serviceDrainTime); } @@ -315,7 +315,7 @@ public class TestTraceConfiguration : ITraceConfiguration public static class ServiceTesterExtensions { - public static ServiceTester GetServiceTester(this IResolutionRoot kernel, int? basePortOverride = null, bool isSecondary = false, TimeSpan? shutdownWaitTime = null, bool writeLogToFile = false,int? serviceDrainTime=null) + public static ServiceTester GetServiceTester(this IResolutionRoot kernel, int? basePortOverride = null, bool isSecondary = false, TimeSpan? shutdownWaitTime = null, bool writeLogToFile = false,int? serviceDrainTimeSec=null) where TServiceHost : MicrodotOrleansServiceHost, new() { ServiceTester tester = kernel.Get>( @@ -323,7 +323,7 @@ public static ServiceTester GetServiceTester(this IR new ConstructorArgument(nameof(isSecondary), isSecondary), new ConstructorArgument(nameof(shutdownWaitTime), shutdownWaitTime), new ConstructorArgument(nameof(writeLogToFile), writeLogToFile), - new ConstructorArgument(nameof(serviceDrainTime), serviceDrainTime) + new ConstructorArgument(nameof(serviceDrainTimeSec), serviceDrainTimeSec) ); return tester; diff --git a/SolutionVersion.cs b/SolutionVersion.cs index 0faa1fa6..14ed1a8e 100644 --- a/SolutionVersion.cs +++ b/SolutionVersion.cs @@ -28,9 +28,9 @@ [assembly: AssemblyCopyright("© 2018 Gigya Inc.")] [assembly: AssemblyDescription("Microdot Framework")] -[assembly: AssemblyVersion("1.10.3.0")] -[assembly: AssemblyFileVersion("1.10.3.0")] -[assembly: AssemblyInformationalVersion("1.10.3.0")] +[assembly: AssemblyVersion("1.10.4.0")] +[assembly: AssemblyFileVersion("1.10.4.0")] +[assembly: AssemblyInformationalVersion("1.10.4.0")] // Setting ComVisible to false makes the types in this assembly not visible diff --git a/tests/Gigya.Microdot.Hosting.UnitTests/NonOrleansMicroService/MicroServiceTests.cs b/tests/Gigya.Microdot.Hosting.UnitTests/NonOrleansMicroService/MicroServiceTests.cs index 60adf5c6..c8d1cc0f 100644 --- a/tests/Gigya.Microdot.Hosting.UnitTests/NonOrleansMicroService/MicroServiceTests.cs +++ b/tests/Gigya.Microdot.Hosting.UnitTests/NonOrleansMicroService/MicroServiceTests.cs @@ -17,11 +17,20 @@ public class MicroServiceTests [Test] public async Task ShouldCallSelfHostServcie() { + NonOrleansServiceTester serviceTester = null; var testingKernel = new TestingKernel(); - var serviceTester = testingKernel.GetServiceTesterForNonOrleansService(1111, TimeSpan.FromSeconds(10)); + try + { + serviceTester = testingKernel.GetServiceTesterForNonOrleansService(1111, TimeSpan.FromSeconds(10)); + (await serviceTester.GetServiceProxy().Add(1, 2)).ShouldBe(3); + } + finally + { + serviceTester?.Dispose(); + testingKernel.Dispose(); + } + - (await serviceTester.GetServiceProxy().Add(1, 2)).ShouldBe(3); - serviceTester.Dispose(); } } diff --git a/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/HealthCheckTests.cs b/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/HealthCheckTests.cs index 0a8c64b8..7c212ed7 100644 --- a/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/HealthCheckTests.cs +++ b/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/HealthCheckTests.cs @@ -38,11 +38,11 @@ public class HealthCheckTests { private ServiceTester tester; - + private int mainPort = 9555; [OneTimeSetUp] public void SetUp() { - tester = AssemblyInitialize.ResolutionRoot.GetServiceTester(); + tester = AssemblyInitialize.ResolutionRoot.GetServiceTester(mainPort); } [OneTimeTearDown] @@ -55,7 +55,7 @@ public void TearDown() public async Task HealthCheck_ServcieDrain_StatueShouldBe521() { int port = 6755;//prevent prot collision, more then one silo is runing at the same time in this TestFixture. - var customServiceTester = AssemblyInitialize.ResolutionRoot.GetServiceTester(basePortOverride: port, serviceDrainTime: 10); + var customServiceTester = AssemblyInitialize.ResolutionRoot.GetServiceTester(basePortOverride: port, serviceDrainTimeSec: 10); var dispose = Task.Run(() => customServiceTester.Dispose()); await Task.Delay(200); @@ -69,7 +69,7 @@ public async Task HealthCheck_ServcieDrain_StatueShouldBe521() public void HealthCheck_NotHealthy_ShouldReturn500() { tester.GetGrainClient(0).SetHealth(false); - var httpResponseMessage = new HttpClient().GetAsync(new Uri($"http://{CurrentApplicationInfo.HostName}:6555/{nameof(IProgrammableHealth).Substring(1)}.status")).Result; + var httpResponseMessage = new HttpClient().GetAsync(new Uri($"http://{CurrentApplicationInfo.HostName}:{mainPort}/{nameof(IProgrammableHealth).Substring(1)}.status")).Result; httpResponseMessage.StatusCode.ShouldBe(HttpStatusCode.InternalServerError); } @@ -77,14 +77,14 @@ public void HealthCheck_NotHealthy_ShouldReturn500() public void HealthCheck_Healthy_ShouldReturn200() { tester.GetGrainClient(0).SetHealth(true); - var httpResponseMessage = new HttpClient().GetAsync(new Uri($"http://{CurrentApplicationInfo.HostName}:6555/{nameof(IProgrammableHealth).Substring(1)}.status")).Result; + var httpResponseMessage = new HttpClient().GetAsync(new Uri($"http://{CurrentApplicationInfo.HostName}:{mainPort}/{nameof(IProgrammableHealth).Substring(1)}.status")).Result; httpResponseMessage.StatusCode.ShouldBe(HttpStatusCode.OK); } [Test] public void HealthCheck_NotImplemented_ShouldReturn200() { - var httpResponseMessage = new HttpClient().GetAsync(new Uri($"http://{CurrentApplicationInfo.HostName}:6555/{nameof(ICalculatorService).Substring(1)}.status")).Result; + var httpResponseMessage = new HttpClient().GetAsync(new Uri($"http://{CurrentApplicationInfo.HostName}:{mainPort}/{nameof(ICalculatorService).Substring(1)}.status")).Result; httpResponseMessage.StatusCode.ShouldBe(HttpStatusCode.OK); httpResponseMessage.Content.ShouldNotBeNull(); } diff --git a/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/SchemaEndpointTests.cs b/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/SchemaEndpointTests.cs index 403c234e..0999b5d6 100644 --- a/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/SchemaEndpointTests.cs +++ b/tests/Gigya.Microdot.Orleans.Hosting.UnitTests/SchemaEndpointTests.cs @@ -43,7 +43,7 @@ public void SetUp() { try { - _tester = AssemblyInitialize.ResolutionRoot.GetServiceTester(); + _tester = AssemblyInitialize.ResolutionRoot.GetServiceTester(8555); _serviceProxyProvider = _tester.GetServiceProxyProvider("CalculatorService"); } catch (Exception e) diff --git a/tests/Gigya.Microdot.UnitTests/Caching/Host/CachingProxyTests.cs b/tests/Gigya.Microdot.UnitTests/Caching/Host/CachingProxyTests.cs index c8fbcc17..9798b49d 100644 --- a/tests/Gigya.Microdot.UnitTests/Caching/Host/CachingProxyTests.cs +++ b/tests/Gigya.Microdot.UnitTests/Caching/Host/CachingProxyTests.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Gigya.Microdot.Hosting.Service; +using Gigya.Microdot.SharedLogic; using Ninject; using NUnit.Framework; using Shouldly; @@ -37,7 +38,7 @@ public void SetUp() try { Host = new SlowServiceHost(k => { Service = k.Get(); }); - StopTask = Host.RunAsync(); + StopTask = Host.RunAsync(new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive)); } catch (Exception ex) { diff --git a/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/HttpServiceListenerTests.cs b/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/HttpServiceListenerTests.cs index 9d1ef8e3..95f227f0 100644 --- a/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/HttpServiceListenerTests.cs +++ b/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/HttpServiceListenerTests.cs @@ -11,6 +11,7 @@ using Gigya.Common.Contracts.Exceptions; using Gigya.Microdot.Fakes; using Gigya.Microdot.Hosting.Service; +using Gigya.Microdot.SharedLogic; using Gigya.Microdot.SharedLogic.Events; using Gigya.Microdot.SharedLogic.Exceptions; using Gigya.Microdot.Testing; @@ -54,7 +55,7 @@ public virtual void SetUp() TracingContext.SetRequestID("1"); _testinghost = new TestingHost(); - _stopTask = _testinghost.RunAsync(); + _stopTask = _testinghost.RunAsync(new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive)); } diff --git a/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/MetricsTests.cs b/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/MetricsTests.cs index 007ba6fd..1163fe95 100644 --- a/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/MetricsTests.cs +++ b/tests/Gigya.Microdot.UnitTests/ServiceListenerTests/MetricsTests.cs @@ -51,7 +51,7 @@ public void TearDown() public void TestMetricsOnSuccess() { TestingHost testinghost = new TestingHost(); - var task = testinghost.RunAsync(); + var task = testinghost.RunAsync(new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive)); testinghost.Instance.Increment(0).Returns((ulong)1); @@ -73,7 +73,7 @@ public void TestMetricsOnSuccess() public void TestMetricsOnFailure() { TestingHost testinghost = new TestingHost(); - var task = testinghost.RunAsync(); + var task = testinghost.RunAsync(new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive)); testinghost.Instance.When(a => a.DoSomething()).Do(x => { throw new Exception(); });