Exemple #1
0
        public void WaitAndIncreaseWithLast()
        {
            var info = new ErrorRetryingInfo(true, 60, true)
            {
                Info = new[]
                {
                    new ErrorRetryingItemInfo(1, 3, 60),
                    new ErrorRetryingItemInfo(2, 3, 60),
                    new ErrorRetryingItemInfo(3, 3, 60),
                },
            };
            var waiter      = new TestErrorRetryingWaiter(60);
            var errRetrying = new WaitBeforeRetryHelper(waiter);

            WaitAndIncrease(info, errRetrying, waiter);

            bool needRetrying = errRetrying.IncreaseAndWait(info);

            Assert.IsTrue(needRetrying);
            Assert.AreEqual(errRetrying.CountIteration, 2);
            Assert.AreEqual(errRetrying.CountRetrying, 3);
            Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue);
            Assert.IsFalse(waiter.IsRegularWaiterRaised.Value);

            //------------------- end
            needRetrying = errRetrying.IncreaseAndWait(info);

            Assert.IsFalse(needRetrying);
            Assert.AreEqual(errRetrying.CountIteration, 3);
            Assert.AreEqual(errRetrying.CountRetrying, 0);
            Assert.IsFalse(waiter.IsRegularWaiterRaised.HasValue);
        }
Exemple #2
0
        private void WaitAndIncrease(ErrorRetryingInfo info, WaitBeforeRetryHelper errRetrying, TestErrorRetryingWaiter waiter)
        {
            bool needRetrying = false;

            Assert.AreEqual(errRetrying.CountIteration, 0);
            Assert.AreEqual(errRetrying.CountRetrying, 0);
            Assert.IsTrue(waiter.IsRegularWaiterRaised == null);

            //var info = new ErrorRetryingInfo( 3, 3, 60 );

            //------------------- Iteration I
            needRetrying = errRetrying.IncreaseAndWait(info);

            Assert.IsTrue(needRetrying);
            Assert.AreEqual(errRetrying.CountIteration, 0);
            Assert.AreEqual(errRetrying.CountRetrying, 1);
            Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && waiter.IsRegularWaiterRaised.Value);

            needRetrying = errRetrying.IncreaseAndWait(info);

            Assert.IsTrue(needRetrying);
            Assert.AreEqual(errRetrying.CountIteration, 0);
            Assert.AreEqual(errRetrying.CountRetrying, 2);
            Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && waiter.IsRegularWaiterRaised.Value);

            needRetrying = errRetrying.IncreaseAndWait(info);

            Assert.IsTrue(needRetrying);
            Assert.AreEqual(errRetrying.CountIteration, 0);
            Assert.AreEqual(errRetrying.CountRetrying, 3);
            Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && !waiter.IsRegularWaiterRaised.Value);

            //------------------- Iteration II
            needRetrying = errRetrying.IncreaseAndWait(info);

            Assert.IsTrue(needRetrying);
            Assert.AreEqual(errRetrying.CountIteration, 1);
            Assert.AreEqual(errRetrying.CountRetrying, 1);
            Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && waiter.IsRegularWaiterRaised.Value);

            needRetrying = errRetrying.IncreaseAndWait(info);

            Assert.IsTrue(needRetrying);
            Assert.AreEqual(errRetrying.CountIteration, 1);
            Assert.AreEqual(errRetrying.CountRetrying, 2);
            Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && waiter.IsRegularWaiterRaised.Value);

            needRetrying = errRetrying.IncreaseAndWait(info);

            Assert.IsTrue(needRetrying);
            Assert.AreEqual(errRetrying.CountIteration, 1);
            Assert.AreEqual(errRetrying.CountRetrying, 3);
            Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && !waiter.IsRegularWaiterRaised.Value);

            //------------------- Iteration I
            needRetrying = errRetrying.IncreaseAndWait(info);

            Assert.IsTrue(needRetrying);
            Assert.AreEqual(errRetrying.CountIteration, 2);
            Assert.AreEqual(errRetrying.CountRetrying, 1);
            Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && waiter.IsRegularWaiterRaised.Value);

            needRetrying = errRetrying.IncreaseAndWait(info);

            Assert.IsTrue(needRetrying);
            Assert.AreEqual(errRetrying.CountIteration, 2);
            Assert.AreEqual(errRetrying.CountRetrying, 2);
            Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && waiter.IsRegularWaiterRaised.Value);
        }