Exemplo n.º 1
0
        public void WaitTimeRangeCustomMinMax()
        {
            TimeSpan min = TimeSpan.FromSeconds(7.5);
            TimeSpan max = TimeSpan.FromSeconds(12.5);

            strategy = new AddJitterRetryStrategy(new SimpleRetryStrategy(1, TimeSpan.FromSeconds(10)), 0.75, 1.25);

            // We expect wait times between 0 (inclusive) and 10 (exclusive) seconds, with a mean value of about 5 seconds.
            TimeSpan  total      = TimeSpan.Zero;
            const int Iterations = 10000;

            for (int i = 0; i < Iterations; i++)
            {
                TimeSpan wait = strategy.GetWaitTime(1);
                total += wait;

                Assert.That(wait, Is.GreaterThanOrEqualTo(min));
                Assert.That(wait, Is.LessThan(max));
            }

            TimeSpan mean        = new TimeSpan(total.Ticks / Iterations);
            TimeSpan diffTo10Sec = TimeSpan.FromSeconds(10) - mean;

            Assert.That(Math.Abs(diffTo10Sec.TotalMilliseconds), Is.LessThanOrEqualTo(100));
        }
Exemplo n.º 2
0
 public void Setup()
 {
     strategy = new AddJitterRetryStrategy(new SimpleRetryStrategy(2, TimeSpan.FromSeconds(10)));
 }