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")); } }
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); } }
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(); } } }
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(); } } }
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)); } }
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(); } }