public void UpdateHealth_should_not_update_health_if_already_have_more_recent_result() { var expectedLastModifiedTime1 = DateTime.UtcNow; var expectedLastModifiedTime2 = DateTime.UtcNow.AddMinutes(1); var endpoint = new Endpoint(_timeCoordinator.Object, new EndpointIdentity(Guid.NewGuid(), "monitor", "address"), new EndpointMetadata("name", "group", null, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)); var newHealth = new EndpointHealth(DateTime.UtcNow, TimeSpan.Zero, EndpointStatus.Healthy); var oldHealth = new EndpointHealth(DateTime.UtcNow.AddSeconds(-1), TimeSpan.Zero, EndpointStatus.Healthy); _timeCoordinator.Setup(c => c.UtcNow).Returns(expectedLastModifiedTime1); endpoint.UpdateHealth(newHealth); _timeCoordinator.Setup(c => c.UtcNow).Returns(expectedLastModifiedTime2); endpoint.UpdateHealth(oldHealth); Assert.Same(newHealth, endpoint.Health); Assert.Equal(expectedLastModifiedTime1, endpoint.LastModifiedTimeUtc); }
public EndpointMetricsForwarderCoordinatorTest() { var endpointId = Guid.NewGuid(); var health = new EndpointHealth(DateTime.UtcNow, TimeSpan.FromSeconds(1), EndpointStatus.Healthy); _endpoint = new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(endpointId, "type", "Address"), new EndpointMetadata("Name", "Group", null, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)); _endpoint.UpdateHealth(health); _forwarder = new Mock<IEndpointMetricsForwarder>(); _duplicateForwarder = new Mock<IEndpointMetricsForwarder>(); }
public void UpdateHealth_should_update_health_and_last_modified_time_if_newer_health_is_provided() { var expectedLastModifiedTime1 = DateTime.UtcNow; var expectedLastModifiedTime2 = DateTime.UtcNow.AddMinutes(1); var endpoint = new Endpoint(_timeCoordinator.Object, new EndpointIdentity(Guid.NewGuid(), "monitor", "address"), new EndpointMetadata("name", "group", null, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)); var oldHealth = new EndpointHealth(DateTime.UtcNow, TimeSpan.Zero, EndpointStatus.Healthy); _timeCoordinator.Setup(c => c.UtcNow).Returns(expectedLastModifiedTime1); endpoint.UpdateHealth(oldHealth); Assert.Same(oldHealth, endpoint.Health); Assert.Equal(expectedLastModifiedTime1, endpoint.LastModifiedTimeUtc); var health = new EndpointHealth(DateTime.UtcNow, TimeSpan.Zero, EndpointStatus.Healthy); _timeCoordinator.Setup(c => c.UtcNow).Returns(expectedLastModifiedTime2); endpoint.UpdateHealth(health); Assert.Same(health, endpoint.Health); Assert.Equal(expectedLastModifiedTime2, endpoint.LastModifiedTimeUtc); }
public void Dispose_should_remove_health_information_and_update_last_modified_time_as_well_as_IsDisposed_property() { var endpoint = new Endpoint(_timeCoordinator.Object, new EndpointIdentity(Guid.NewGuid(), "monitor", "address"), new EndpointMetadata("name", "group", null, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)); endpoint.UpdateHealth(new EndpointHealth(DateTime.UtcNow, TimeSpan.Zero, EndpointStatus.Healthy)); DateTime expectedLastModifiedTime = DateTime.UtcNow; _timeCoordinator.Setup(c => c.UtcNow).Returns(expectedLastModifiedTime); endpoint.Dispose(); Assert.True(endpoint.IsDisposed); Assert.Null(endpoint.Health); Assert.Equal(expectedLastModifiedTime, endpoint.LastModifiedTimeUtc); }