コード例 #1
0
        public async Task Run([TimerTrigger("%HealthMonitorTimerTriggerSchedule%")] TimerInfo myTimer)
        {
            await healthMonitoringProcessor.Process().ConfigureAwait(false);

            logger.LogTrace($"Next run of health check is {myTimer?.ScheduleStatus.Next}");
        }
コード例 #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();
            }
        }