예제 #1
0
        public static void GracefulShutdown()
        {
            using var counter = new Counter();
            var timer = new AsyncTimer(counter.Run);
            var task  = timer.DisposeAsync();

            True(task.IsCompletedSuccessfully);
        }
예제 #2
0
        public static async Task GracefulShutdownAsync()
        {
            using var counter = new Counter();
            var timer = new AsyncTimer(counter.Run);

            True(timer.Start(TimeSpan.FromMilliseconds(10)));
            True(counter.WaitOne(DefaultTimeout));
            True(timer.IsRunning);
            await timer.DisposeAsync();

            False(timer.IsRunning);
        }
        public static async Task StartStopAsync()
        {
            using var counter = new Counter();
            using var timer   = new AsyncTimer(counter.Run);
            True(timer.Start(TimeSpan.FromMilliseconds(10)));
            True(counter.WaitOne(DefaultTimeout));
            True(timer.IsRunning);
            False(await timer.StopAsync());
            False(timer.IsRunning);
            var currentValue = counter.Value;

            True(currentValue > 0);
            //ensure that timer is no more executing
            await Task.Delay(100);

            Equal(currentValue, counter.Value);
        }
예제 #4
0
        public static async Task StartStopAsync()
        {
            var counter = new Counter();

            using (var timer = new AsyncTimer(counter.Run))
            {
                True(timer.Start(TimeSpan.FromMilliseconds(10)));
                await Task.Delay(100);

                True(await timer.StopAsync());
                var currentValue = counter.Value;
                True(currentValue > 0);
                //ensure that timer is no more executing
                await Task.Delay(100);

                Equal(currentValue, counter.Value);
            }
        }