Ejemplo n.º 1
0
        public Task <HealthStatus> AssertAvailable()
        {
            return(Task.Factory.StartNew(() => {
                var status =
                    TimeoutRunner.Run(_settings.TaskAvailabilityCheckTimeout, () => _task.AssertAvailable(),
                                      ex => {
                    _logger.Error(Subject, "Availability test failed for " + Subject, ex);
                    _logger.InfoMessage(() => new TaskAvailabilityFailed(Subject)
                    {
                        ExceptionText = ex.ToString(),
                        ExceptionType = ex.GetType().Name
                    });
                });

                switch (status)
                {
                case Completion.Exception:

                    return HealthStatus.Error;

                case Completion.Success:
                    return HealthStatus.Active;

                case Completion.Timedout:
                    _logger.InfoMessage(() => new TaskAvailabilityFailed(Subject)
                    {
                        ExceptionType = "Timedout"
                    });
                    return HealthStatus.Timedout;

                default:
                    throw new ArgumentOutOfRangeException("status", "Status " + status + " should not be possible here");
                }
            }, TaskCreationOptions.AttachedToParent));
        }
Ejemplo n.º 2
0
        public void run_happy_path()
        {
            bool wasCalled = false;

            TimeoutRunner.Run(1.Seconds(), () => wasCalled = true, e => {
                throw e;
            }).ShouldBe(Completion.Success);

            wasCalled.ShouldBeTrue();
        }
Ejemplo n.º 3
0
        public void run_exception_case()
        {
            var ex = new FubuException(400, "Bad!");

            var handler = MockRepository.GenerateMock <Action <Exception> >();

            TimeoutRunner.Run(1.Seconds(), () => {
                throw ex;
            },
                              handler).ShouldBe(Completion.Exception);
        }
Ejemplo n.º 4
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)
         );
 }
Ejemplo n.º 5
0
        private OwnershipStatus activate()
        {
            Action activation = () => _lock.Write(() => _task.Activate());

            var status = TimeoutRunner.Run(_settings.TaskActivationTimeout, activation, ex => {
                _logger.Error(Subject, "Failed to take ownership of task " + Subject, ex);
                _logger.InfoMessage(() => new TaskActivationFailure(Subject));
            });

            switch (status)
            {
            case Completion.Success:
                _logger.InfoMessage(() => new TookOwnershipOfPersistentTask(Subject));
                _repository.AddOwnershipToThisNode(Subject);
                return(OwnershipStatus.OwnershipActivated);

            case Completion.Timedout:
                _logger.InfoMessage(() => new TaskActivationTimeoutFailure(Subject));
                return(OwnershipStatus.TimedOut);

            default:
                return(OwnershipStatus.Exception);
            }
        }
Ejemplo n.º 6
0
 public void run_timeout()
 {
     TimeoutRunner.Run(1.Seconds(), () => Thread.Sleep(2.Seconds()), ex => Assert.Fail("should be no exception"))
     .ShouldBe(Completion.Timedout);
 }