Exemplo n.º 1
0
        public void PollingThreadShouldHaveCorrectCultureSet()
        {
            var task = new ThreadCultureRecordingTask();

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

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

                pollingTaskManager.Stop(TimeSpanOf100Milliseconds);

                Assert.That(task.ThreadCulture.Name.ToLowerInvariant(), Is.EqualTo("en-au"));
            }
        }
Exemplo n.º 2
0
        public void StartShouldStartTheManager()
        {
            using (PollingTaskManager pollingTaskManager = new PollingTaskManager(new BasePollingTask[0], TimeSpanOf25Milliseconds))
            {
                pollingTaskManager.Start();

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

                Assert.That(pollingTaskManager.Status, Is.EqualTo(PollingTaskManagerStatus.Started));
            }
        }
Exemplo n.º 3
0
        public void TerminateShouldStopManager()
        {
            using (PollingTaskManager pollingTaskManager = new PollingTaskManager(new BasePollingTask[0], TimeSpanOf25Milliseconds))
            {
                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);
            }
        }
Exemplo n.º 4
0
        public void TerminateShouldForcibleyStopExecutingTasks()
        {
            NeverEndingPollingTask task = new NeverEndingPollingTask();

            using (PollingTaskManager pollingTaskManager = new PollingTaskManager(new BasePollingTask[] { task }, TimeSpanOf25Milliseconds))
            {
                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();
                }
            }
        }
Exemplo n.º 5
0
        public void StopShouldNotStopAndReturnWhenTimeoutIsExceeded()
        {
            NeverEndingPollingTask task = new NeverEndingPollingTask();

            using (PollingTaskManager pollingTaskManager = new PollingTaskManager(new BasePollingTask[] { task }, TimeSpanOf25Milliseconds))
            {
                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();
            }
        }
Exemplo n.º 6
0
        public void StopShouldCancelRunningTasks()
        {
            LongRunningPollingTask task = new LongRunningPollingTask();

            using (PollingTaskManager pollingTaskManager = new PollingTaskManager(new BasePollingTask[] { task }, TimeSpanOf25Milliseconds))
            {
                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();
                }
            }
        }