/// <summary> /// Default constructor. /// </summary> /// <param name="options"> /// The options. /// </param> internal ListTestsArgumentExecutor( CommandLineOptions options, IRunSettingsProvider runSettingsProvider, ITestRequestManager testRequestManager, IOutput output) { Contract.Requires(options != null); this.commandLineOptions = options; this.output = output; this.testRequestManager = testRequestManager; this.runSettingsManager = runSettingsProvider; this.discoveryEventsRegistrar = new DiscoveryEventsRegistrar(output); }
/// <summary> /// Default constructor. /// </summary> public RunSpecificTestsArgumentExecutor( CommandLineOptions options, IRunSettingsProvider runSettingsProvider, ITestRequestManager testRequestManager) { Contract.Requires(options != null); Contract.Requires(testRequestManager != null); this.commandLineOptions = options; this.testRequestManager = testRequestManager; this.runSettingsManager = runSettingsProvider; this.output = ConsoleOutput.Instance; this.discoveryEventsRegistrar = new DiscoveryEventsRegistrar(this.discoveryRequest_OnDiscoveredTests); }
/// <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> /// <returns>True, if successful</returns> public bool DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscoveryEventsRegistrar discoveryEventsRegistrar) { bool success = false; // create discovery request var criteria = new DiscoveryCriteria(discoveryPayload.Sources, this.commandLineOptions.BatchSize, TimeSpan.MaxValue, discoveryPayload.RunSettings); using (IDiscoveryRequest discoveryRequest = this.testPlatform.CreateDiscoveryRequest(criteria)) { try { this.testLoggerManager?.RegisterDiscoveryEvents(discoveryRequest); discoveryEventsRegistrar?.RegisterDiscoveryEvents(discoveryRequest); this.testPlatformEventSource.DiscoveryRequestStart(); discoveryRequest.DiscoverAsync(); discoveryRequest.WaitForCompletion(); this.testPlatformEventSource.DiscoveryRequestStop(); success = true; } catch (Exception ex) { if (ex is TestPlatformException || ex is SettingsException || ex is InvalidOperationException) { #if TODO Utilities.RaiseTestRunError(testLoggerManager, null, ex); #endif success = false; } else { throw; } } finally { this.testLoggerManager?.UnregisterDiscoveryEvents(discoveryRequest); discoveryEventsRegistrar?.UnregisterDiscoveryEvents(discoveryRequest); } } return(success); }
/// <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 void DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscoveryEventsRegistrar discoveryEventsRegistrar, ProtocolConfig protocolConfig) { EqtTrace.Info("TestRequestManager.DiscoverTests: Discovery tests started."); 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, discoveryPayload.TestPlatformOptions)) { try { discoveryEventsRegistrar?.RegisterDiscoveryEvents(discoveryRequest); this.testPlatformEventSource.DiscoveryRequestStart(); discoveryRequest.DiscoverAsync(); discoveryRequest.WaitForCompletion(); } finally { discoveryEventsRegistrar?.UnregisterDiscoveryEvents(discoveryRequest); } } } finally { EqtTrace.Info("TestRequestManager.DiscoverTests: Discovery tests completed."); this.testPlatformEventSource.DiscoveryRequestStop(); // Posts the Discovery Complete event. this.metricsPublisher.Result.PublishMetrics(TelemetryDataConstants.TestDiscoveryCompleteEvent, requestData.MetricsCollection.Metrics); } }
/// <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 void DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscoveryEventsRegistrar discoveryEventsRegistrar, ProtocolConfig protocolConfig) { EqtTrace.Info("TestRequestManager.DiscoverTests: Discovery tests started."); 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(), discoveryEventsRegistrar, out string updatedRunsettings)) { runsettings = updatedRunsettings; } var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettings); var batchSize = runConfiguration.BatchSize; var testCaseFilterFromRunsettings = runConfiguration.TestCaseFilter; 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) { TestCaseFilter = this.commandLineOptions.TestCaseFilterValue ?? testCaseFilterFromRunsettings }; // Make sure to run the run request inside a lock as the below section is not thread-safe // There can be only one discovery or execution request at a given point in time lock (this.syncObject) { try { EqtTrace.Info("TestRequestManager.DiscoverTests: Synchronization context taken"); this.currentDiscoveryRequest = this.testPlatform.CreateDiscoveryRequest(requestData, criteria, discoveryPayload.TestPlatformOptions); discoveryEventsRegistrar?.RegisterDiscoveryEvents(this.currentDiscoveryRequest); // Notify start of discovery start this.testPlatformEventSource.DiscoveryRequestStart(); // Start the discovery of tests and wait for completion this.currentDiscoveryRequest.DiscoverAsync(); this.currentDiscoveryRequest.WaitForCompletion(); } finally { if (this.currentDiscoveryRequest != null) { // Dispose the discovery request and unregister for events discoveryEventsRegistrar?.UnregisterDiscoveryEvents(currentDiscoveryRequest); this.currentDiscoveryRequest.Dispose(); this.currentDiscoveryRequest = null; } EqtTrace.Info("TestRequestManager.DiscoverTests: Discovery tests completed."); this.testPlatformEventSource.DiscoveryRequestStop(); // Posts the Discovery Complete event. this.metricsPublisher.Result.PublishMetrics(TelemetryDataConstants.TestDiscoveryCompleteEvent, requestData.MetricsCollection.Metrics); } } }
/// <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); }
/// <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 runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(discoveryPayload.RunSettings); var batchSize = runConfiguration.BatchSize; var runsettings = discoveryPayload.RunSettings; if (this.UpdateRunSettingsIfRequired(runsettings, out string updatedRunsettings)) { runsettings = updatedRunsettings; } runsettings = UpdateExtensionsFolderInRunSettings(runsettings); // create discovery request var criteria = new DiscoveryCriteria(discoveryPayload.Sources, batchSize, this.commandLineOptions.TestStatsEventTimeout, runsettings); using (IDiscoveryRequest discoveryRequest = this.testPlatform.CreateDiscoveryRequest(criteria, protocolConfig)) { try { this.testLoggerManager?.RegisterDiscoveryEvents(discoveryRequest); discoveryEventsRegistrar?.RegisterDiscoveryEvents(discoveryRequest); this.testPlatformEventSource.DiscoveryRequestStart(); discoveryRequest.DiscoverAsync(); discoveryRequest.WaitForCompletion(); success = true; } catch (Exception ex) { if (ex is TestPlatformException || ex is SettingsException || ex is InvalidOperationException) { #if TODO Utilities.RaiseTestRunError(testLoggerManager, null, ex); #endif success = false; } else { throw; } } finally { this.testLoggerManager?.UnregisterDiscoveryEvents(discoveryRequest); discoveryEventsRegistrar?.UnregisterDiscoveryEvents(discoveryRequest); } } EqtTrace.Info("TestRequestManager.DiscoverTests: Discovery tests completed, successful: {0}.", success); this.testPlatformEventSource.DiscoveryRequestStop(); return(success); }