public async Task response_http_status_serviceunavailable_when_beat_pulse_service_is_not_healthy() { string defaultName; string defaultPath; var healthCheck = new ActionLiveness((cancellationToken) => Task.FromResult(LivenessResult.UnHealthy("Some message when service is not available"))); var webHostBuilder = new WebHostBuilder() .UseBeatPulse() .UseStartup <DefaultStartup>() .ConfigureServices(svc => { svc.AddBeatPulse(context => { context.AddLiveness(nameof(defaultName), opt => { opt.UsePath(nameof(defaultPath)); opt.UseLiveness(healthCheck); }); }); }); var server = new TestServer(webHostBuilder); var response = await server.CreateClient() .GetAsync(BeatPulseKeys.BEATPULSE_DEFAULT_PATH); var responseStatus = response.StatusCode; responseStatus.Should() .Be(HttpStatusCode.ServiceUnavailable); (await response.Content.ReadAsStringAsync()).Should() .Be(Enum.GetName(typeof(HttpStatusCode), responseStatus)); }
public async Task break_the_liveness_execution_if_detailed_output_is_disabled() { var check1IsExecuted = false; var check2IsExecuted = false; var healthCheck1 = new ActionLiveness( (cancellationToken) => { check1IsExecuted = true; return(Task.FromResult(LivenessResult.UnHealthy("custom check1 is not working"))); }); var healthCheck2 = new ActionLiveness( (cancellationToken) => { check2IsExecuted = false; return(Task.FromResult(LivenessResult.Healthy())); }); var webHostBuilder = new WebHostBuilder() .UseBeatPulse() .UseStartup <DefaultStartup>() .ConfigureServices(svc => { svc.AddBeatPulse(context => { context.AddLiveness("check1", opt => { opt.UsePath("check1"); opt.UseLiveness(healthCheck1); }); context.AddLiveness("check2", opt => { opt.UsePath("check2"); opt.UseLiveness(healthCheck2); }); }); }); var server = new TestServer(webHostBuilder); var response = await server.CreateClient() .GetAsync(BeatPulseKeys.BEATPULSE_DEFAULT_PATH); response.StatusCode .Should().Be(StatusCodes.Status503ServiceUnavailable); check1IsExecuted.Should().BeTrue(); check2IsExecuted.Should().BeFalse(); }
public async Task response_http_status_serviceunavailable_when_beat_pulse_service_beat_pulse_execution_is_timeout() { string defaultName; string defaultPath; var healthCheck = new ActionLiveness( async(cancellationToken) => { await Task.Delay(100); return(LivenessResult.Healthy()); }); var webHostBuilder = new WebHostBuilder() .UseBeatPulse(options => options.ConfigureTimeout(50)) .UseStartup <DefaultStartup>() .ConfigureServices(svc => { svc.AddBeatPulse(context => { context.AddLiveness(nameof(defaultName), opt => { opt.UsePath(nameof(defaultPath)); opt.UseLiveness(healthCheck); }); }); }); var server = new TestServer(webHostBuilder); var response = await server.CreateClient() .GetAsync(BeatPulseKeys.BEATPULSE_DEFAULT_PATH); var expected = HttpStatusCode.ServiceUnavailable; response.StatusCode .Should() .Be(expected); (await response.Content.ReadAsStringAsync()).Should() .Be(Enum.GetName(typeof(HttpStatusCode), expected)); }
public async Task response_http_status_ok_and_detailed_information_when_beat_pulse_service_is_healthy_and_detailed_information_is_configured() { string defaultName; string defaultPath; var healthCheck = new ActionLiveness((cancellationToken) => Task.FromResult(LivenessResult.Healthy())); var webHostBuilder = new WebHostBuilder() .UseBeatPulse(options => options.ConfigureDetailedOutput()) .UseStartup <DefaultStartup>() .ConfigureServices(svc => { svc.AddBeatPulse(context => { context.AddLiveness(nameof(defaultName), opt => { opt.UsePath(nameof(defaultPath)); opt.UseLiveness(healthCheck); }); }); }); var server = new TestServer(webHostBuilder); var response = await server.CreateClient() .GetAsync(BeatPulseKeys.BEATPULSE_DEFAULT_PATH); response.StatusCode .Should() .Be(HttpStatusCode.OK); var content = await response.Content.ReadAsStringAsync(); JsonConvert.DeserializeObject <OutputMessage>(content) .Should().NotBeNull(); }