public override void Dispose() { if (GrainClient.IsInitialized) { GrainClient.Uninitialize(); } if (ServiceAppDomain != null) { ServiceAppDomain.RunOnContext(() => { Host.Stop(); Host.Dispose(); var completed = StopTask.Wait(60000); if (!completed) { throw new TimeoutException("ServiceTester: The service failed to shutdown within the 60 second limit."); } }); Kill(); } LogListener.Close(); }
public ServiceTester(int?basePortOverride, bool isSecondary, ILog log, IResolutionRoot resolutionRoot, TimeSpan?shutdownWaitTime = null, bool writeLogToFile = false) { Log = log; ResolutionRoot = resolutionRoot; // ReSharper disable VirtualMemberCallInContructor InitializeInfrastructure(); var serviceArguments = GetServiceArguments(basePortOverride, isSecondary, shutdownWaitTime); BasePort = serviceArguments.BasePortOverride.Value; ServiceAppDomain = Common.CreateDomain(typeof(TServiceHost).Name + BasePort); StartLogListener(BasePort, ServiceAppDomain, writeLogToFile); ServiceAppDomain.RunOnContext(serviceArguments, args => { Host?.Stop(); Host?.Dispose(); Host = new TServiceHost(); StopTask = Host.RunAsync(args); }); }
public override void Dispose() { if (GrainClient.IsInitialized) { GrainClient.Uninitialize(); } try { if (ServiceAppDomain != null) { ServiceAppDomain.RunOnContext(() => { Host.Stop(); //don't use host.dispose, host.stop should do all the work var completed = StopTask.Wait(60000); if (!completed) { throw new TimeoutException("ServiceTester: The service failed to shutdown within the 60 second limit."); } if (Host.WaitForServiceGracefullyStoppedAsync().IsCompleted&& Host.WaitForServiceGracefullyStoppedAsync().Result == StopResult.Force) { throw new TimeoutException("ServiceTester: The service failed to shutdown gracefully."); } }); Kill(); } } finally { LogListener.Close(); } }