Пример #1
0
        public void TerminateShouldForciblyStopExecutingTasks()
        {
            var task = new NeverEndingPollingTask();

            using (var pollingTaskManager = new PollingTaskManager(new BasePollingTask[] { task }, TimeSpanOf25Milliseconds, Log))
            {
                pollingTaskManager.Start();

                WaitForThrowOnTimeout(() => pollingTaskManager.PollCounter > 0, TimeSpanOf100Milliseconds);

                WaitForThrowOnTimeout(() => task.Counter > 0, TimeSpanOf100Milliseconds);

                Assert.That(pollingTaskManager.Stop(TimeSpanOf100Milliseconds), Is.False);

                Assert.That(task.IsStillAlive, Is.True);

                pollingTaskManager.Terminate();

                Assert.That(task.IsStillAlive, Is.False);

                if (task.IsStillAlive)
                {
                    task.TerminateTask();
                }
            }
        }
Пример #2
0
        public void ShouldNotStopWhenTimeoutIsExceeded()
        {
            var task = new NeverEndingPollingTask();

            using (var pollingTaskManager = new PollingTaskManager(new BasePollingTask[] { task }, TimeSpanOf25Milliseconds, Log))
            {
                pollingTaskManager.Start();

                WaitForThrowOnTimeout(() => pollingTaskManager.PollCounter > 0, TimeSpanOf100Milliseconds);

                Assert.That(pollingTaskManager.Stop(TimeSpanOf100Milliseconds), Is.False);

                Assert.That(pollingTaskManager.Status, Is.EqualTo(PollingTaskManagerStatus.Started));

                Assert.That(task.IsStillAlive, Is.True);

                task.TerminateTask();
            }
        }