public PatternTestExecutor(TestExecutionOptions options, IProgressMonitor progressMonitor, IFormatter formatter, IConverter converter, ITestEnvironmentManager environmentManager) { this.options = options; this.progressMonitor = progressMonitor; this.formatter = formatter; this.converter = converter; this.environmentManager = environmentManager; scheduler = new WorkScheduler(() => options.SingleThreaded ? 1 : TestAssemblyExecutionParameters.DegreeOfParallelism); }
private static int Fibonnaci(WorkScheduler scheduler, int count) { if (count < 2) return count; int sum = 0; scheduler.Run(new Action[] { () => Interlocked.Add(ref sum, Fibonnaci(scheduler, count - 1)), () => Interlocked.Add(ref sum, Fibonnaci(scheduler, count - 2)) }); return sum; }
public void ShouldWaitForAllActionsToFinishBeforeReturning( [Column(0, 1, 2, 7, 19)] int numActions) { Stopwatch stopwatch = Stopwatch.StartNew(); bool[] finished = new bool[numActions]; Action[] actions = new Action[numActions]; for (int i = 0; i < numActions; i++) { int actionIndex = i; actions[i] = () => { Thread.Sleep((actionIndex + 1) * 71 % 37); TestLog.WriteLine("Iteration #{0} finished after {1}ms", actionIndex + 1, stopwatch.ElapsedMilliseconds); finished[actionIndex] = true; }; } var scheduler = new WorkScheduler(() => maxThreads); scheduler.Run(actions); for (int i = 0; i < numActions; i++) Assert.IsTrue(finished[i]); }
public void SupportsReentrance() { var scheduler = new WorkScheduler(() => maxThreads); Assert.AreEqual(21, Fibonnaci(scheduler, 8)); }