예제 #1
0
        public async Task Given_A_Healthy_Endpoint_When_The_Healthcheck_Is_Performed_Then_The_Correct_Service_Instance_Is_Reported()
        {
            var reportHealth     = Substitute.For <IReportHealth>();
            var healthcheckQuery = new FindHealthcheckEndpointsQueryBuilder().Build(1);
            var healthcheckJob   = CreateHealthcheckJob(findHealthcheckQuery: healthcheckQuery, reportHealth: reportHealth);

            await healthcheckJob.Execute(null);

            reportHealth.Received().ReportHealthy(healthcheckQuery.HealthcheckEndpoints[0].InstanceIdentifier);
        }
예제 #2
0
        public async Task Given_Multiple_Unhealthy_Healthcheck_Endpoints_When_The_Healthchecks_Are_Performed_Then_All_Endpoints_Are_Reported_Unhealthy()
        {
            var reportHealth      = Substitute.For <IReportHealth>();
            var healthcheckClient = Substitute.For <IHealthcheckClient>();
            var healthcheckQuery  = new FindHealthcheckEndpointsQueryBuilder().Build(5);
            var healthcheckJob    = CreateHealthcheckJob(findHealthcheckQuery: healthcheckQuery, reportHealth: reportHealth, healthcheckClient: healthcheckClient);

            healthcheckClient.GetHealthcheck(Arg.Any <Uri>())
            .Returns(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable));

            await healthcheckJob.Execute(null);

            reportHealth.Received(5).ReportError(Arg.Any <InstanceIdentifier>());
        }
예제 #3
0
        public async Task Given_Multiple_Healthcheck_Endpoints_When_The_Healthchecks_Are_Performed_And_One_Throws_An_Exception_Then_The_Other_Healthchecks_Are_Unaffected()
        {
            var reportHealth      = Substitute.For <IReportHealth>();
            var healthcheckClient = Substitute.For <IHealthcheckClient>();
            var healthcheckQuery  = new FindHealthcheckEndpointsQueryBuilder().Build(5);
            var healthcheckJob    = CreateHealthcheckJob(findHealthcheckQuery: healthcheckQuery, reportHealth: reportHealth, healthcheckClient: healthcheckClient);

            healthcheckClient.GetHealthcheck(Arg.Any <Uri>())
            .Returns(new HttpResponseMessage(HttpStatusCode.OK));

            healthcheckClient.GetHealthcheck(healthcheckQuery.HealthcheckEndpoints[2].HealthcheckUri)
            .Throws(new InvalidOperationException());

            await healthcheckJob.Execute(null);

            reportHealth.Received(4).ReportHealthy(Arg.Any <InstanceIdentifier>());
        }
예제 #4
0
        private HealthcheckScheduledJob CreateHealthcheckJob(IFindHealthcheckEndpointsQuery findHealthcheckQuery = null, IReportHealth reportHealth = null, IHealthcheckClient healthcheckClient = null)
        {
            if (findHealthcheckQuery == null)
            {
                var findHealtcheckQueryBuilder = new FindHealthcheckEndpointsQueryBuilder();
                findHealthcheckQuery = findHealtcheckQueryBuilder.Build();
            }

            if (reportHealth == null)
            {
                reportHealth = Substitute.For <IReportHealth>();
            }

            if (healthcheckClient == null)
            {
                healthcheckClient = Substitute.For <IHealthcheckClient>();

                healthcheckClient.GetHealthcheck(Arg.Any <Uri>())
                .Returns(new HttpResponseMessage(HttpStatusCode.OK));
            }

            return(new HealthcheckScheduledJob(findHealthcheckQuery, reportHealth, healthcheckClient));
        }