private async Task ProcessRegions(string path, IEnumerable <RegionModel> regions)
        {
            foreach (var region in regions)
            {
                var regionHealthEndpoint = new Uri(region.RegionEndpoint.Replace("{0}", $"{nameof(HealthMonitoringProcessor)}.{nameof(ProcessRegions)}.{Guid.NewGuid().ToString()}", StringComparison.OrdinalIgnoreCase));

                var isHealthy = await healthCheckerService.IsHealthy(regionHealthEndpoint, region.PageRegion == Data.Enums.PageRegion.Body, MediaTypeNames.Text.Html).ConfigureAwait(false);

                if (isHealthy)
                {
                    logger.LogInformation($"Starting to mark {regionHealthEndpoint} as healthy");
                    await appRegistryService.MarkRegionAsHealthy(path, region.PageRegion).ConfigureAwait(false);

                    logger.LogInformation($"Completed marking {regionHealthEndpoint} as healthy");
                }
            }
        }
示例#2
0
        public async Task ProcessWhenUnhealthyEndpointThenMarkedAsHealthy(bool isHealthy, bool healthCheckRequired, bool markAsHealthyCalled)
        {
            // Arrange
            const string expectedRegionEndpoint = "https://expectedHost/regionEndpoint";

            var listOfPaths = new List <AppRegistryModel>
            {
                new AppRegistryModel
                {
                    Path    = "Path1",
                    Regions = new List <RegionModel>()
                    {
                        new RegionModel()
                        {
                            RegionEndpoint      = expectedRegionEndpoint,
                            HealthCheckRequired = healthCheckRequired,
                            IsHealthy           = isHealthy,
                            PageRegion          = PageRegion.Body,
                        },
                        new RegionModel
                        {
                            RegionEndpoint      = expectedRegionEndpoint,
                            HealthCheckRequired = healthCheckRequired,
                            IsHealthy           = isHealthy,
                            PageRegion          = PageRegion.Body,
                        },
                    },
                    AjaxRequests = new List <AjaxRequestModel>()
                    {
                        new AjaxRequestModel()
                        {
                            AjaxEndpoint        = expectedRegionEndpoint,
                            HealthCheckRequired = healthCheckRequired,
                            IsHealthy           = isHealthy,
                            Name = "ajax-1",
                        },
                        new AjaxRequestModel
                        {
                            AjaxEndpoint        = expectedRegionEndpoint,
                            HealthCheckRequired = healthCheckRequired,
                            IsHealthy           = isHealthy,
                            Name = "ajax-2",
                        },
                    },
                },
            };

            A.CallTo(() => appRegistryService.GetPathsAndRegions()).Returns(listOfPaths);
            A.CallTo(() => healthCheckerService.IsHealthy(A <Uri> .Ignored, A <bool> .Ignored, A <string> .Ignored)).Returns(true);

            // Act
            await healthMonitoringProcessor.Process().ConfigureAwait(false);

            // Assert
            if (markAsHealthyCalled)
            {
                var expectedRegionUri = new Uri(expectedRegionEndpoint);
                var firstItem         = listOfPaths.First();
                var pageRegion        = firstItem.Regions.First();
                A.CallTo(() => healthCheckerService.IsHealthy(expectedRegionUri, A <bool> .Ignored, A <string> .Ignored)).MustHaveHappened();
                A.CallTo(() => appRegistryService.MarkRegionAsHealthy(firstItem.Path, pageRegion.PageRegion)).MustHaveHappened();
            }
            else
            {
                A.CallTo(() => healthCheckerService.IsHealthy(A <Uri> .Ignored, A <bool> .Ignored, A <string> .Ignored)).MustNotHaveHappened();
                A.CallTo(() => appRegistryService.MarkRegionAsHealthy(A <string> .Ignored, A <PageRegion> .Ignored)).MustNotHaveHappened();
            }
        }