示例#1
0
            private void Run(GallioFunc <bool> condition)
            {
                var runner = new RetryRunner(
                    repeat ?? Retry.DefaultRepeat,
                    polling ?? Retry.DefaultPolling,
                    timeout ?? Retry.DefaultTimeout,
                    action, condition, messageFormat, messageArgs, clock);

                runner.Run();
            }
示例#2
0
        public void RetryWithCondition_OneExecutionSuccess()
        {
            var executions = 0;

            void doExecution()
            {
                executions++;
            }

            RetryRunner.Run(doExecution, retryConditionWhenNoException: () => executions == 0);
        }
示例#3
0
        public void Retry_OneExecutionSuccessfulAndDelegateIsNotRun()
        {
            var sum     = 0;
            var myCheck = 0;

            Action doExecution = () => sum++;

            RetryRunner.Run(doExecution, betweenRetriesDelegate: p => myCheck = 100);

            Assert.AreEqual(1, sum);
            Assert.AreEqual(0, myCheck);
        }
示例#4
0
        public void RetryWithCondition_ThreeExecutionsSuccessAndDoesNotSurpassRetriesCount()
        {
            var executions = 0;

            void doExecution()
            {
                executions++;
            }

            RetryRunner.Run(doExecution, retryConditionWhenNoException: () => executions != 3);

            Assert.AreEqual(3, executions);
        }
示例#5
0
        public void Retry_OneExecutionSuccessful()
        {
            var executions = 0;

            Action closure = () =>
            {
                executions++;
            };

            RetryRunner.Run(closure);

            Assert.AreEqual(1, executions);
        }
示例#6
0
 static async Task<int> Main(string[] args)
 {
     return await
     Parser.Default.ParseArguments<
     TimeoutOptions,
     RetryOptions
     >(args)
         .MapResult<TimeoutOptions, RetryOptions, Task<int>>(
             (TimeoutOptions opts) => TimeoutRunner.Run(opts),
             (RetryOptions opts) => RetryRunner.Run(opts),
             err => Task.FromResult(1)
         );
 }
示例#7
0
        public void RetryWithOutput_OneSuccessfulExecution()
        {
            var executions = 0;

            Func <bool> closure = () =>
            {
                executions++;
                return(true);
            };

            var output = RetryRunner.Run(closure);

            Assert.IsTrue(output);
            Assert.AreEqual(1, executions);
        }
示例#8
0
        public void Retry_TwoExecutionsFirstFailed()
        {
            var executions = 0;

            Action closure = () =>
            {
                executions++;

                if (executions != 2)
                {
                    throw new Exception("Failed");
                }
            };

            RetryRunner.Run(closure);

            Assert.AreEqual(2, executions);
        }
示例#9
0
        public void Retry_FourTimesUntilSuccess()
        {
            var executions = 0;

            Action closure = () =>
            {
                executions++;

                if (executions != 4)
                {
                    throw new Exception("Failed");
                }
            };

            RetryRunner.Run(closure, 4);

            Assert.AreEqual(4, executions);
        }
示例#10
0
        public void Retry_ThreeExecutionsUntilSuccess()
        {
            var executions = 0;

            Action closure = () =>
            {
                executions++;

                if (executions != 3)
                {
                    throw new Exception("Failed");
                }
            };

            RetryRunner.Run(closure);

            Assert.AreEqual(3, executions);
        }
示例#11
0
        public void Retry_UseAllRetriesAndDelegateRunsForEach()
        {
            var executions = 0;
            var myCheck    = 0;

            Action closure = () =>
            {
                executions++;

                if (executions < 3)
                {
                    throw new Exception("failed");
                }
            };

            RetryRunner.Run(closure, betweenRetriesDelegate: p => myCheck++);

            Assert.AreEqual(3, executions);
            Assert.AreEqual(2, myCheck);
        }
