public void Increment_AfterPeriodExceeded_ResetsBeforeIncrementing() { const long periodMillis = 1000; var clock = new ManualTestClock(); var bucket = new ResettingNumbersBucket(clock, new TransientConfigurableValue <long>(periodMillis)); bucket.Increment(CounterMetric.CommandSuccess); clock.AddMilliseconds(periodMillis + 1); Assert.Equal(1, bucket.GetCount(CounterMetric.CommandSuccess)); bucket.Increment(CounterMetric.CommandSuccess); // Should reset and then count one. Assert.Equal(1, bucket.GetCount(CounterMetric.CommandSuccess)); // Should be 1, not 2. }
public void Increment_AfterPeriodExceeded_ResetsBeforeIncrementing() { const long periodMillis = 1000; var mockConfig = new Mock <IFailurePercentageCircuitBreakerConfig>(MockBehavior.Strict); mockConfig.Setup(m => m.GetWindowMillis(It.IsAny <GroupKey>())).Returns(periodMillis); var clock = new ManualTestClock(); var bucket = new ResettingNumbersBucket(AnyGroupKey, clock, mockConfig.Object, new DefaultMjolnirLogFactory()); bucket.Increment(CounterMetric.CommandSuccess); clock.AddMilliseconds(periodMillis + 1); Assert.Equal(1, bucket.GetCount(CounterMetric.CommandSuccess)); bucket.Increment(CounterMetric.CommandSuccess); // Should reset and then count one. Assert.Equal(1, bucket.GetCount(CounterMetric.CommandSuccess)); // Should be 1, not 2. }