예제 #1
0
        public void Should_not_stall_the_scheduler()
        {
            ActionQueue queue = new ThreadPoolActionQueue();
            ActionScheduler scheduler = new TimerActionScheduler(new ThreadPoolActionQueue());

            var called = new Future<bool>();

            scheduler.Schedule(200.Milliseconds(), queue, () => { throw new InvalidOperationException("Bugger!"); });
            scheduler.Schedule(400.Milliseconds(), queue, () => called.Complete(true));

            called.IsAvailable(1.Seconds()).ShouldBeTrue();
        }
예제 #2
0
        public void Should_wait_until_the_appropriate_time_for_the_action_to_execute()
        {
            ActionQueue queue = new ThreadPoolActionQueue();
            ActionScheduler scheduler = new TimerActionScheduler(new SynchronousActionQueue());

            var called = new Future<bool>();

            scheduler.Schedule(100.Milliseconds(), queue, () => called.Complete(true));

            called.IsAvailable(0.Seconds()).ShouldBeFalse();

            called.IsAvailable(1.Seconds()).ShouldBeTrue();
        }
예제 #3
0
        public void Should_not_run_any_pending_actions()
        {
            ActionQueue queue = new ThreadPoolActionQueue();
            ActionScheduler scheduler = new TimerActionScheduler(new ThreadPoolActionQueue());

            var called = new Future<bool>();

            scheduler.Schedule(1.Seconds(), queue, () => called.Complete(true));

            scheduler.Disable();

            called.IsAvailable(2.Seconds()).ShouldBeFalse();
        }
예제 #4
0
        public void Should_run_the_action_immediately()
        {
            ActionQueue queue = new ThreadPoolActionQueue();
            ActionScheduler scheduler = new TimerActionScheduler(new SynchronousActionQueue());

            var called = new Future<bool>();

            scheduler.Schedule(TimeSpan.Zero, queue, () => called.Complete(true));

            called.IsAvailable(1.Seconds()).ShouldBeTrue();
        }
예제 #5
0
        public void Should_run_the_action_until_disabled()
        {
            ActionQueue queue = new ThreadPoolActionQueue();
            ActionScheduler scheduler = new TimerActionScheduler(new ThreadPoolActionQueue());

            Stopwatch elapsed = Stopwatch.StartNew();

            int count = 0;
            var called = new Future<int>();
            var failed = new Future<bool>();

            ScheduledAction scheduledAction = null;
            scheduledAction = scheduler.Schedule(TimeSpan.Zero, 100.Milliseconds(), queue, () =>
                {
                    count++;
                    if (count == 10)
                    {
                        called.Complete(count);
                        scheduledAction.Cancel();
                    }
                    else if (count > 10)
                    {
                        failed.Complete(true);
                    }
                });

            called.IsAvailable(5.Seconds()).ShouldBeTrue();

            elapsed.Stop();

            failed.IsAvailable(200.Milliseconds()).ShouldBeFalse();

            Trace.WriteLine("Time Period: " + elapsed.ElapsedMilliseconds);
        }