public async Task Process()
        {
            var appRegistry = await appRegistryService.GetPathsAndRegions().ConfigureAwait(false);

            foreach (var path in appRegistry.Where(p => string.IsNullOrWhiteSpace(p.ExternalURL?.ToString())))
            {
                if (path.Regions != null)
                {
                    await ProcessRegions(path.Path, path.Regions.Where(r => r.RequiresHealthCheck())).ConfigureAwait(false);
                }

                if (path.AjaxRequests != null)
                {
                    await ProcessAjaxRequests(path.Path, path.AjaxRequests.Where(a => a.RequiresHealthCheck())).ConfigureAwait(false);
                }
            }
        }
Exemplo n.º 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();
            }
        }