Last active
August 29, 2015 14:02
-
-
Save renestein/69a155f9c6b865d2beb5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public virtual async Task Dispose_When_Tasks_Are_Queued_Then_All_Tasks_Are_Executed() | |
{ | |
const int NUMBER_OF_TASKS = 1000; | |
const int DELAY_TASK_CAN_CONTINUE_SIGNAL_S = 1; | |
int numberOfTasksExecuted = 0; | |
var waitForSignalCts = new CancellationTokenSource(); | |
var tasks = Enumerable.Range(0, NUMBER_OF_TASKS) | |
.Select(taskIndex => TestTaskFactory.StartNew(() => | |
{ | |
waitForSignalCts.Token.WaitHandle.WaitOne(); | |
return Interlocked.Increment(ref numberOfTasksExecuted); | |
})).ToArray(); | |
waitForSignalCts.CancelAfter(TimeSpan.FromSeconds(DELAY_TASK_CAN_CONTINUE_SIGNAL_S)); | |
Scheduler.Dispose(); | |
await Task.WhenAll(tasks); | |
Assert.AreEqual(NUMBER_OF_TASKS, numberOfTasksExecuted); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment