Пример #1
0
 public static EndpointHealth FromResult(DateTime checkTimeUtc, HealthInfo health, TimeSpan healthyResponseTimeLimit)
 {
     var status = (EndpointStatus)health.Status;
     if (status == EndpointStatus.Healthy && health.ResponseTime > healthyResponseTimeLimit)
         status = EndpointStatus.Unhealthy;
     return new EndpointHealth(checkTimeUtc, health.ResponseTime, status, health.Details);
 }
Пример #2
0
        public void CheckHealth_should_update_the_endpoint_with_its_health_status(HealthStatus healthStatus)
        {
            var tokenSource = new CancellationTokenSource();
            var healthInfo = new HealthInfo(healthStatus, TimeSpan.FromSeconds(1), new Dictionary<string, string> { { "property1", "value1" }, { "property2", "value2" } });
            var monitor = MonitorMock.GetMock("monitor");
            monitor.Setup(x => x.CheckHealthAsync("address", It.IsAny<CancellationToken>())).Returns(Task.FromResult(healthInfo));

            var endpoint = new Endpoint(Guid.NewGuid(), monitor.Object, "address", "name", "group");

            endpoint.CheckHealth(tokenSource.Token, MonitorSettingsHelper.ConfigureDefaultSettings()).Wait();

            var health = endpoint.Health;
            Assert.NotNull(health);
            Assert.Equal(healthInfo.ResponseTime, health.ResponseTime);
            Assert.Equal(healthInfo.Status.ToString(), health.Status.ToString());
            Assert.True(DateTime.UtcNow - health.CheckTimeUtc < TimeSpan.FromMilliseconds(500), "CheckTimeUtc should be captured");
            Assert.Equal(healthInfo.Details, health.Details);
        }
        public void GetEndpoint_should_return_endpoint_information_with_details(HealthStatus status)
        {
            Guid id = Guid.NewGuid();
            var monitor = MonitorMock.GetMock("monitor");
            var healthInfo = new HealthInfo(status, TimeSpan.FromSeconds(2), new Dictionary<string, string> { { "a", "b" }, { "c", "d" } });
            monitor.Setup(p => p.CheckHealthAsync("address", It.IsAny<CancellationToken>())).Returns(Task.FromResult(healthInfo));

            var endpoint = new Endpoint(id, monitor.Object, "address", "name", "group");
            endpoint.CheckHealth(new CancellationToken(), MonitorSettingsHelper.ConfigureDefaultSettings()).Wait();
            _endpointRegistry.Setup(r => r.GetById(id)).Returns(endpoint);

            var result = _controller.GetEndpoint(id) as OkNegotiatedContentResult<EndpointDetails>;
            Assert.NotNull(result);
            AssertEndpoint(endpoint, result.Content);

            Assert.Equal(status.ToString(), result.Content.Status.ToString());
            Assert.NotNull(result.Content.LastCheckUtc);
            Assert.Equal(healthInfo.ResponseTime, result.Content.LastResponseTime);
            Assert.Equal(healthInfo.Details, result.Content.Details);
        }
 private EndpointHealth FromResult(DateTime checkTimeUtc, TimeSpan responseTime, HealthInfo result)
 {
     return new EndpointHealth(checkTimeUtc, responseTime, GetStatus(result.Status, responseTime), result.Details);
 }