public async Task CheckHealthAsync_should_use_long_timeout_for_endpoints_with_faulty_statuses(HealthStatus status)
        {
            var expectedTime = _failureTimeOut;

            SetupDefaultDelay();
            SetupDelayToReturnImmediatelyOn(expectedTime);
            SetupStopWatch("watch", TimeSpan.Zero, expectedTime);
            SetupMonitor(async token =>
            {
                if (_endpoint.Health == null)
                {
                    return(new HealthInfo(status));
                }

                await Task.Delay(expectedTime.Add(TimeSpan.FromMilliseconds(1)), token);
                return(new HealthInfo(HealthStatus.Healthy));
            });

            //First state
            await _endpoint.CheckHealth(_sampler, new CancellationToken());

            Assert.Equal(status.ToString(), _endpoint.Health.Status.ToString());

            //Timed out state
            var result = await _sampler.CheckHealthAsync(_endpoint, new CancellationToken());

            Assert.Equal(EndpointStatus.Faulty, result.Status);
            Assert.Equal(expectedTime, result.ResponseTime);
            Assert.Equal(_utcNow, result.CheckTimeUtc);
        }
 public async Task CheckHealth_should_update_the_endpoint_with_its_health_status()
 {
     var endpoint = new MonitorableEndpoint(new EndpointIdentity(Guid.Empty, "monitor", "address"), MonitorMock.Mock("monitor"));
     var sampler = new Mock<IHealthSampler>();
     var token = new CancellationToken();
     var result = new EndpointHealth(DateTime.UtcNow, TimeSpan.Zero, EndpointStatus.Healthy);
     sampler.Setup(s => s.CheckHealthAsync(endpoint, token)).Returns(Task.FromResult(result));
     await endpoint.CheckHealth(sampler.Object, token);
     Assert.Same(result, endpoint.Health);
 }
        public async Task CheckHealth_should_update_the_endpoint_with_its_health_status()
        {
            var endpoint = new MonitorableEndpoint(new EndpointIdentity(Guid.Empty, "monitor", "address"), MonitorMock.Mock("monitor"));
            var sampler  = new Mock <IHealthSampler>();
            var token    = new CancellationToken();
            var result   = new EndpointHealth(DateTime.UtcNow, TimeSpan.Zero, EndpointStatus.Healthy);

            sampler.Setup(s => s.CheckHealthAsync(endpoint, token)).Returns(Task.FromResult(result));
            await endpoint.CheckHealth(sampler.Object, token);

            Assert.Same(result, endpoint.Health);
        }