private static void BusyRunnerHandler(TestRunnerHandler busyRunner, int busyRunnerIndex) { TestDescription sink; var testResult = RetrieveTestResult(busyRunner, busyRunnerIndex); _completedJobs.Enqueue(testResult); _dispatchedJobs.TryRemove(busyRunnerIndex, out sink); Interlocked.Decrement(ref _busyRunnersCount); busyRunner.isBusy = false; }
private static TestDescription RetrieveTestResult(TestRunnerHandler busyRunner, int busyRunnerIndex) { try { return(busyRunner.GetTestResult()); } catch (IOException) { var testResult = _dispatchedJobs[busyRunnerIndex]; testResult.TestsPass = false; return(testResult); } }
private static void Dispatch() { while (true) { while (_unassignedJobs.IsEmpty && !_shouldStop) { Thread.Sleep(DISPATCH_JOBCHECK_COOLDOWN_MS); } if (_shouldStop && _unassignedJobs.IsEmpty) { break; } TestDescription testToDispatch = null; if (!_unassignedJobs.TryDequeue(out testToDispatch)) { continue; } while (testToDispatch != null) { int assignedRunnerIndex; while (_busyRunnersCount >= _maxSimultaneousBusyRunners) { Thread.Sleep(DISPATCH_RUNNER_ACQUISITION_COOLDOWN_MS); } while ((assignedRunnerIndex = _testRunners.FindIndex(r => !r.isBusy)) == -1) { Thread.Sleep(DISPATCH_RUNNER_ACQUISITION_COOLDOWN_MS); } TestRunnerHandler assignedRunner = _testRunners[assignedRunnerIndex]; try { assignedRunner.SendJob(testToDispatch); } catch (IOException) { RunnerRestart(assignedRunner, assignedRunnerIndex); continue; } _dispatchedJobs.TryAdd(assignedRunnerIndex, testToDispatch); assignedRunner.isBusy = true; Interlocked.Increment(ref _busyRunnersCount); Task.Factory.StartNew(() => BusyRunnerHandler(assignedRunner, assignedRunnerIndex)); testToDispatch = null; } } }
private static void RunnerRestart(TestRunnerHandler busyRunner, int busyRunnerIndex) { busyRunner.KillTestRunner(); _testRunners[busyRunnerIndex] = new TestRunnerHandler(_oneTimeRunners, _killTimeFactor); }