Increment() public method

public Increment ( ) : void
return void
        public async Task Manager_should_delete_old_stats()
        {
            const int expectedRepeats = 3;

            var age = TimeSpan.FromHours(1);
            var utcNow = DateTime.UtcNow;
            var asyncCountdown = new AsyncCountdown("delete old stats", expectedRepeats);
            var asyncCounter = new AsyncCounter();

            var monitorSettings = new Mock<IMonitorSettings>();
            monitorSettings.Setup(s => s.StatsHistoryMaxAge).Returns(age);

            var timeCoordinator = new Mock<ITimeCoordinator>();
            timeCoordinator.Setup(c => c.UtcNow).Returns(utcNow);

            var endpointMetricsCoordinator = new Mock<IEndpointMetricsForwarderCoordinator>();

            var repository = new Mock<IEndpointStatsRepository>();

            repository.Setup(r => r.DeleteStatisticsOlderThan(utcNow - age, It.IsAny<int>())).Returns(() =>
            {
                asyncCountdown.Decrement();
                asyncCounter.Increment();

                const int deletedItemsCount = 127;
                return asyncCounter.Value >= expectedRepeats ? 0 : deletedItemsCount;
            });

            using (new EndpointStatsManager(repository.Object, monitorSettings.Object, timeCoordinator.Object, endpointMetricsCoordinator.Object))
                await asyncCountdown.WaitAsync(MaxTestTime);

            await Task.Delay(TimeSpan.FromMilliseconds(500));
            //it should stop calling cleanup when there are no more items to be cleaned
            Assert.Equal(expectedRepeats, asyncCounter.Value);
        }
Esempio n. 2
0
        public AwaitableBuilder <T> WithCounter(AsyncCounter counter)
        {
            var inner = _task;

            _task = async() =>
            {
                try
                {
                    return(await inner.Invoke());
                }
                finally
                {
                    counter.Increment();
                }
            };
            return(this);
        }