示例#12
0
        public void Retry_TwoExecutionsAndDelegateIsRunOnce()
        {
            var executions = 0;
            var myCheck    = 0;

            Action closure = () =>
            {
                executions++;

                if (executions != 2)
                {
                    throw new Exception("Failed");
                }
            };

            RetryRunner.Run(closure, betweenRetriesDelegate: p => myCheck += 1);

            Assert.AreEqual(2, executions);
            Assert.AreEqual(1, myCheck);
        }
示例#13
0
        public void RetryWithOutput_FourTimesUntilSuccess()
        {
            var executions = 0;

            bool doExecution()
            {
                executions++;

                if (executions != 4)
                {
                    throw new Exception("Failed");
                }

                return(executions == 4);
            };

            var output = RetryRunner.Run(doExecution, 4);

            Assert.AreEqual(4, executions);
        }
示例#14
0
        public void RetryWithOutput_ThreeExecutionsUntilSuccess()
        {
            var executions = 0;

            bool doExecution()
            {
                executions++;

                if (executions != 3)
                {
                    throw new Exception("Failed");
                }

                return(executions == 3);
            }

            var output = RetryRunner.Run(doExecution);

            Assert.IsTrue(output);
            Assert.AreEqual(3, executions);
        }
示例#15
0
        public void RetryWithOutput_TwoExecutionsFirstFailed()
        {
            var executions = 0;

            bool doExecution()
            {
                executions++;

                if (executions != 2)
                {
                    throw new Exception("Failed");
                }

                return(executions == 2);
            }

            var output = RetryRunner.Run(doExecution);

            Assert.IsTrue(output);
            Assert.AreEqual(2, executions);
        }
示例#16
0
        public void RetryWithCondition_ThreeExecutionsFailedAndDoesNotSurpassRetriesCount()
        {
            var executions = 0;

            void doExecution()
            {
                executions++;
                throw new Exception("Failed");
            }

            try
            {
                RetryRunner.Run(doExecution, retryConditionWhenNoException: () => executions != 5);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(3, executions);
                Assert.AreEqual("Failed", ex.Message);
                return;
            }

            Assert.Fail();
        }
示例#17
0
        public void RetryWithOutput_ThreeExecutionsAndFailed()
        {
            var executions = 0;

            bool doExecution()
            {
                executions++;

                throw new Exception("Failed");
            }

            try
            {
                var output = RetryRunner.Run(doExecution);
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Failed", ex.Message);
                Assert.AreEqual(3, executions);
                return;
            }

            Assert.Fail();
        }
示例#18
0
        public void RetryWithOutput_ZeroRetries()
        {
            var executions = 0;

            bool doExecution()
            {
                executions++;

                throw new Exception("Failed");
            }

            try
            {
                RetryRunner.Run(doExecution, 0);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(1, executions);
                Assert.AreEqual("Failed", ex.Message);
                return;
            }

            Assert.Fail();
        }
示例#19
0
        public void Retry_ZeroRetries()
        {
            var executions = 0;

            Action closure = () =>
            {
                executions++;

                throw new Exception("Failed");
            };

            try
            {
                RetryRunner.Run(closure, 0);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(1, executions);
                Assert.AreEqual("Failed", ex.Message);
                return;
            }

            Assert.Fail();
        }
示例#20
0
        public void Retry_ThreeExecutionsAndJustFailed()
        {
            var executions = 0;

            Action closure = () =>
            {
                executions++;

                throw new Exception("Failed");
            };

            try
            {
                RetryRunner.Run(closure);
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Failed", ex.Message);
                Assert.AreEqual(3, executions);
                return;
            }

            Assert.Fail();
        }
示例#21
0
 private void Run(Func<bool> condition)
 {
     var runner = new RetryRunner(
         repeat ?? Retry.DefaultRepeat,
         polling ?? Retry.DefaultPolling,
         timeout ?? Retry.DefaultTimeout,
         action, condition, messageFormat, messageArgs, clock);
     runner.Run();
 }