private IEnumerable <TestResult> RunAllTests(IEnumerable <TestCase> testCases, Dictionary <string, string> envVars, string runSettings, bool forCoverage) { using (var runCompleteSignal = new AutoResetEvent(false)) { var eventHandler = new RunEventHandler(runCompleteSignal, _logger); var strykerVsTestHostLauncher1 = new StrykerVsTestHostLauncher(null, envVars, _id); if (_flags.HasFlag(OptimizationFlags.AbortTestOnKill) && !forCoverage) { eventHandler.TestsFailed += Handler_TestsFailed; } if (testCases != null) { var finalTestCases1 = _discoveredTests.Where(discoveredTest => testCases.Any(test => test.Id == discoveredTest.Id)); _vsTestConsole.RunTestsWithCustomTestHost(finalTestCases1, runSettings, eventHandler, strykerVsTestHostLauncher1); } else { _vsTestConsole.RunTestsWithCustomTestHost(_sources, runSettings, eventHandler, strykerVsTestHostLauncher1); } // Test host exited signal comes after the run complete strykerVsTestHostLauncher1.WaitProcessExit(); // At this point, run must have complete. Check signal for true runCompleteSignal.WaitOne(); eventHandler.TestsFailed -= Handler_TestsFailed; return(eventHandler.TestResults); } }
private IEnumerable <TestResult> RunAllTests(IEnumerable <TestCase> testCases, Dictionary <string, string> envVars, string runSettings, bool forCoverage, int retries = 0) { void Handler_VsTestFailed(object sender, EventArgs e) { _vsTestFailed = true; } using (var runCompleteSignal = new AutoResetEvent(false)) { var eventHandler = new RunEventHandler(runCompleteSignal, _logger); var strykerVsTestHostLauncher = _hostBuilder(envVars, _id); eventHandler.VsTestFailed += Handler_VsTestFailed; if (_flags.HasFlag(OptimizationFlags.AbortTestOnKill) && !forCoverage) { eventHandler.TestsFailed += Handler_TestsFailed; } if (testCases != null) { var finalTestCases = _discoveredTests.Where(discoveredTest => testCases.Any(test => test.Id == discoveredTest.Id)); _vsTestConsole.RunTestsWithCustomTestHost(finalTestCases, runSettings, eventHandler, strykerVsTestHostLauncher); } else { _vsTestConsole.RunTestsWithCustomTestHost(_sources, runSettings, eventHandler, strykerVsTestHostLauncher); } // Test host exited signal comes after the run complete strykerVsTestHostLauncher.WaitProcessExit(); // At this point, run must have complete. Check signal for true runCompleteSignal.WaitOne(); eventHandler.TestsFailed -= Handler_TestsFailed; eventHandler.VsTestFailed -= Handler_VsTestFailed; if (_vsTestFailed && retries <= 10) { _vsTestConsole = PrepareVsTestConsole(); _vsTestFailed = false; return(RunAllTests(testCases, envVars, runSettings, forCoverage, ++retries)); } return(eventHandler.TestResults); } }
private IRunResults RunTestSession(Dictionary <int, ITestGuids> mutantTestsMap, bool runAllTests, string runSettings, Action <RunEventHandler> updateHandler = null, int retries = 0) { using var eventHandler = new RunEventHandler(_vsTests, _logger, RunnerId); void HandlerVsTestFailed(object sender, EventArgs e) => _vsTestFailed = true; void HandlerUpdate(object sender, EventArgs e) => updateHandler?.Invoke(eventHandler); var strykerVsTestHostLauncher = _hostBuilder(_id); eventHandler.VsTestFailed += HandlerVsTestFailed; eventHandler.ResultsUpdated += HandlerUpdate; _aborted = false; var options = new TestPlatformOptions { TestCaseFilter = _options.TestCaseFilter }; if (runAllTests) { _vsTestConsole.RunTestsWithCustomTestHost(_sources, runSettings, options, eventHandler, strykerVsTestHostLauncher); } else { _vsTestConsole.RunTestsWithCustomTestHost(mutantTestsMap.SelectMany(m => m.Value.GetGuids()).Select(t => _vsTests[t].Case), runSettings, options, eventHandler, strykerVsTestHostLauncher); } // Test host exited signal comes after the run completed strykerVsTestHostLauncher.WaitProcessExit(); // At this point, run must have complete. Check signal for true eventHandler.WaitEnd(); eventHandler.ResultsUpdated -= HandlerUpdate; eventHandler.VsTestFailed -= HandlerVsTestFailed; if (!_vsTestFailed || retries > 10) { return(eventHandler); } _vsTestConsole = PrepareVsTestConsole(); _vsTestFailed = false; return(RunTestSession(mutantTestsMap, true, runSettings, updateHandler, ++retries)); }
private IRunResults RunTestSession(IEnumerable <TestCase> testCases, string runSettings, Action <RunEventHandler> updateHandler = null, int retries = 0) { using (var eventHandler = new RunEventHandler(_logger, RunnerId)) { void HandlerVsTestFailed(object sender, EventArgs e) => _vsTestFailed = true; void HandlerUpdate(object sender, EventArgs e) => updateHandler?.Invoke(eventHandler); var strykerVsTestHostLauncher = _hostBuilder(_id); eventHandler.VsTestFailed += HandlerVsTestFailed; eventHandler.ResultsUpdated += HandlerUpdate; _aborted = false; if (testCases != null) { _vsTestConsole.RunTestsWithCustomTestHost(_discoveredTests.Where(discoveredTest => testCases.Any(test => test.Id == discoveredTest.Id)), runSettings, eventHandler, strykerVsTestHostLauncher); } else { _vsTestConsole.RunTestsWithCustomTestHost(_sources, runSettings, eventHandler, strykerVsTestHostLauncher); } // Test host exited signal comes after the run completed strykerVsTestHostLauncher.WaitProcessExit(); // At this point, run must have complete. Check signal for true eventHandler.WaitEnd(); eventHandler.ResultsUpdated -= HandlerUpdate; eventHandler.VsTestFailed -= HandlerVsTestFailed; if (!_vsTestFailed || retries > 10) { return(eventHandler); } _vsTestConsole = PrepareVsTestConsole(); _vsTestFailed = false; return(RunTestSession(testCases, runSettings, updateHandler, ++retries)); } }
private static IEnumerable <TestResult> RunTestsWithCustomTestHostLauncher(IVsTestConsoleWrapper consoleWrapper, List <string> list) { var runCompleteSignal = new AutoResetEvent(false); var processExitedSignal = new AutoResetEvent(false); var handler = new RunEventHandler(runCompleteSignal); consoleWrapper.RunTestsWithCustomTestHost(list, DefaultRunSettings, handler, new CustomTestHostLauncher(() => processExitedSignal.Set())); // Test host exited signal comes after the run complete processExitedSignal.WaitOne(); // At this point, run must have complete. Check signal for true Debug.Assert(runCompleteSignal.WaitOne()); return(handler.TestResults); }
private IEnumerable <TestResult> RunAllTests(int?activeMutationId, string runSettings) { var runCompleteSignal = new AutoResetEvent(false); var processExitedSignal = new AutoResetEvent(false); var handler = new RunEventHandler(runCompleteSignal, _messages); var testHostLauncher = new StrykerVsTestHostLauncher(() => processExitedSignal.Set(), activeMutationId); _vsTestConsole.RunTestsWithCustomTestHost(_sources, runSettings, handler, testHostLauncher); // Test host exited signal comes after the run complete processExitedSignal.WaitOne(); // At this point, run must have complete. Check signal for true runCompleteSignal.WaitOne(); return(handler.TestResults); }