public async Task SetPassiveAsync_DestinationBecameUnhealthy_SetUnhealthyAndScheduleReactivation() { var destination = new DestinationState("destination0"); destination.Health.Active = DestinationHealth.Healthy; destination.Health.Passive = DestinationHealth.Healthy; var cluster = CreateCluster(passive: true, active: false, destination); using var timerFactory = new TestTimerFactory(); var updater = new DestinationHealthUpdater(timerFactory, GetClusterUpdater(), new Mock <ILogger <DestinationHealthUpdater> >().Object); await updater.SetPassiveAsync(cluster, destination, DestinationHealth.Unhealthy, TimeSpan.FromSeconds(2)); timerFactory.VerifyTimer(0, 2000); Assert.Empty(cluster.DestinationsState.AvailableDestinations); Assert.Equal(DestinationHealth.Healthy, destination.Health.Active); Assert.Equal(DestinationHealth.Unhealthy, destination.Health.Passive); timerFactory.FireAll(); Assert.Equal(DestinationHealth.Healthy, destination.Health.Active); Assert.Equal(DestinationHealth.Unknown, destination.Health.Passive); Assert.Equal(1, cluster.DestinationsState.AvailableDestinations.Count); Assert.Same(destination, cluster.DestinationsState.AvailableDestinations[0]); timerFactory.AssertTimerDisposed(0); }
public async Task SetPassiveAsync_HealthSateIsNotChanged_DoNothing(DestinationHealth health) { var destination = new DestinationState("destination0"); destination.Health.Active = DestinationHealth.Healthy; destination.Health.Passive = health; var cluster = CreateCluster(passive: true, active: false, destination); using var timerFactory = new TestTimerFactory(); var updater = new DestinationHealthUpdater(timerFactory, GetClusterUpdater(), new Mock <ILogger <DestinationHealthUpdater> >().Object); await updater.SetPassiveAsync(cluster, destination, health, TimeSpan.FromSeconds(2)); Assert.Equal(0, timerFactory.Count); Assert.Equal(DestinationHealth.Healthy, destination.Health.Active); Assert.Equal(health, destination.Health.Passive); }
public async Task SetPassiveAsync_DestinationBecameHealthy_SetNewState() { var destination = new DestinationState("destination0"); destination.Health.Active = DestinationHealth.Healthy; destination.Health.Passive = DestinationHealth.Unhealthy; var cluster = CreateCluster(passive: true, active: false, destination); using var timerFactory = new TestTimerFactory(); var updater = new DestinationHealthUpdater(timerFactory, GetClusterUpdater(), new Mock <ILogger <DestinationHealthUpdater> >().Object); await updater.SetPassiveAsync(cluster, destination, DestinationHealth.Healthy, TimeSpan.FromSeconds(2)); Assert.Equal(0, timerFactory.Count); Assert.Equal(DestinationHealth.Healthy, destination.Health.Active); Assert.Equal(DestinationHealth.Healthy, destination.Health.Passive); Assert.Equal(1, cluster.DestinationsState.AvailableDestinations.Count); Assert.Same(destination, cluster.DestinationsState.AvailableDestinations[0]); }