Esempio n. 1
0
        private void RunTests(
            IRequestData requestData,
            TestRunCriteria testRunCriteria,
            ITestRunEventsRegistrar testRunEventsRegistrar,
            TestPlatformOptions options)
        {
            // Make sure to run the run request inside a lock as the below section is not thread-safe.
            // TranslationLayer can process faster as it directly gets the raw un-serialized messages
            // whereas below logic needs to deserialize and do some cleanup.
            // While this section is cleaning up, TranslationLayer can trigger run causing multiple
            // threads to run the below section at the same time.
            lock (this.syncObject)
            {
                try
                {
                    this.currentTestRunRequest = this.testPlatform.CreateTestRunRequest(
                        requestData,
                        testRunCriteria,
                        options);

                    this.testRunResultAggregator.RegisterTestRunEvents(this.currentTestRunRequest);
                    testRunEventsRegistrar?.RegisterTestRunEvents(this.currentTestRunRequest);
                    ((Microsoft.VisualStudio.TestPlatform.Client.TestPlatform) this.testPlatform).VStestLoggerManager = this.VSTestLoggerManager;

                    this.TestPlatformEventSourceInstance.ExecutionRequestStart();

                    this.currentTestRunRequest.ExecuteAsync();

                    // Wait for the run completion event
                    this.currentTestRunRequest.WaitForCompletion();
                }
                catch (Exception ex)
                {
                    EqtTrace.Error("TestRequestManager.RunTests: failed to run tests: {0}", ex);
                    testRunResultAggregator.MarkTestRunFailed();
                    throw;
                }
                finally
                {
                    if (this.currentTestRunRequest != null)
                    {
                        this.testRunResultAggregator.UnregisterTestRunEvents(this.currentTestRunRequest);
                        testRunEventsRegistrar?.UnregisterTestRunEvents(this.currentTestRunRequest);

                        this.currentTestRunRequest.Dispose();
                        this.currentTestRunRequest = null;
                    }
                }
            }
        }
Esempio n. 2
0
        internal static void RaiseTestRunError(TestLoggerManager loggerManager, TestRunResultAggregator testRunResultAggregator, Exception exception)
        {
            // testRunResultAggregator can be null, if error is being raised in discovery context.
            testRunResultAggregator?.MarkTestRunFailed();

            TestRunMessageEventArgs errorMessage = new TestRunMessageEventArgs(TestMessageLevel.Error, exception.Message);

            loggerManager.SendTestRunMessage(errorMessage);

            // Send inner exception only when its message is different to avoid duplicate.
            if (exception is TestPlatformException && exception.InnerException != null && string.Compare(exception.Message, exception.InnerException.Message, StringComparison.CurrentCultureIgnoreCase) != 0)
            {
                errorMessage = new TestRunMessageEventArgs(TestMessageLevel.Error, exception.InnerException.Message);
                loggerManager.SendTestRunMessage(errorMessage);
            }
        }
Esempio n. 3
0
        private void RunTests(IRequestData requestData, TestRunCriteria testRunCriteria, ITestRunEventsRegistrar testRunEventsRegistrar)
        {
            // Make sure to run the run request inside a lock as the below section is not thread-safe
            // TranslationLayer can process faster as it directly gets the raw unserialized messages whereas
            // below logic needs to deserialize and do some cleanup
            // While this section is cleaning up, TranslationLayer can trigger run causing multiple threads to run the below section at the same time
            lock (syncobject)
            {
                try
                {
                    this.currentTestRunRequest = this.testPlatform.CreateTestRunRequest(requestData, testRunCriteria);

                    this.testRunResultAggregator.RegisterTestRunEvents(this.currentTestRunRequest);
                    testRunEventsRegistrar?.RegisterTestRunEvents(this.currentTestRunRequest);

                    this.testPlatformEventSource.ExecutionRequestStart();

                    this.currentTestRunRequest.ExecuteAsync();

                    this.runRequestStartedEventHandle.Set();

                    // Wait for the run completion event
                    this.currentTestRunRequest.WaitForCompletion();
                }
                catch (Exception ex)
                {
                    EqtTrace.Error("TestRequestManager.RunTests: failed to run tests: {0}", ex);
                    testRunResultAggregator.MarkTestRunFailed();
                    throw;
                }
                finally
                {
                    if (this.currentTestRunRequest != null)
                    {
                        this.testRunResultAggregator.UnregisterTestRunEvents(this.currentTestRunRequest);
                        testRunEventsRegistrar?.UnregisterTestRunEvents(this.currentTestRunRequest);

                        this.currentTestRunRequest.Dispose();
                        this.currentTestRunRequest = null;
                    }
                }
            }
        }