private void Initialize() { Host = new TServiceHost(); BasePort = ServiceArguments.BasePortOverride ?? GetBasePortFromHttpServiceAttribute(); SiloStopped = Task.Run(() => Host.Run(ServiceArguments)); //Silo is ready or failed to start Task.WaitAny(SiloStopped, Host.WaitForServiceStartedAsync()); if (SiloStopped.IsFaulted) { try { // Flatten Aggregated exception SiloStopped.GetAwaiter().GetResult(); } catch (Exception e) { throw new Exception("Silo Failed to start", e); } } else if (SiloStopped.IsCompleted) { throw new Exception("Silo Failed to start"); } }
public override void Dispose() { _clusterClient?.Dispose(); Host.Stop(); // don't use host.dispose, host.stop should do all the work var siloStopTimeout = TimeSpan.FromSeconds(60); var completed = SiloStopped.Wait(siloStopTimeout); if (!completed) { throw new TimeoutException($"ServiceTester: The service failed to shutdown within the {siloStopTimeout.TotalSeconds} seconds limit."); } var waitStopped = Host.WaitForServiceGracefullyStoppedAsync(); // We aren't actually waiting? if (waitStopped.IsCompleted && waitStopped.Result == StopResult.Force) { throw new TimeoutException("ServiceTester: The service failed to shutdown gracefully."); } base.Dispose(); }