public bool SendEmailUsingMultipleHosts(IEnumerable <string> hostsList, string email)
        {
            var retryer = new TaskRetryer()
            {
                // Optional configuration attempts
                Config = new RetryConfig {
                    RetryInterval   = 0,  // Time in milliseconds to wait (default = 0)
                    MaximumAttempts = 10, // Default = 0 indicating no limit of attempts
                },
            };

            var mailer     = new FakeMailer();
            var enumerator = hostsList.GetEnumerator();

            retryer.RetryableOperation = delegate {
                enumerator.MoveNext(); // No need to check since it will only be called servers.Count times
                string host = enumerator.Current;
                mailer.SmtpHost = host.Trim();
                var output = mailer.SendEmail(email);

                if (output == false)
                {
                    TestContext.WriteLine("Failure when sending email. Chilkat error: {0}", mailer.LastErrorText);
                }

                return(output);
            };
            retryer.ExceptionLogger =
                args => TestContext.WriteLine("Email send failure, try #{0}: {1}", args.TryCount, args.Exception.Message);

            return(retryer.ProcessRetries());
        }
Beispiel #2
0
        private TaskRetryer GetTaskRetryer(int maxAttempts = 0)
        {
            var retryer = new TaskRetryer {
                RetryableOperation = CheckKidsCount,
                ExceptionLogger    = (args) => TestContext.WriteLine("Exception message: " + args.Exception.Message),
                Config             = new RetryConfig()
                {
                    MaximumAttempts = maxAttempts, // 0 represents unlimited attempts
                    RetryInterval   = 900,         // Representing 9 months
                },
            };

            return(retryer);
        }
Beispiel #3
0
        public void FailureSyncStaticTest()
        {
            Exception error = null;

            var instance = TaskRetryer.DefaultInstance;

            instance.Config             = GetConfigForFailure();
            instance.RetryableOperation = Try;
            instance.ExceptionLogger    = (ex) => error = ex.Exception;

            // Trying with exception suppression
            bool actual = TaskRetryer.ProcessRetries(Try, null); // out error

            Assert.AreEqual(_tries, TriesToFail);
            Assert.AreEqual(_tries, actual);
            Assert.IsInstanceOfType(error, typeof(OperationCanceledException));

            // Trying without exception suppression
            TestInitialize();
            TaskRetryer.ProcessRetries(Try, null);
        }