public static void GenerateEventList(TestContext context) { var throttle = new Throttle(MaxEvents, TimeSpan); for (int i = 0; i < TotalEvents; i++) { var id = i; throttle.Execute(() => { Events.Add(new Event { Id = id, Time = DateTime.Now }); }); } }
private VsTestFrameworkReporter(ITestCaseDiscoverySink sink, IFrameworkHandle frameworkHandle, bool isRunningInsideVisualStudio) { _sink = sink; _frameworkHandle = frameworkHandle; _isRunningInsideVisualStudio = isRunningInsideVisualStudio; // This is part of a workaround for a Visual Studio bug (see issue #15). // If test results are reported too quickly (100 or more in 500ms), the // Visual Studio test framework internally will start new work items in // a ThreadPool to process results there. If the TestExecutor returns // before all work items in the ThreadPool have been processed, results // will be lost. We work around this in two ways: // 1) ReportTestResult: Minimize the chance of reporting too quickly // by throttling our own output. // 2) AllTestsFinished: We would like to wait till all other ThreadPool // work item have finished. The closest approximation is to add a // work item which will be scheduled after all others and let it // sleep for a short time. _throttle = new Throttle(NrOfTestsBeforeThrottling, TimeSpan.FromMilliseconds(ThrottleDurationInMs)); }