示例#1
0
        public void InitialBackoffTicks_FirstCall_ReturnsConfiguredValue()
        {
            var policy = new ExponentialBackoffPolicy(
                new TestRandomGenerator(),
                initialBackoffTicks: 10,
                maxBackoffTicks: 2000);

            Assert.AreEqual(TimeSpan.FromTicks(10), policy.NextBackoff());
            Assert.AreEqual(TimeSpan.FromTicks(16), policy.NextBackoff());
        }
示例#2
0
        public void MaxBackoffTicks_MultipleCalls_ReachesLimit()
        {
            var policy = new ExponentialBackoffPolicy(
                new TestRandomGenerator(),
                initialBackoffTicks: 10,
                maxBackoffTicks: 2000);

            for (var i = 0; i < 50; i++)
            {
                if (policy.NextBackoff() == TimeSpan.FromTicks(2000))
                {
                    break;
                }
            }

            Assert.AreEqual(TimeSpan.FromTicks(2000), policy.NextBackoff());
        }
示例#3
0
        public void MaxBackoffTicks_Int32MaxValueWithJitter_ReturnsUpToInt32PlusMaxJitter()
        {
            const long MaximumWithJitter = (long)(int.MaxValue + int.MaxValue * ExponentialBackoffPolicy.Jitter);

            var policy = new ExponentialBackoffPolicy(
                new TestRandomGenerator()
            {
                DoubleResult = 1
            },
                initialBackoffTicks: 1,
                maxBackoffTicks: int.MaxValue);

            for (var i = 0; i < 1000; i++)
            {
                var backoff = policy.NextBackoff();

                Assert.Greater(backoff.Ticks, 0);
                Assert.LessOrEqual(backoff.Ticks, MaximumWithJitter);
            }

            Assert.AreEqual(policy.NextBackoff(), TimeSpan.FromTicks(MaximumWithJitter));
        }