Skip to content

Commit

Permalink
Some minor changes to help tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejsmith committed Aug 24, 2015
1 parent 37dad06 commit 9e30ff0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Core/Jobs/JobBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private async Task<JobResult> 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) { }
Expand All @@ -105,6 +105,8 @@ private async Task<JobResult> 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)) {
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Tests/Jobs/WorkItemJobTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -155,6 +156,7 @@ public void CanRunBadWorkItem() {
});

job.RunUntilEmpty();
Thread.Sleep(1);

Assert.Equal(1, statusCount);

Expand Down

0 comments on commit 9e30ff0

Please sign in to comment.