示例#1
0
        public void PollingThreadShouldHaveCorrectCultureSet()
        {
            var task = new ThreadCultureRecordingTask();

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

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

                pollingTaskManager.Stop(TimeSpanOf100Milliseconds);

                Assert.That(task.ThreadCulture.Name.ToLowerInvariant(), Is.EqualTo("en-au"));
            }
        }
示例#2
0
        public void TerminateShouldStopManager()
        {
            using (var pollingTaskManager = new PollingTaskManager(new BasePollingTask[0], TimeSpanOf25Milliseconds, Log))
            {
                pollingTaskManager.Start();

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

                pollingTaskManager.Terminate();

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

                long counter = pollingTaskManager.PollCounter;

                Assert.That(WaitFor(() => pollingTaskManager.PollCounter != counter, TimeSpanOf100Milliseconds), Is.False);
            }
        }
示例#3
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();
                }
            }
        }
示例#4
0
        public void StopShouldCancelRunningTasks()
        {
            var task = new LongRunningPollingTask();

            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.True);

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

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

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

                if (task.IsStillAlive)
                {
                    task.TerminateTask();
                }
            }
        }
示例#5
0
        public void ShouldStart()
        {
            using (var pollingTaskManager = new PollingTaskManager(new BasePollingTask[0], TimeSpanOf25Milliseconds, Log))
            {
                pollingTaskManager.Start();

                Assert.That(WaitFor(() => pollingTaskManager.PollCounter > 0, TimeSpanOf100Milliseconds), Is.True);

                Assert.That(pollingTaskManager.Status, Is.EqualTo(PollingTaskManagerStatus.Started));
            }
        }
示例#6
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();
            }
        }