From 3235da2a3a3d088c39da23a4255d2b8c81dc5492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Fri, 3 May 2024 09:06:15 +0200 Subject: [PATCH 1/5] Add options to not share hosts and skip default adapters --- .../TestPlatform.cs | 24 ++++++++- .../FeatureFlag/FeatureFlag.cs | 4 ++ .../PublicAPI/PublicAPI.Shipped.txt | 2 + .../RunSettings/RunConfiguration.cs | 51 +++++++++++++++++++ .../Hosting/DefaultTestHostManager.cs | 2 +- 5 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/TestPlatform.cs b/src/Microsoft.TestPlatform.Client/TestPlatform.cs index 89c3d9d8bf..45ee1303a1 100644 --- a/src/Microsoft.TestPlatform.Client/TestPlatform.cs +++ b/src/Microsoft.TestPlatform.Client/TestPlatform.cs @@ -87,7 +87,7 @@ public IDiscoveryRequest CreateDiscoveryRequest( loggerManager.Initialize(discoveryCriteria.RunSettings); IProxyDiscoveryManager discoveryManager = _testEngine.GetDiscoveryManager(requestData, discoveryCriteria, sourceToSourceDetailMap, warningLogger); - discoveryManager.Initialize(options?.SkipDefaultAdapters ?? false); + discoveryManager.Initialize(GetSkipDefaultAdapters(options, discoveryCriteria.RunSettings)); return new DiscoveryRequest(requestData, discoveryCriteria, discoveryManager, loggerManager); } @@ -110,11 +110,31 @@ public ITestRunRequest CreateTestRunRequest( loggerManager.Initialize(testRunCriteria.TestRunSettings); IProxyExecutionManager executionManager = _testEngine.GetExecutionManager(requestData, testRunCriteria, sourceToSourceDetailMap, warningLogger); - executionManager.Initialize(options?.SkipDefaultAdapters ?? false); + executionManager.Initialize(GetSkipDefaultAdapters(options, testRunCriteria.TestRunSettings)); return new TestRunRequest(requestData, testRunCriteria, executionManager, loggerManager); } + private static bool GetSkipDefaultAdapters(TestPlatformOptions? options, string? runSettings) + { + if (options?.SkipDefaultAdapters ?? false) + { + EqtTrace.Verbose($"TestPlatform.GetSkipDefaultAdapters: Skipping default adapters because of TestPlatform options SkipDefaultAdapters."); + return true; + } + + RunConfiguration runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runSettings); + var skipping = runConfiguration.SkipDefaultAdapters; + if (skipping) + { + EqtTrace.Verbose($"TestPlatform.GetSkipDefaultAdapters: Skipping default adapters because of RunConfiguration SkipDefaultAdapters."); + return true; + } + + EqtTrace.Verbose($"TestPlatform.GetSkipDefaultAdapters: Not skipping default adapters SkipDefaultAdapters was false."); + return false; + } + /// public bool StartTestSession( IRequestData requestData, diff --git a/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs b/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs index 86a7f4c85b..5235fc9e22 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs @@ -69,6 +69,10 @@ private FeatureFlag() { } // Disable forwarding standard output of testhost. public const string VSTEST_DISABLE_STANDARD_OUTPUT_FORWARDING = nameof(VSTEST_DISABLE_STANDARD_OUTPUT_FORWARDING); + // Disable not sharing .NET Framework testhosts. Which will return behavior to sharing testhosts when they are running .NET Framework dlls, and are not disabling appdomains or running in parallel. + public const string VSTEST_DISABLE_NOT_SHARING_NETFRAMEWORK_TESTHOST = nameof(VSTEST_DISABLE_NOT_SHARING_NETFRAMEWORK_TESTHOST); + + [Obsolete("Only use this in tests.")] internal static void Reset() { diff --git a/src/Microsoft.TestPlatform.ObjectModel/PublicAPI/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.ObjectModel/PublicAPI/PublicAPI.Shipped.txt index 74364fb56a..596322bbee 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/PublicAPI/PublicAPI.Shipped.txt +++ b/src/Microsoft.TestPlatform.ObjectModel/PublicAPI/PublicAPI.Shipped.txt @@ -974,3 +974,5 @@ virtual Microsoft.VisualStudio.TestPlatform.ObjectModel.ValidateValueCallback.In Microsoft.VisualStudio.TestPlatform.ObjectModel.Architecture.RiscV64 = 8 -> Microsoft.VisualStudio.TestPlatform.ObjectModel.Architecture Microsoft.VisualStudio.TestPlatform.ObjectModel.RunConfiguration.CaptureStandardOutput.get -> bool Microsoft.VisualStudio.TestPlatform.ObjectModel.RunConfiguration.ForwardStandardOutput.get -> bool +Microsoft.VisualStudio.TestPlatform.ObjectModel.RunConfiguration.EnableSharedTestHost.get -> bool +Microsoft.VisualStudio.TestPlatform.ObjectModel.RunConfiguration.SkipDefaultAdapters.get -> bool diff --git a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs index 57f198202e..316ef6cf07 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs @@ -95,6 +95,7 @@ public RunConfiguration() : base(Constants.RunConfigurationSettingsName) ExecutionThreadApartmentState = Constants.DefaultExecutionThreadApartmentState; CaptureStandardOutput = !FeatureFlag.Instance.IsSet(FeatureFlag.VSTEST_DISABLE_STANDARD_OUTPUT_CAPTURING); ForwardStandardOutput = !FeatureFlag.Instance.IsSet(FeatureFlag.VSTEST_DISABLE_STANDARD_OUTPUT_FORWARDING); + EnableSharedTestHost = FeatureFlag.Instance.IsSet(FeatureFlag.VSTEST_DISABLE_NOT_SHARING_NETFRAMEWORK_TESTHOST); } /// @@ -455,6 +456,16 @@ public bool ResultsDirectorySet /// public bool ForwardStandardOutput { get; private set; } + /// + /// Enables sharing of .NET Framework testhosts. + /// + public bool EnableSharedTestHost { get; private set; } + + /// + /// Skips passing VisualStudio built in adapters to the project. + /// + public bool SkipDefaultAdapters { get; private set; } + /// public override XmlElement ToXml() { @@ -578,6 +589,14 @@ public override XmlElement ToXml() forwardStandardOutput.InnerXml = ForwardStandardOutput.ToString(); root.AppendChild(forwardStandardOutput); + XmlElement enableSharedTestHost = doc.CreateElement(nameof(EnableSharedTestHost)); + enableSharedTestHost.InnerXml = EnableSharedTestHost.ToString(); + root.AppendChild(enableSharedTestHost); + + XmlElement skipDefaultAdapters = doc.CreateElement(nameof(SkipDefaultAdapters)); + skipDefaultAdapters.InnerXml = SkipDefaultAdapters.ToString(); + root.AppendChild(skipDefaultAdapters); + return root; } @@ -964,6 +983,38 @@ public static RunConfiguration FromXml(XmlReader reader) runConfiguration.ForwardStandardOutput = bForwardStandardOutput; break; + case "EnableSharedTestHost": + { + XmlRunSettingsUtilities.ThrowOnHasAttributes(reader); + string element = reader.ReadElementContentAsString(); + + bool boolValue; + if (!bool.TryParse(element, out boolValue)) + { + throw new SettingsException(string.Format(CultureInfo.CurrentCulture, + Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, boolValue, elementName)); + } + + runConfiguration.EnableSharedTestHost = boolValue; + break; + } + + case "SkipDefaultAdapters": + { + XmlRunSettingsUtilities.ThrowOnHasAttributes(reader); + string element = reader.ReadElementContentAsString(); + + bool boolValue; + if (!bool.TryParse(element, out boolValue)) + { + throw new SettingsException(string.Format(CultureInfo.CurrentCulture, + Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, boolValue, elementName)); + } + + runConfiguration.SkipDefaultAdapters = boolValue; + break; + } + default: // Ignore a runsettings element that we don't understand. It could occur in the case // the test runner is of a newer version, but the test host is of an earlier version. diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index ca4e20243e..b841ef0957 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -379,7 +379,7 @@ public void Initialize(IMessageLogger? logger, string runsettingsXml) _targetFramework = runConfiguration.TargetFramework; _testHostProcess = null; - Shared = !runConfiguration.DisableAppDomain; + Shared = !runConfiguration.DisableAppDomain && runConfiguration.EnableSharedTestHost; _hostExitedEventRaised = false; IsInitialized = true; From af2808dba3b24fa80127c2891061a807b2ee2e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Thu, 16 May 2024 09:01:53 +0200 Subject: [PATCH 2/5] Add tests --- .../Hosting/DefaultTestHostManagerTests.cs | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs index c38169246a..ec66985de4 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs @@ -111,9 +111,17 @@ public void GetTestHostProcessStartInfoShouldNotIncludeFileNameFromSubFolderTest } [TestMethod] - public void GetTestHostProcessStartInfoShouldIncludeConnectionInfo() + public void GetTestHostProcessStartInfoShouldIncludeConnectionInfo_WhenShared() { var connectionInfo = new TestRunnerConnectionInfo { Port = 123, ConnectionInfo = new TestHostConnectionInfo { Endpoint = "127.0.0.0:123", Role = ConnectionRole.Client, Transport = Transport.Sockets }, RunnerProcessId = 101 }; + _testHostManager.Initialize(_mockMessageLogger.Object, $""" + + + + {true} + + + """); var info = _testHostManager.GetTestHostProcessStartInfo( Enumerable.Empty(), null, @@ -122,6 +130,18 @@ public void GetTestHostProcessStartInfoShouldIncludeConnectionInfo() Assert.AreEqual(" --port 123 --endpoint 127.0.0.0:123 --role client --parentprocessid 101", info.Arguments); } + [TestMethod] + public void GetTestHostProcessStartInfoShouldIncludeConnectionInfo_WhenNotShared() + { + var connectionInfo = new TestRunnerConnectionInfo { Port = 123, ConnectionInfo = new TestHostConnectionInfo { Endpoint = "127.0.0.0:123", Role = ConnectionRole.Client, Transport = Transport.Sockets }, RunnerProcessId = 101 }; + var info = _testHostManager.GetTestHostProcessStartInfo( + Enumerable.Empty(), + null, + connectionInfo); + + Assert.AreEqual(" --port 123 --endpoint 127.0.0.0:123 --role client --parentprocessid 101 --testsourcepath ", info.Arguments); + } + [TestMethod] public void GetTestHostConnectionInfoShouldIncludeEndpointRoleAndChannelType() { @@ -395,11 +415,25 @@ public void PropertiesShouldReturnEmptyDictionary() } [TestMethod] - public void DefaultTestHostManagerShouldBeShared() + public void DefaultTestHostManagerShouldBeSharedWhenOptedIn() { + _testHostManager.Initialize(_mockMessageLogger.Object, $""" + + + + {true} + + + """); Assert.IsTrue(_testHostManager.Shared); } + [TestMethod] + public void DefaultTestHostManagerShouldNotBeShared() + { + Assert.IsFalse(_testHostManager.Shared); + } + [TestMethod] public void LaunchTestHostShouldUseCustomHostIfSet() { From 720d8b9c16678254ac2b0be93eb279e907cf7bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Fri, 17 May 2024 16:29:04 +0200 Subject: [PATCH 3/5] Fix conflated appdomaindisable and testhost sharing --- .../Hosting/DefaultTestHostManager.cs | 16 +++++++++----- .../DifferentTestFrameworkSimpleTests.cs | 2 +- .../Hosting/DefaultTestHostManagerTests.cs | 22 +------------------ 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index b841ef0957..75fe13b98b 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -58,7 +58,7 @@ public class DefaultTestHostManager : ITestRuntimeProvider2 private readonly IEnvironment _environment; private readonly IDotnetHostHelper _dotnetHostHelper; private readonly IEnvironmentVariableHelper _environmentVariableHelper; - + private bool _disableAppDomain; private Architecture _architecture; private Framework? _targetFramework; private ITestHostLauncher? _customTestHostLauncher; @@ -199,10 +199,10 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( testhostProcessPath = Path.Combine(currentWorkingDirectory, "..", testHostProcessName); } - if (!Shared) + if (_disableAppDomain) { - // Not sharing the host which means we need to pass the test assembly path as argument - // so that the test host can create an appdomain on startup (Main method) and set appbase + // When host appdomains are disabled (in that case host is not shared) we need to pass the test assembly path as argument + // so that the test host can create one appdomain on startup (Main method) and set appbase. argumentsString += " --testsourcepath " + sources.FirstOrDefault()?.AddDoubleQuote(); } @@ -379,7 +379,13 @@ public void Initialize(IMessageLogger? logger, string runsettingsXml) _targetFramework = runConfiguration.TargetFramework; _testHostProcess = null; - Shared = !runConfiguration.DisableAppDomain && runConfiguration.EnableSharedTestHost; + _disableAppDomain = runConfiguration.DisableAppDomain; + // If appdomains are disabled the host cannot be shared, because sharing means loading multiple assemblies + // into the same process, and without appdomains we cannot safely do that. + // + // The OPPOSITE is not true though, disabling testhost sharing does not mean that we should not load the + // dll into a separate appdomain in the host. + Shared = !_disableAppDomain && runConfiguration.EnableSharedTestHost; _hostExitedEventRaised = false; IsInitialized = true; diff --git a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DifferentTestFrameworkSimpleTests.cs b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DifferentTestFrameworkSimpleTests.cs index 0ab5326a1f..cde8909ee8 100644 --- a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DifferentTestFrameworkSimpleTests.cs +++ b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DifferentTestFrameworkSimpleTests.cs @@ -163,7 +163,7 @@ public void NUnitRunAllTestExecution(RunnerInfo runnerInfo) var arguments = PrepareArguments( GetAssetFullPath("NUTestProject.dll"), - GetTestAdapterPath(UnitTestFramework.NUnit), + null, // GetTestAdapterPath(UnitTestFramework.NUnit), string.Empty, FrameworkArgValue, runnerInfo.InIsolationValue, TempDirectory.Path); InvokeVsTest(arguments); diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs index ec66985de4..df62734bfb 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs @@ -111,17 +111,9 @@ public void GetTestHostProcessStartInfoShouldNotIncludeFileNameFromSubFolderTest } [TestMethod] - public void GetTestHostProcessStartInfoShouldIncludeConnectionInfo_WhenShared() + public void GetTestHostProcessStartInfoShouldIncludeConnectionInfo() { var connectionInfo = new TestRunnerConnectionInfo { Port = 123, ConnectionInfo = new TestHostConnectionInfo { Endpoint = "127.0.0.0:123", Role = ConnectionRole.Client, Transport = Transport.Sockets }, RunnerProcessId = 101 }; - _testHostManager.Initialize(_mockMessageLogger.Object, $""" - - - - {true} - - - """); var info = _testHostManager.GetTestHostProcessStartInfo( Enumerable.Empty(), null, @@ -130,18 +122,6 @@ public void GetTestHostProcessStartInfoShouldIncludeConnectionInfo_WhenShared() Assert.AreEqual(" --port 123 --endpoint 127.0.0.0:123 --role client --parentprocessid 101", info.Arguments); } - [TestMethod] - public void GetTestHostProcessStartInfoShouldIncludeConnectionInfo_WhenNotShared() - { - var connectionInfo = new TestRunnerConnectionInfo { Port = 123, ConnectionInfo = new TestHostConnectionInfo { Endpoint = "127.0.0.0:123", Role = ConnectionRole.Client, Transport = Transport.Sockets }, RunnerProcessId = 101 }; - var info = _testHostManager.GetTestHostProcessStartInfo( - Enumerable.Empty(), - null, - connectionInfo); - - Assert.AreEqual(" --port 123 --endpoint 127.0.0.0:123 --role client --parentprocessid 101 --testsourcepath ", info.Arguments); - } - [TestMethod] public void GetTestHostConnectionInfoShouldIncludeEndpointRoleAndChannelType() { From 5413bc3f4e3670a9a98ba32139c2c3cd5a479b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Fri, 17 May 2024 16:51:40 +0200 Subject: [PATCH 4/5] Share by default but add opt-out --- .../FeatureFlag/FeatureFlag.cs | 2 +- .../PublicAPI/PublicAPI.Shipped.txt | 2 +- .../RunSettings/RunConfiguration.cs | 14 +++++++------- .../Hosting/DefaultTestHostManager.cs | 4 ++-- .../Hosting/DefaultTestHostManagerTests.cs | 10 +++++----- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs b/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs index 5235fc9e22..76f8ec1546 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs @@ -70,7 +70,7 @@ private FeatureFlag() { } public const string VSTEST_DISABLE_STANDARD_OUTPUT_FORWARDING = nameof(VSTEST_DISABLE_STANDARD_OUTPUT_FORWARDING); // Disable not sharing .NET Framework testhosts. Which will return behavior to sharing testhosts when they are running .NET Framework dlls, and are not disabling appdomains or running in parallel. - public const string VSTEST_DISABLE_NOT_SHARING_NETFRAMEWORK_TESTHOST = nameof(VSTEST_DISABLE_NOT_SHARING_NETFRAMEWORK_TESTHOST); + public const string VSTEST_DISABLE_SHARING_NETFRAMEWORK_TESTHOST = nameof(VSTEST_DISABLE_SHARING_NETFRAMEWORK_TESTHOST); [Obsolete("Only use this in tests.")] diff --git a/src/Microsoft.TestPlatform.ObjectModel/PublicAPI/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.ObjectModel/PublicAPI/PublicAPI.Shipped.txt index 596322bbee..221f78d7d1 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/PublicAPI/PublicAPI.Shipped.txt +++ b/src/Microsoft.TestPlatform.ObjectModel/PublicAPI/PublicAPI.Shipped.txt @@ -974,5 +974,5 @@ virtual Microsoft.VisualStudio.TestPlatform.ObjectModel.ValidateValueCallback.In Microsoft.VisualStudio.TestPlatform.ObjectModel.Architecture.RiscV64 = 8 -> Microsoft.VisualStudio.TestPlatform.ObjectModel.Architecture Microsoft.VisualStudio.TestPlatform.ObjectModel.RunConfiguration.CaptureStandardOutput.get -> bool Microsoft.VisualStudio.TestPlatform.ObjectModel.RunConfiguration.ForwardStandardOutput.get -> bool -Microsoft.VisualStudio.TestPlatform.ObjectModel.RunConfiguration.EnableSharedTestHost.get -> bool +Microsoft.VisualStudio.TestPlatform.ObjectModel.RunConfiguration.DisableSharedTestHost.get -> bool Microsoft.VisualStudio.TestPlatform.ObjectModel.RunConfiguration.SkipDefaultAdapters.get -> bool diff --git a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs index 316ef6cf07..2594087461 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs @@ -95,7 +95,7 @@ public RunConfiguration() : base(Constants.RunConfigurationSettingsName) ExecutionThreadApartmentState = Constants.DefaultExecutionThreadApartmentState; CaptureStandardOutput = !FeatureFlag.Instance.IsSet(FeatureFlag.VSTEST_DISABLE_STANDARD_OUTPUT_CAPTURING); ForwardStandardOutput = !FeatureFlag.Instance.IsSet(FeatureFlag.VSTEST_DISABLE_STANDARD_OUTPUT_FORWARDING); - EnableSharedTestHost = FeatureFlag.Instance.IsSet(FeatureFlag.VSTEST_DISABLE_NOT_SHARING_NETFRAMEWORK_TESTHOST); + DisableSharedTestHost = FeatureFlag.Instance.IsSet(FeatureFlag.VSTEST_DISABLE_SHARING_NETFRAMEWORK_TESTHOST); } /// @@ -457,9 +457,9 @@ public bool ResultsDirectorySet public bool ForwardStandardOutput { get; private set; } /// - /// Enables sharing of .NET Framework testhosts. + /// Disables sharing of .NET Framework testhosts. /// - public bool EnableSharedTestHost { get; private set; } + public bool DisableSharedTestHost { get; private set; } /// /// Skips passing VisualStudio built in adapters to the project. @@ -589,9 +589,9 @@ public override XmlElement ToXml() forwardStandardOutput.InnerXml = ForwardStandardOutput.ToString(); root.AppendChild(forwardStandardOutput); - XmlElement enableSharedTestHost = doc.CreateElement(nameof(EnableSharedTestHost)); - enableSharedTestHost.InnerXml = EnableSharedTestHost.ToString(); - root.AppendChild(enableSharedTestHost); + XmlElement disableSharedTesthost = doc.CreateElement(nameof(DisableSharedTestHost)); + disableSharedTesthost.InnerXml = DisableSharedTestHost.ToString(); + root.AppendChild(disableSharedTesthost); XmlElement skipDefaultAdapters = doc.CreateElement(nameof(SkipDefaultAdapters)); skipDefaultAdapters.InnerXml = SkipDefaultAdapters.ToString(); @@ -995,7 +995,7 @@ public static RunConfiguration FromXml(XmlReader reader) Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, boolValue, elementName)); } - runConfiguration.EnableSharedTestHost = boolValue; + runConfiguration.DisableSharedTestHost = boolValue; break; } diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index 75fe13b98b..9d5fd5e4ef 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -384,8 +384,8 @@ public void Initialize(IMessageLogger? logger, string runsettingsXml) // into the same process, and without appdomains we cannot safely do that. // // The OPPOSITE is not true though, disabling testhost sharing does not mean that we should not load the - // dll into a separate appdomain in the host. - Shared = !_disableAppDomain && runConfiguration.EnableSharedTestHost; + // dll into a separate appdomain in the host. It just means that we wish to run each dll in separate exe. + Shared = !_disableAppDomain && !runConfiguration.DisableSharedTestHost; _hostExitedEventRaised = false; IsInitialized = true; diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs index df62734bfb..9b36182524 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs @@ -395,23 +395,23 @@ public void PropertiesShouldReturnEmptyDictionary() } [TestMethod] - public void DefaultTestHostManagerShouldBeSharedWhenOptedIn() + public void DefaultTestHostManagerShouldNotBeSharedWhenOptedIn() { _testHostManager.Initialize(_mockMessageLogger.Object, $""" - {true} + {true} """); - Assert.IsTrue(_testHostManager.Shared); + Assert.IsFalse(_testHostManager.Shared); } [TestMethod] - public void DefaultTestHostManagerShouldNotBeShared() + public void DefaultTestHostManagerShouldBeShared() { - Assert.IsFalse(_testHostManager.Shared); + Assert.IsTrue(_testHostManager.Shared); } [TestMethod] From 6c1a07a809d22bb3815b9521604c6bfe40526351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Fri, 17 May 2024 17:42:15 +0200 Subject: [PATCH 5/5] Use reactorable names --- .../RunSettings/RunConfiguration.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs index 2594087461..1de0786730 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs @@ -983,7 +983,7 @@ public static RunConfiguration FromXml(XmlReader reader) runConfiguration.ForwardStandardOutput = bForwardStandardOutput; break; - case "EnableSharedTestHost": + case nameof(DisableSharedTestHost): { XmlRunSettingsUtilities.ThrowOnHasAttributes(reader); string element = reader.ReadElementContentAsString(); @@ -999,7 +999,7 @@ public static RunConfiguration FromXml(XmlReader reader) break; } - case "SkipDefaultAdapters": + case nameof(SkipDefaultAdapters): { XmlRunSettingsUtilities.ThrowOnHasAttributes(reader); string element = reader.ReadElementContentAsString();