diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DefaultTestHostManager.cs index 138d4a70b2..4bbab1f86b 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DefaultTestHostManager.cs @@ -95,7 +95,7 @@ internal DefaultTestHostManager(Architecture architecture, Framework framework, var exitCode = 0; this.processHelper.TryGetExitCode(process, out exitCode); - this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode)); + this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode, process.Id)); }); /// @@ -129,7 +129,7 @@ internal DefaultTestHostManager(Architecture architecture, Framework framework, if (this.processHelper.TryGetExitCode(process, out exitCode)) { EqtTrace.Error("Test host exited with error: {0}", this.testHostProcessStdError); - this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode)); + this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode, process.Id)); } }); @@ -258,7 +258,7 @@ private int LaunchHost(TestProcessStartInfo testHostStartInfo) } catch (OperationCanceledException ex) { - this.OnHostExited(new HostProviderEventArgs(ex.Message, -1)); + this.OnHostExited(new HostProviderEventArgs(ex.Message, -1, 0)); return -1; } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs index e7fb3c01bf..934cf4210d 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs @@ -106,7 +106,7 @@ internal DotnetTestHostManager( var exitCode = 0; this.processHelper.TryGetExitCode(process, out exitCode); - this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode)); + this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode, process.Id)); }); /// @@ -140,7 +140,7 @@ internal DotnetTestHostManager( if (this.processHelper.TryGetExitCode(process, out exitCode)) { EqtTrace.Error("Test host exited with error: {0}", this.testHostProcessStdError); - this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode)); + this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode, process.Id)); } }; diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/TestEngine.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/TestEngine.cs index f0cfb77339..3ae1c613f2 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/TestEngine.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/TestEngine.cs @@ -6,17 +6,17 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine using System; using System.Linq; + using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; /// /// Cross Platform test engine entry point for the client. @@ -34,21 +34,28 @@ public class TestEngine : ITestEngine /// /// Fetches the DiscoveryManager for this engine. This manager would provide all functionality required for discovery. /// - /// - /// ITestDiscoveryManager object that can do discovery + /// + /// Test host manager + /// + /// + /// The discovery Criteria. + /// + /// + /// ITestDiscoveryManager object that can do discovery + /// public IProxyDiscoveryManager GetDiscoveryManager(ITestRuntimeProvider testHostManager, DiscoveryCriteria discoveryCriteria) { - int parallelLevel = this.VerifyParallelSettingAndCalculateParallelLevel(discoveryCriteria.Sources.Count(), discoveryCriteria.RunSettings); + var parallelLevel = this.VerifyParallelSettingAndCalculateParallelLevel(discoveryCriteria.Sources.Count(), discoveryCriteria.RunSettings); - Func proxyDiscoveryManagerCreator = () => new ProxyDiscoveryManager(testHostManager); - if (!testHostManager.Shared) + Func proxyDiscoveryManagerCreator = delegate { - return new ParallelProxyDiscoveryManager(proxyDiscoveryManagerCreator, parallelLevel, sharedHosts: testHostManager.Shared); - } - else - { - return proxyDiscoveryManagerCreator(); - } + // Create a new HostProvider, to be associated with individual ProxyDiscoveryManager(&POM) + var hostManager = this.GetDefaultTestHostManager(XmlRunSettingsUtilities.GetRunConfigurationNode(discoveryCriteria.RunSettings)); + hostManager.Initialize(TestSessionMessageLogger.Instance); + + return new ProxyDiscoveryManager(hostManager); + }; + return !testHostManager.Shared ? new ParallelProxyDiscoveryManager(proxyDiscoveryManagerCreator, parallelLevel, sharedHosts: testHostManager.Shared) : proxyDiscoveryManagerCreator(); } /// @@ -62,18 +69,26 @@ public IProxyDiscoveryManager GetDiscoveryManager(ITestRuntimeProvider testHostM public IProxyExecutionManager GetExecutionManager(ITestRuntimeProvider testHostManager, TestRunCriteria testRunCriteria) { var distinctSources = GetDistinctNumberOfSources(testRunCriteria); - int parallelLevel = this.VerifyParallelSettingAndCalculateParallelLevel(distinctSources, testRunCriteria.TestRunSettings); + var parallelLevel = this.VerifyParallelSettingAndCalculateParallelLevel(distinctSources, testRunCriteria.TestRunSettings); - var runconfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings); var isDataCollectorEnabled = XmlRunSettingsUtilities.IsDataCollectionEnabled(testRunCriteria.TestRunSettings); // SetupChannel ProxyExecutionManager with data collection if data collectors are specififed in run settings. - Func proxyExecutionManagerCreator = - () => - isDataCollectorEnabled - ? new ProxyExecutionManagerWithDataCollection(testHostManager, new ProxyDataCollectionManager(testRunCriteria.TestRunSettings)) - : new ProxyExecutionManager(testHostManager); + Func proxyExecutionManagerCreator = delegate + { + // Create a new HostManager, to be associated with individual ProxyExecutionManager(&POM) + var hostManager = this.GetDefaultTestHostManager(XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings)); + hostManager.Initialize(TestSessionMessageLogger.Instance); + + if (testRunCriteria.TestHostLauncher != null) + { + hostManager.SetCustomLauncher(testRunCriteria.TestHostLauncher); + } + return isDataCollectorEnabled ? new ProxyExecutionManagerWithDataCollection(hostManager, new ProxyDataCollectionManager(testRunCriteria.TestRunSettings)) + : new ProxyExecutionManager(hostManager); + }; + // parallelLevel = 1 for desktop should go via else route. if (parallelLevel > 1 || !testHostManager.Shared) { @@ -97,9 +112,12 @@ public ITestExtensionManager GetExtensionManager() /// /// Retrieves the default test host manager for this engine. /// - /// The architecture we want the test host manager for. - /// Framework for the test session. - /// An instance of the test host manager. + /// + /// The run Configuration. + /// + /// + /// An instance of the test host manager. + /// public ITestRuntimeProvider GetDefaultTestHostManager(RunConfiguration runConfiguration) { var framework = runConfiguration.TargetFrameworkVersion; @@ -138,8 +156,15 @@ private static int GetDistinctNumberOfSources(TestRunCriteria testRunCriteria) /// /// Verifies Parallel Setting and returns parallel level to use based on the run criteria /// - /// Test Run Criteria - /// Parallel Level to use + /// + /// The source Count. + /// + /// + /// The run Settings. + /// + /// + /// Parallel Level to use + /// private int VerifyParallelSettingAndCalculateParallelLevel(int sourceCount, string runSettings) { // Default is 1 diff --git a/src/Microsoft.TestPlatform.ObjectModel/Host/ITestRunTimeProvider.cs b/src/Microsoft.TestPlatform.ObjectModel/Host/ITestRunTimeProvider.cs index 1233ec16ca..3382572a8f 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Host/ITestRunTimeProvider.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Host/ITestRunTimeProvider.cs @@ -126,14 +126,17 @@ public HostProviderEventArgs(string message) this.ErrroCode = 0; } - public HostProviderEventArgs(string message, int errorCode) + public HostProviderEventArgs(string message, int errorCode, int processId) { this.Data = message; this.ErrroCode = errorCode; + this.ProcessId = processId; } public string Data { get; set; } public int ErrroCode { get; set; } + + public int ProcessId { get; set; } } }