diff --git a/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs b/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs index dbaf6745c7..bfe9114704 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs @@ -38,12 +38,12 @@ private FeatureFlag() { } // Added for artifact post-processing, it enable/disable the post processing. // Added in 17.2-preview 7.0-preview - public const string DISABLE_ARTIFACTS_POSTPROCESSING = VSTEST_ + "_" + nameof(DISABLE_ARTIFACTS_POSTPROCESSING); + public const string DISABLE_ARTIFACTS_POSTPROCESSING = VSTEST_ + nameof(DISABLE_ARTIFACTS_POSTPROCESSING); // Added for artifact post-processing, it will show old output for dotnet sdk scenario. // It can be useful if we need to restore old UX in case users are parsing the console output. // Added in 17.2-preview 7.0-preview - public const string DISABLE_ARTIFACTS_POSTPROCESSING_NEW_SDK_UX = VSTEST_ + "_" + nameof(DISABLE_ARTIFACTS_POSTPROCESSING_NEW_SDK_UX); + public const string DISABLE_ARTIFACTS_POSTPROCESSING_NEW_SDK_UX = VSTEST_ + nameof(DISABLE_ARTIFACTS_POSTPROCESSING_NEW_SDK_UX); } #endif diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs index 88517706fc..8c45d307e9 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs @@ -122,19 +122,18 @@ private bool TryGetExecutablePath(string executableBaseName, out string executab public bool TryGetDotnetPathByArchitecture(PlatformArchitecture targetArchitecture, out string muxerPath) { + // If current process is the same as the target architecture we return the current process filename. if (_processHelper.GetCurrentProcessArchitecture() == targetArchitecture) { string currentProcessFileName = _processHelper.GetCurrentProcessFileName(); - if (Path.GetFileName(currentProcessFileName) != _muxerName) - { - EqtTrace.Verbose($"DotnetHostHelper.TryGetDotnetPathByArchitecture: Target architecture is the same as the current process architecture '{targetArchitecture}', but the current process is not a muxer: '{currentProcessFileName}'"); - } - else + if (Path.GetFileName(currentProcessFileName) == _muxerName) { muxerPath = currentProcessFileName; EqtTrace.Verbose($"DotnetHostHelper.TryGetDotnetPathByArchitecture: Target architecture is the same as the current process architecture '{targetArchitecture}', and the current process is a muxer, using that: '{muxerPath}'"); return true; } + + EqtTrace.Verbose($"DotnetHostHelper.TryGetDotnetPathByArchitecture: Target architecture is the same as the current process architecture '{targetArchitecture}', but the current process is not a muxer: '{currentProcessFileName}'"); } // We used similar approach as the runtime resolver. diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs index c891784174..6c5d6fea09 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs @@ -196,17 +196,15 @@ public void DiscoverTestsUsingSourceNavigation(RunnerInfo runnerInfo) } [TestMethod] - // flaky on the desktop runner, desktop framework combo - [NetFullTargetFrameworkDataSource(useDesktopRunner: false)] + [NetFullTargetFrameworkDataSource(inProcess: true)] [NetCoreTargetFrameworkDataSource] - public void CancelTestDiscovery(RunnerInfo runnerInfo) + public async Task CancelTestDiscovery(RunnerInfo runnerInfo) { // Setup var testAssemblies = new List { GetAssetFullPath("DiscoveryTestProject.dll"), GetAssetFullPath("SimpleTestProject.dll"), - GetAssetFullPath("SimpleTestProject2.dll") }; SetTestEnvironment(_testEnvironment, runnerInfo); @@ -214,19 +212,30 @@ public void CancelTestDiscovery(RunnerInfo runnerInfo) var discoveredTests = new List(); var discoveryEvents = new Mock(); - discoveryEvents.Setup((events) => events.HandleDiscoveredTests(It.IsAny>())).Callback - ((IEnumerable testcases) => discoveredTests.AddRange(testcases)); + discoveryEvents.Setup(events => events.HandleDiscoveredTests(It.IsAny>())) + .Callback((IEnumerable testcases) => + { + discoveredTests.AddRange(testcases); + _vstestConsoleWrapper.CancelDiscovery(); + }); + var isTestCancelled = false; + discoveryEvents.Setup(events => events.HandleDiscoveryComplete(It.IsAny(), It.IsAny>(), It.IsAny())) + .Callback((long _, IEnumerable testcases, bool isAborted) => + { + isTestCancelled = isAborted; + if (testcases != null) + { + discoveredTests.AddRange(testcases); + } + }); // Act - var discoveryTask = Task.Run(() => _vstestConsoleWrapper.DiscoverTests(testAssemblies, GetDefaultRunSettings(), discoveryEvents.Object)); - - Task.Delay(2000).Wait(); - _vstestConsoleWrapper.CancelDiscovery(); - discoveryTask.Wait(); + await Task.Run(() => _vstestConsoleWrapper.DiscoverTests(testAssemblies, GetDefaultRunSettings(), discoveryEvents.Object)); // Assert. - int discoveredSources = discoveredTests.Select((testcase) => testcase.Source).Distinct().Count(); - Assert.AreNotEqual(testAssemblies.Count, discoveredSources, "All test assemblies discovered"); + Assert.IsTrue(isTestCancelled); + int discoveredSourcesCount = discoveredTests.Select(testcase => testcase.Source).Distinct().Count(); + Assert.AreNotEqual(testAssemblies.Count, discoveredSourcesCount, "All test assemblies discovered"); } private IList GetTestAssemblies()