예제 #1
0
        private bool 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)
            {
                bool success = true;

                try
                {
                    using (ITestRunRequest testRunRequest = this.testPlatform.CreateTestRunRequest(requestData, testRunCriteria))
                    {
                        this.currentTestRunRequest = testRunRequest;
                        this.runRequestCreatedEventHandle.Set();

                        try
                        {
                            this.testLoggerManager.RegisterTestRunEvents(testRunRequest);
                            this.testRunResultAggregator.RegisterTestRunEvents(testRunRequest);
                            testRunEventsRegistrar?.RegisterTestRunEvents(testRunRequest);

                            this.testPlatformEventSource.ExecutionRequestStart();

                            testRunRequest.ExecuteAsync();

                            // Wait for the run completion event
                            testRunRequest.WaitForCompletion();
                        }
                        finally
                        {
                            this.testLoggerManager.UnregisterTestRunEvents(testRunRequest);
                            this.testRunResultAggregator.UnregisterTestRunEvents(testRunRequest);
                            testRunEventsRegistrar?.UnregisterTestRunEvents(testRunRequest);
                        }
                    }
                }
                catch (Exception ex)
                {
                    EqtTrace.Error("TestRequestManager.RunTests: failed to run tests: {0}", ex);
                    if (ex is TestPlatformException ||
                        ex is SettingsException ||
                        ex is InvalidOperationException)
                    {
                        LoggerUtilities.RaiseTestRunError(this.testLoggerManager, this.testRunResultAggregator, ex);
                        success = false;
                    }
                    else
                    {
                        throw;
                    }
                }

                this.currentTestRunRequest = null;
                return(success);
            }
        }
예제 #2
0
        private bool RunTests(TestRunCriteria testRunCriteria, ITestRunEventsRegistrar testRunEventsRegistrar)
        {
            bool success = true;

            using (this.currentTestRunRequest = this.testPlatform.CreateTestRunRequest(testRunCriteria))
            {
                this.runRequestCreatedEventHandle.Set();
                try
                {
                    this.testLoggerManager.RegisterTestRunEvents(this.currentTestRunRequest);
                    this.testRunResultAggregator.RegisterTestRunEvents(this.currentTestRunRequest);
                    testRunEventsRegistrar?.RegisterTestRunEvents(this.currentTestRunRequest);

                    this.testPlatformEventSource.ExecutionRequestStart();

                    this.currentTestRunRequest.ExecuteAsync();

                    // Wait for the run completion event
                    this.currentTestRunRequest.WaitForCompletion();

                    this.testPlatformEventSource.ExecutionRequestStop();
                }
                catch (Exception ex)
                {
                    if (ex is TestPlatformException ||
                        ex is SettingsException ||
                        ex is InvalidOperationException)
                    {
                        LoggerUtilities.RaiseTestRunError(this.testLoggerManager, this.testRunResultAggregator, ex);
                        success = false;
                    }
                    else
                    {
                        throw;
                    }
                }
                finally
                {
                    this.testLoggerManager.UnregisterTestRunEvents(this.currentTestRunRequest);
                    this.testRunResultAggregator.UnregisterTestRunEvents(this.currentTestRunRequest);
                    testRunEventsRegistrar?.UnregisterTestRunEvents(this.currentTestRunRequest);
                }
            }

            this.currentTestRunRequest = null;

            return(success);
        }
예제 #3
0
        /// <summary>
        /// Discover Tests given a list of sources, run settings.
        /// </summary>
        /// <param name="discoveryPayload">Discovery payload</param>
        /// <param name="discoveryEventsRegistrar">EventHandler for discovered tests</param>
        /// <param name="protocolConfig">Protocol related information</param>
        /// <returns>True, if successful</returns>
        public bool DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscoveryEventsRegistrar discoveryEventsRegistrar, ProtocolConfig protocolConfig)
        {
            EqtTrace.Info("TestRequestManager.DiscoverTests: Discovery tests started.");

            bool success     = false;
            var  runsettings = discoveryPayload.RunSettings;

            if (discoveryPayload.TestPlatformOptions != null)
            {
                this.telemetryOptedIn = discoveryPayload.TestPlatformOptions.CollectMetrics;
            }

            var requestData = this.GetRequestData(protocolConfig);

            if (this.UpdateRunSettingsIfRequired(runsettings, discoveryPayload.Sources?.ToList(), out string updatedRunsettings))
            {
                runsettings = updatedRunsettings;
            }

            var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettings);
            var batchSize        = runConfiguration.BatchSize;

            if (requestData.IsTelemetryOptedIn)
            {
                // Collect Metrics
                this.CollectMetrics(requestData, runConfiguration);

                // Collect Commands
                this.LogCommandsTelemetryPoints(requestData);
            }

            // create discovery request
            var criteria = new DiscoveryCriteria(discoveryPayload.Sources, batchSize, this.commandLineOptions.TestStatsEventTimeout, runsettings);

            criteria.TestCaseFilter = this.commandLineOptions.TestCaseFilterValue;

            try
            {
                using (IDiscoveryRequest discoveryRequest = this.testPlatform.CreateDiscoveryRequest(requestData, criteria))
                {
                    try
                    {
                        this.testLoggerManager?.RegisterDiscoveryEvents(discoveryRequest);
                        discoveryEventsRegistrar?.RegisterDiscoveryEvents(discoveryRequest);

                        this.testPlatformEventSource.DiscoveryRequestStart();

                        discoveryRequest.DiscoverAsync();
                        discoveryRequest.WaitForCompletion();

                        success = true;
                    }

                    finally
                    {
                        this.testLoggerManager?.UnregisterDiscoveryEvents(discoveryRequest);
                        discoveryEventsRegistrar?.UnregisterDiscoveryEvents(discoveryRequest);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is TestPlatformException ||
                    ex is SettingsException ||
                    ex is InvalidOperationException)
                {
                    LoggerUtilities.RaiseTestRunError(testLoggerManager, null, ex);
                    success = false;
                }
                else
                {
                    throw;
                }
            }

            EqtTrace.Info("TestRequestManager.DiscoverTests: Discovery tests completed, successful: {0}.", success);
            this.testPlatformEventSource.DiscoveryRequestStop();

            // Posts the Discovery Complete event.
            this.metricsPublisher.Result.PublishMetrics(TelemetryDataConstants.TestDiscoveryCompleteEvent, requestData.MetricsCollection.Metrics);

            return(success);
        }