From 9e30ff00e18c27acdae42c7ae0d012a20dd005e0 Mon Sep 17 00:00:00 2001 From: ejsmith Date: Sun, 23 Aug 2015 19:08:10 -0500 Subject: [PATCH] Some minor changes to help tests. --- src/Core/Jobs/JobBase.cs | 4 +++- src/Core/Tests/Jobs/WorkItemJobTests.cs | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Core/Jobs/JobBase.cs b/src/Core/Jobs/JobBase.cs index 67f5c02e7..88eab0291 100644 --- a/src/Core/Jobs/JobBase.cs +++ b/src/Core/Jobs/JobBase.cs @@ -82,7 +82,7 @@ private async Task TryRunAsync(CancellationToken token) { iterations++; if (interval.HasValue) await Task.Delay(interval.Value, cancellationToken).AnyContext(); - else if (iterations % 10000 == 0) + else if (iterations % 10000 == 0) // allow for cancellation token to get set Thread.Sleep(1); } catch (TaskCanceledException) { } @@ -105,6 +105,8 @@ private async Task TryRunAsync(CancellationToken token) { if (cancellationToken.IsCancellationRequested) Logger.Trace().Message("Job cancellation requested.").Write(); + + Thread.Sleep(1); // allow events to process } public void RunContinuous(TimeSpan? delay = null, int iterationLimit = -1, CancellationToken token = default(CancellationToken)) { diff --git a/src/Core/Tests/Jobs/WorkItemJobTests.cs b/src/Core/Tests/Jobs/WorkItemJobTests.cs index 11d48c6e3..c8b9783d6 100644 --- a/src/Core/Tests/Jobs/WorkItemJobTests.cs +++ b/src/Core/Tests/Jobs/WorkItemJobTests.cs @@ -105,6 +105,7 @@ public async Task CanHandleMultipleWorkItemInstances() await Task.WhenAny(tasks); cancellationTokenSource.Cancel(); await Task.WhenAll(tasks); + Thread.Sleep(1); Assert.Equal(100, completedItems.Count + errors); Assert.Equal(3, jobIds.Count); Assert.Equal(100, jobIds.Sum(kvp => kvp.Value)); @@ -155,6 +156,7 @@ public void CanRunBadWorkItem() { }); job.RunUntilEmpty(); + Thread.Sleep(1); Assert.Equal(1, statusCount);