public void When_state_never_exists_It_fails_after_timeout_waiting_before_retry()
        {
            var toTry = new CountTriesAction(options);
            var until = new ThrowsThenSubsequentlySucceedsPredicateQuery(true, true, 2, new Options { Timeout = TimeSpan.FromMilliseconds(250), RetryInterval = TimeSpan.FromMilliseconds(200) });

            var timeout1 = TimeSpan.FromMilliseconds(200);
            Assert.Throws<TestException>(() => _retryUntilTimeoutTimingStrategy.TryUntil(toTry, until, new Options { Timeout = timeout1 }));
        }
        public void When_state_exists_It_returns_immediately()
        {
            var toTry = new CountTriesAction(options);
            var retryInterval1 = TimeSpan.FromMilliseconds(10);
            var until = new AlwaysSucceedsPredicateQuery(true,TimeSpan.Zero,retryInterval1);

            retryUntilTimeoutRobustWrapper.TryUntil(toTry, until,TimeSpan.FromMilliseconds(20), retryInterval1);

            Assert.That(toTry.Tries, Is.EqualTo(1));
        }
        public void When_state_exists_after_three_tries_It_tries_three_times()
        {
            options.RetryInterval = TimeSpan.FromMilliseconds(10);
            var toTry = new CountTriesAction(options);
            var until = new ThrowsThenSubsequentlySucceedsPredicateQuery(true, true, 2, TimeSpan.FromMilliseconds(1000), options.RetryInterval);

            retryUntilTimeoutRobustWrapper.TryUntil(toTry, until, TimeSpan.FromMilliseconds(100), options.RetryInterval);

            Assert.That(toTry.Tries, Is.EqualTo(3));
        }
        public void When_state_exists_after_three_tries_It_tries_three_times()
        {
            options.RetryInterval = TimeSpan.FromMilliseconds(10);
            var toTry = new CountTriesAction(options);
            var until = new ThrowsThenSubsequentlySucceedsPredicateQuery(true, true, 2, TimeSpan.FromMilliseconds(1000), options.RetryInterval);

            retryUntilTimeoutRobustWrapper.TryUntil(toTry, until, TimeSpan.FromMilliseconds(100), options.RetryInterval);

            Assert.That(toTry.Tries, Is.EqualTo(3));
        }
        public void When_state_exists_It_returns_immediately()
        {
            var toTry          = new CountTriesAction(options);
            var retryInterval1 = TimeSpan.FromMilliseconds(10);
            var until          = new AlwaysSucceedsPredicateQuery(true, TimeSpan.Zero, retryInterval1);

            retryUntilTimeoutRobustWrapper.TryUntil(toTry, until, TimeSpan.FromMilliseconds(20), retryInterval1);

            Assert.That(toTry.Tries, Is.EqualTo(1));
        }
        public void It_applies_the_retryAfter_timeout_within_until()
        {
            var toTry = new CountTriesAction(options);
            var retryAfter = TimeSpan.FromMilliseconds(20);
            var until = new AlwaysThrowsPredicateQuery<TestException>(options.Timeout, retryAfter);

            Assert.Throws<TestException>(() => retryUntilTimeoutRobustWrapper.TryUntil(toTry, until, options.Timeout, options.RetryInterval));

            Assert.That(toTry.Tries, Is.GreaterThan(1));
            Assert.That(toTry.Tries, Is.LessThan(12));
        }
        public void It_applies_the_retryAfter_timeout_within_until()
        {
            var toTry      = new CountTriesAction(options);
            var retryAfter = TimeSpan.FromMilliseconds(20);
            var until      = new AlwaysThrowsPredicateQuery <TestException>(options.Timeout, retryAfter);

            Assert.Throws <TestException>(() => retryUntilTimeoutRobustWrapper.TryUntil(toTry, until, options.Timeout, options.RetryInterval));

            Assert.That(toTry.Tries, Is.GreaterThan(1));
            Assert.That(toTry.Tries, Is.LessThan(12));
        }
        public void It_applies_the_retryAfter_timeout_within_until()
        {
            var toTry = new CountTriesAction(options);
            var retryAfter = TimeSpan.FromMilliseconds(20);
            var until = new AlwaysThrowsPredicateQuery<TestException>(TimeSpan.Zero, retryAfter);

            Assert.Throws<TestException>(() => _retryUntilTimeoutTimingStrategy.TryUntil(toTry, until, new Options{Timeout = options.Timeout}));

            Assert.That(toTry.Tries, Is.GreaterThan(1));
            Assert.That(toTry.Tries, Is.LessThan(12));
        }
        public void When_state_exists_after_three_tries_It_tries_three_times()
        {
            options.RetryInterval = TimeSpan.FromMilliseconds(1000);
            var toTry = new CountTriesAction(options);

            var until = new ThrowsThenSubsequentlySucceedsPredicateQuery(true, true, 2, new Options { Timeout = TimeSpan.FromMilliseconds(1000), RetryInterval = options.RetryInterval });

            _retryUntilTimeoutTimingStrategy.TryUntil(toTry, until, new Options{Timeout = TimeSpan.FromMilliseconds(200)});

            Assert.That(toTry.Tries, Is.EqualTo(3));
        }
        public void It_applies_the_retryAfter_timeout_within_until()
        {
            var toTry      = new CountTriesAction(options);
            var retryAfter = TimeSpan.FromMilliseconds(20);
            var until      = new AlwaysThrowsPredicateQuery <TestException>(TimeSpan.Zero, retryAfter);

            Assert.Throws <TestException>(() => _retryUntilTimeoutTimingStrategy.TryUntil(toTry, until, new Options {
                Timeout = options.Timeout
            }));

            Assert.That(toTry.Tries, Is.GreaterThan(1));
            Assert.That(toTry.Tries, Is.LessThan(12));
        }
        public void When_state_never_exists_It_fails_after_timeout_waiting_before_retry()
        {
            var toTry = new CountTriesAction(options);
            var until = new ThrowsThenSubsequentlySucceedsPredicateQuery(true, true, 2, new Options {
                Timeout = TimeSpan.FromMilliseconds(250), RetryInterval = TimeSpan.FromMilliseconds(200)
            });

            var timeout1 = TimeSpan.FromMilliseconds(200);

            Assert.Throws <TestException>(() => _retryUntilTimeoutTimingStrategy.TryUntil(toTry, until, new Options {
                Timeout = timeout1
            }));
        }
        public void When_state_never_exists_It_fails_after_timeout()
        {
            var toTry = new CountTriesAction(options);
            var until = new AlwaysSucceedsPredicateQuery(false, TimeSpan.Zero, options.RetryInterval);

            var stopwatch = Stopwatch.StartNew();
            var timeout1 = TimeSpan.FromMilliseconds(200);
            Assert.Throws<MissingHtmlException>(() => retryUntilTimeoutRobustWrapper.TryUntil(toTry, until, timeout1, options.RetryInterval));

            stopwatch.Stop();
            var elapsedMilliseconds = stopwatch.ElapsedMilliseconds;

            Assert.That(elapsedMilliseconds, Is.InRange(timeout1.TotalMilliseconds - (options.RetryInterval.Milliseconds + When_waiting.AccuracyMilliseconds),
                                                        timeout1.TotalMilliseconds + (options.RetryInterval.Milliseconds + When_waiting.AccuracyMilliseconds)));
        }
        public void When_state_exists_after_three_tries_It_tries_three_times()
        {
            options.RetryInterval = TimeSpan.FromMilliseconds(1000);
            var toTry = new CountTriesAction(options);

            var until = new ThrowsThenSubsequentlySucceedsPredicateQuery(true, true, 2, new Options {
                Timeout = TimeSpan.FromMilliseconds(1000), RetryInterval = options.RetryInterval
            });

            _retryUntilTimeoutTimingStrategy.TryUntil(toTry, until, new Options {
                Timeout = TimeSpan.FromMilliseconds(200)
            });

            Assert.That(toTry.Tries, Is.EqualTo(3));
        }
        public void When_state_never_exists_It_fails_after_timeout()
        {
            var toTry = new CountTriesAction(options);
            var until = new AlwaysSucceedsPredicateQuery(false, TimeSpan.Zero, options.RetryInterval);

            var stopwatch = Stopwatch.StartNew();
            var timeout1  = TimeSpan.FromMilliseconds(200);

            Assert.Throws <MissingHtmlException>(() => retryUntilTimeoutRobustWrapper.TryUntil(toTry, until, timeout1, options.RetryInterval));

            stopwatch.Stop();
            var elapsedMilliseconds = stopwatch.ElapsedMilliseconds;

            Assert.That(elapsedMilliseconds, Is.InRange(timeout1.TotalMilliseconds - (options.RetryInterval.Milliseconds + When_waiting.AccuracyMilliseconds),
                                                        timeout1.TotalMilliseconds + (options.RetryInterval.Milliseconds + When_waiting.AccuracyMilliseconds)));
        }