From f875b0ab49a068063b3e5f8c8dfdef32405b3db4 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 29 Nov 2022 14:43:05 +0100 Subject: [PATCH 1/3] Fix satellite resolution for Microsoft.TestPlatform.Common (#4147) Fix satellite resolution for Microsoft.TestPlatform.Common --- .../ExtensionFramework/TestPluginCache.cs | 9 +++ .../Utilities/AssemblyResolver.cs | 65 +------------------ 2 files changed, 10 insertions(+), 64 deletions(-) diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs index 91c4e0493d..c1cb08f860 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs @@ -463,6 +463,15 @@ private Dictionary GetTestExtensions resolutionPaths = extensionAssembly.IsNullOrEmpty() ? GetDefaultResolutionPaths() : GetResolutionPaths(extensionAssembly); diff --git a/src/Microsoft.TestPlatform.Common/Utilities/AssemblyResolver.cs b/src/Microsoft.TestPlatform.Common/Utilities/AssemblyResolver.cs index 6f8da1ad72..3d2aa09775 100644 --- a/src/Microsoft.TestPlatform.Common/Utilities/AssemblyResolver.cs +++ b/src/Microsoft.TestPlatform.Common/Utilities/AssemblyResolver.cs @@ -123,71 +123,8 @@ internal void AddSearchDirectories(IEnumerable directories) TPDebug.Assert(requestedName != null && !requestedName.Name.IsNullOrEmpty(), "AssemblyResolver.OnResolve: requested is null or name is empty!"); - // Workaround: adding expected folder for the satellite assembly related to the current CurrentThread.CurrentUICulture relative to the current assembly location. - // After the move to the net461 the runtime doesn't resolve anymore the satellite assembly correctly. - // The expected workflow should be https://learn.microsoft.com/en-us/dotnet/core/extensions/package-and-deploy-resources#net-framework-resource-fallback-process - // But the resolution never fallback to the CultureInfo.Parent folder and fusion log return a failure like: - // ... - // LOG: The same bind was seen before, and was failed with hr = 0x80070002. - // ERR: Unrecoverable error occurred during pre - download check(hr = 0x80070002). - // ... - // The bizarre thing is that as a result we're failing caller task like discovery and when for reporting reason - // we're accessing again to the resource it works. - // Looks like a loading timing issue but we're not in control of the assembly loader order. var isResource = requestedName.Name.EndsWith(".resources"); - string[]? satelliteLocation = null; - - // We help to resolve only test platform resources to be less invasive as possible with the default/expected behavior - if (isResource && requestedName.Name.StartsWith("Microsoft.VisualStudio.TestPlatform")) - { - try - { - string? currentAssemblyLocation = null; - try - { - currentAssemblyLocation = Assembly.GetExecutingAssembly().Location; - // In .NET 5 and later versions, for bundled assemblies, the value returned is an empty string. - currentAssemblyLocation = currentAssemblyLocation == string.Empty ? null : Path.GetDirectoryName(currentAssemblyLocation); - } - catch (NotSupportedException) - { - // https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.location - } - - if (currentAssemblyLocation is not null) - { - List satelliteLocations = new(); - - // We mimic the satellite workflow and we add CurrentUICulture and CurrentUICulture.Parent folder in order - string? currentUICulture = Thread.CurrentThread.CurrentUICulture?.Name; - if (currentUICulture is not null) - { - satelliteLocations.Add(Path.Combine(currentAssemblyLocation, currentUICulture)); - } - - // CurrentUICulture.Parent - string? parentCultureInfo = Thread.CurrentThread.CurrentUICulture?.Parent?.Name; - if (parentCultureInfo is not null) - { - satelliteLocations.Add(Path.Combine(currentAssemblyLocation, parentCultureInfo)); - } - - if (satelliteLocations.Count > 0) - { - satelliteLocation = satelliteLocations.ToArray(); - } - } - } - catch (Exception ex) - { - // We catch here because this is a workaround, we're trying to substitute the expected workflow of the runtime - // and this shouldn't be needed, but if we fail we want to log what's happened and give a chance to the in place - // resolution workflow - EqtTrace.Error($"AssemblyResolver.OnResolve: Exception during the custom satellite resolution\n{ex}"); - } - } - - foreach (var dir in (satelliteLocation is not null) ? _searchDirectories.Union(satelliteLocation) : _searchDirectories) + foreach (var dir in _searchDirectories) { if (dir.IsNullOrEmpty()) { From e8fbc6f71bc2ffcb64ab9610464797f2e9e6bc7b Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" <42748379+dotnet-maestro[bot]@users.noreply.github.com> Date: Tue, 29 Nov 2022 17:45:17 +0100 Subject: [PATCH 2/3] Update dependencies from https://dev.azure.com/devdiv/DevDiv/_git/vs-code-coverage build 20221129.1 (#4149) Microsoft.Internal.CodeCoverage From Version 17.5.1-beta.22578.1 -> To Version 17.5.1-beta.22579.1 Co-authored-by: dotnet-maestro[bot] --- eng/Version.Details.xml | 4 ++-- eng/Versions.props | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 80468d11dd..75c8e94bde 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -1,9 +1,9 @@ - + https://dev.azure.com/devdiv/DevDiv/_git/vs-code-coverage - dcf573e0b853cd81204963064c618aeeb2383272 + 2b83d7dfcb1449ba091268a38dfda1125e9eb6ce https://github.com/dotnet/diagnostics diff --git a/eng/Versions.props b/eng/Versions.props index 3ef927b250..6815c377ae 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -82,7 +82,7 @@ JS etc.) is risky. This can break setup authoring and cause runtime failures in workloads where Rolsyn is not installed. --> 3.8.0-3.20427.2 - 17.5.1-beta.22578.1 + 17.5.1-beta.22579.1 0.2.0-preview.22424.1 6.0.0-preview.22424.1 16.5.2 From dbdb1f6f9007a288c904aa1f13485a3e57080fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 30 Nov 2022 11:14:32 +0100 Subject: [PATCH 3/3] Remove specific handling for MSTest in trx logger (#4152) --- .../TrxLogger.cs | 16 +-------- .../TrxLoggerTests.cs | 34 +++++-------------- 2 files changed, 9 insertions(+), 41 deletions(-) diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs index 8154173ea2..2170b6accd 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs @@ -608,27 +608,13 @@ private ITestElement GetOrCreateTestElement(Guid executionId, Guid parentExecuti TestCase testCase = rockSteadyTestResult.TestCase; Guid testId = Converter.GetTestId(testCase); - // Scenario for inner test case when parent test element is not present. - string? testName = testCase.DisplayName; - var adapter = testCase.ExecutorUri.ToString(); - if (adapter.Contains(TrxLoggerConstants.MstestAdapterString) && - parentTestElement == null && - !string.IsNullOrEmpty(rockSteadyTestResult.DisplayName)) - { - // Note: For old mstest adapters hierarchical support was not present. Thus inner result of data driven was identified using test result display name. - // Non null test result display name means its a inner result of data driven/ordered test. - // Changing GUID to keep supporting old mstest adapters. - testId = Guid.NewGuid(); - testName = rockSteadyTestResult.DisplayName; - } - // Get test element testElement = GetTestElement(testId); // Create test element if (testElement == null) { - testElement = Converter.ToTestElement(testId, executionId, parentExecutionId, testName!, testType, testCase); + testElement = Converter.ToTestElement(testId, executionId, parentExecutionId, testCase.DisplayName, testType, testCase); _testElements.TryAdd(testId, testElement); } diff --git a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/TrxLoggerTests.cs b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/TrxLoggerTests.cs index 143e45d2ab..f9cf3f8e1f 100644 --- a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/TrxLoggerTests.cs +++ b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/TrxLoggerTests.cs @@ -328,15 +328,9 @@ public void TestResultHandlerShouldAddFlatResultsIfParentTestResultIsNotPresent( } [TestMethod] - public void TestResultHandlerShouldChangeGuidAndDisplayNameForMsTestResultIfParentNotPresentButTestResultNamePresent() + public void TestResultHandlerShouldNotChangeGuidAndDisplayNameForTestResultIfParentNotPresentButTestResultNamePresent() { - ValidateTestIdAndNameInTrx(true); - } - - [TestMethod] - public void TestResultHandlerShouldNotChangeGuidAndDisplayNameForNonMsTestResultIfParentNotPresentButTestResultNamePresent() - { - ValidateTestIdAndNameInTrx(false); + ValidateTestIdAndNameInTrx(); } [TestMethod] @@ -863,42 +857,30 @@ public void IntializeShouldThrowExceptionIfBothPrefixAndNameProvided() Assert.ThrowsException(() => _testableTrxLogger.Initialize(_events.Object, _parameters)); } - private void ValidateTestIdAndNameInTrx(bool isMstestAdapter) + private void ValidateTestIdAndNameInTrx() { TestCase testCase = CreateTestCase("TestCase"); - testCase.ExecutorUri = isMstestAdapter ? new Uri("some://mstestadapteruri") : new Uri("some://uri"); + testCase.ExecutorUri = new Uri("some://uri"); VisualStudio.TestPlatform.ObjectModel.TestResult result = new(testCase); result.SetPropertyValue(TrxLoggerConstants.ExecutionIdProperty, Guid.NewGuid()); - if (isMstestAdapter) - { - result.DisplayName = "testDisplayName"; - } Mock resultEventArg = new(result); _testableTrxLogger.TestResultHandler(new object(), resultEventArg.Object); var testRunCompleteEventArgs = CreateTestRunCompleteEventArgs(); _testableTrxLogger.TestRunCompleteHandler(new object(), testRunCompleteEventArgs); - ValidateResultAttributesInTrx(_testableTrxLogger.TrxFile!, testCase.Id, testCase.DisplayName, isMstestAdapter); + ValidateResultAttributesInTrx(_testableTrxLogger.TrxFile!, testCase.Id, testCase.DisplayName); } - private static void ValidateResultAttributesInTrx(string trxFileName, Guid testId, string testName, bool isMstestAdapter) + private static void ValidateResultAttributesInTrx(string trxFileName, Guid testId, string testName) { using FileStream file = File.OpenRead(trxFileName); using XmlReader reader = XmlReader.Create(file); XDocument document = XDocument.Load(reader); var resultNode = document.Descendants(document.Root!.GetDefaultNamespace() + "UnitTestResult").First(); - if (isMstestAdapter) - { - Assert.AreNotEqual(resultNode.Attributes("testId").First().Value, testId.ToString()); - Assert.AreNotEqual(resultNode.Attributes("testName").First().Value, testName); - } - else - { - Assert.AreEqual(resultNode.Attributes("testId").First().Value, testId.ToString()); - Assert.AreEqual(resultNode.Attributes("testName").First().Value, testName); - } + Assert.AreEqual(resultNode.Attributes("testId").First().Value, testId.ToString()); + Assert.AreEqual(resultNode.Attributes("testName").First().Value, testName); } private static void ValidateTimeWithinUtcLimits(DateTimeOffset dateTime)