示例#1
0
        public async Task Should_Store_Checks_For_Separate_Services(IHealthCheckStorage storage)
        {
            var unhealthy = new HealthCheckStatus(HealthStatus.Unhealthy);
            var healthy   = new HealthCheckStatus(HealthStatus.Healthy);

            await storage.CheckedAsync("s1", unhealthy);

            await storage.CheckedAsync("s2", healthy);

            Assert.Equal(unhealthy, await storage.GetCurrentStatusAsync("s1"));
            Assert.Equal(healthy, await storage.GetCurrentStatusAsync("s2"));
        }
示例#2
0
        public async Task Should_Replace_Older_Value(IHealthCheckStorage storage)
        {
            var olderCheck = new HealthCheckStatus(HealthStatus.Unhealthy)
            {
                DateTime = DateTime.UtcNow.AddSeconds(-1)
            };
            var newerCheck = new HealthCheckStatus(HealthStatus.Healthy);

            await storage.CheckedAsync("test", olderCheck);

            Assert.Equal(olderCheck, await storage.GetCurrentStatusAsync("test"));

            await storage.CheckedAsync("test", newerCheck);

            Assert.Equal(newerCheck, await storage.GetCurrentStatusAsync("test"));
        }
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = new CancellationToken())
        {
            var healthStatus = await _healthCheckStorage.GetCurrentStatusAsync(ServiceName);

            if (healthStatus == null || healthStatus.DateTime + CheckPeriod < DateTime.UtcNow)
            {
                healthStatus = await _healthCheckService.CheckHealthAsync();

                await _healthCheckStorage.CheckedAsync(ServiceName, healthStatus);
            }
            return(healthStatus.Status switch
            {
                HealthStatus.Healthy => HealthCheckResult.Healthy(),
                _ => HealthCheckResult.Unhealthy(healthStatus.ErrorMessage)
            });
示例#4
0
 public async Task Should_Return_Null_When_Getting_Status_Without_Check_Performed(IHealthCheckStorage storage)
 {
     Assert.Null(await storage.GetCurrentStatusAsync("test"));
 }