Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
            }
        }