public void Cancel_already_triggered_Delay()
        {
            var agentTimer = new MockAgentTimer(DbgUtils.CurrentMethodName());

            using (var cancellationTokenSource = new CancellationTokenSource())
            {
                var continuationCalled = false;

                agentTimer.Delay(agentTimer.Now + 30.Minutes(), cancellationTokenSource.Token)
                .AttachSynchronousContinuation(task =>
                {
                    continuationCalled.Should().BeFalse();
                    continuationCalled = true;
                    task.IsCanceled.Should().BeFalse();
                });

                agentTimer.FastForward(30.Minutes());
                continuationCalled.Should().BeTrue();

                cancellationTokenSource.Cancel();
            }
        }
        public void Delay_with_relativeToInstant_in_the_past()
        {
            var agentTimer = new MockAgentTimer(DbgUtils.CurrentMethodName());

            var t1         = 7.Seconds();
            var t2         = 11.Seconds();
            var timeToWait = t1 + t2;

            // We take time instant at the start of a "atomic" calculation
            var now = agentTimer.Now;

            // Let's assume there's a long calculation that takes some time
            agentTimer.FastForward(t1);
            // and the conclusion of the calculation that we need to delay for timeToWait
            // (relative to `now` time instant)
            var delayTask = agentTimer.Delay(now + timeToWait);

            delayTask.IsCompleted.Should().BeFalse();

            agentTimer.FastForward(t2);

            delayTask.IsCompleted.Should().BeTrue();
        }
예제 #3
0
        private async Task WorkLoop()
        {
            _logger.Debug()?.Log("Signaling work loop started event...");
            _loopStarted.Set();

            await ExceptionUtils.DoSwallowingExceptions(_logger, async() =>
            {
                while (true)
                {
                    await WorkLoopIteration();
                }
                // ReSharper disable once FunctionNeverReturns
            }
                                                        , dbgCallerMethodName : ThisClassName + "." + DbgUtils.CurrentMethodName());

            _logger.Debug()?.Log("Signaling work loop completed event...");
            _loopCompleted.Set();
        }
        private async Task WorkLoop()
        {
            _logger.Debug()?.Log("Signaling work loop started event...");
            _loopStarted.Set();

            await ExceptionUtils.DoSwallowingExceptions(_logger, async() =>
            {
                while (!CancellationTokenSource.IsCancellationRequested)
                {
                    await WorkLoopIteration().ConfigureAwait(false);
                }
                // ReSharper disable once FunctionNeverReturns
            }
                                                        , dbgCallerMethodName : _dbgName + "." + DbgUtils.CurrentMethodName())
            .ConfigureAwait(false);

            _logger.Debug()?.Log("Signaling work loop completed event...");
            _loopCompleted.Set();
        }
예제 #5
0
 public void CurrentMethodName_test()
 {
     DbgUtils.CurrentMethodName().Should().Be(nameof(CurrentMethodName_test));
 }
예제 #6
0
 private Task DoWork() =>
 ExceptionUtils.DoSwallowingExceptions(_logger, async() =>
 {
     while (true)
     {
         await ProcessQueueItems(await ReceiveBatchAsync());
     }
     // ReSharper disable once FunctionNeverReturns
 }
                                       , dbgCallerMethodName: ThisClassName + "." + DbgUtils.GetCurrentMethodName());