From e9f626b9713be073087d002fd8bc3510ac95c5d9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 May 2025 12:16:03 +0000 Subject: [PATCH 1/4] Initial plan for issue From 62d067459eb78ac5fe5681c8b543b8b394b078ec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 May 2025 12:26:56 +0000 Subject: [PATCH 2/4] Fix System.MissingMethodException for KeyValuePair deconstruction polyfill Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com> --- .../Execution/TestExecutionManager.cs | 8 ++++---- .../Execution/TestRunCancellationToken.cs | 16 ++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Adapter/MSTest.TestAdapter/Execution/TestExecutionManager.cs b/src/Adapter/MSTest.TestAdapter/Execution/TestExecutionManager.cs index bd5dde9130..665aa928a9 100644 --- a/src/Adapter/MSTest.TestAdapter/Execution/TestExecutionManager.cs +++ b/src/Adapter/MSTest.TestAdapter/Execution/TestExecutionManager.cs @@ -618,15 +618,15 @@ private async Task ExecuteTestsWithTestRunnerAsync( var testContextProperties = new Dictionary(capacity: 8); // Add tcm properties. - foreach ((TestProperty key, object? value) in tcmProperties) + foreach (KeyValuePair kvp in tcmProperties) { - testContextProperties[key.Id] = value; + testContextProperties[kvp.Key.Id] = kvp.Value; } // Add source level parameters. - foreach ((string key, object value) in sourceLevelParameters) + foreach (KeyValuePair kvp in sourceLevelParameters) { - testContextProperties[key] = value; + testContextProperties[kvp.Key] = kvp.Value; } return testContextProperties; diff --git a/src/Adapter/MSTest.TestAdapter/Execution/TestRunCancellationToken.cs b/src/Adapter/MSTest.TestAdapter/Execution/TestRunCancellationToken.cs index fbd7b24255..398d50e358 100644 --- a/src/Adapter/MSTest.TestAdapter/Execution/TestRunCancellationToken.cs +++ b/src/Adapter/MSTest.TestAdapter/Execution/TestRunCancellationToken.cs @@ -1,6 +1,10 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; +using System.Collections.Concurrent; +using System.Threading; + namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter; /// @@ -17,7 +21,7 @@ public class TestRunCancellationToken /// Callbacks to be invoked when canceled. /// Needs to be a concurrent collection, see https://github.com/microsoft/testfx/issues/3953. /// - private readonly ConcurrentBag<(Action, object?)> _registeredCallbacks = new(); + private readonly ConcurrentBag, object?>> _registeredCallbacks = new(); /// /// Gets a value indicating whether the test run is canceled. @@ -32,9 +36,9 @@ private set if (!previousValue && value) { - foreach ((Action callBack, object? state) in _registeredCallbacks) + foreach (var callbackInfo in _registeredCallbacks) { - callBack.Invoke(state); + callbackInfo.Item1.Invoke(callbackInfo.Item2); } } } @@ -49,9 +53,9 @@ private set /// Registers a callback method to be invoked when canceled. /// /// Callback delegate for handling cancellation. - public void Register(Action callback) => _registeredCallbacks.Add((_ => callback(), null)); + public void Register(Action callback) => _registeredCallbacks.Add(Tuple.Create, object?>((_ => callback()), null)); - internal void Register(Action callback, object? state) => _registeredCallbacks.Add((callback, state)); + internal void Register(Action callback, object? state) => _registeredCallbacks.Add(Tuple.Create(callback, state)); /// /// Unregister the callback method. From 20cd20798cbac029a6a3758d96ed054773241caf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 May 2025 12:27:55 +0000 Subject: [PATCH 3/4] Fix deconstruction in DeploymentItemUtility.cs Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com> --- .../Utilities/DeploymentItemUtility.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentItemUtility.cs b/src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentItemUtility.cs index bd8c0d78e6..44e4516943 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentItemUtility.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentItemUtility.cs @@ -259,9 +259,9 @@ private static List GetDeploymentItems(IEnumerable deploymentIte IList result = new List(); - foreach ((string? key, string? value) in deploymentItemsData) + foreach (KeyValuePair kvp in deploymentItemsData) { - AddDeploymentItem(result, new DeploymentItem(key, value)); + AddDeploymentItem(result, new DeploymentItem(kvp.Key, kvp.Value)); } return result; From e08f8fd234894adaa3ebd2205239efe869e575e2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 May 2025 12:35:10 +0000 Subject: [PATCH 4/4] Revert changes to TestRunCancellationToken.cs Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com> --- .../Execution/TestRunCancellationToken.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Adapter/MSTest.TestAdapter/Execution/TestRunCancellationToken.cs b/src/Adapter/MSTest.TestAdapter/Execution/TestRunCancellationToken.cs index 398d50e358..fbd7b24255 100644 --- a/src/Adapter/MSTest.TestAdapter/Execution/TestRunCancellationToken.cs +++ b/src/Adapter/MSTest.TestAdapter/Execution/TestRunCancellationToken.cs @@ -1,10 +1,6 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using System.Collections.Concurrent; -using System.Threading; - namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter; /// @@ -21,7 +17,7 @@ public class TestRunCancellationToken /// Callbacks to be invoked when canceled. /// Needs to be a concurrent collection, see https://github.com/microsoft/testfx/issues/3953. /// - private readonly ConcurrentBag, object?>> _registeredCallbacks = new(); + private readonly ConcurrentBag<(Action, object?)> _registeredCallbacks = new(); /// /// Gets a value indicating whether the test run is canceled. @@ -36,9 +32,9 @@ private set if (!previousValue && value) { - foreach (var callbackInfo in _registeredCallbacks) + foreach ((Action callBack, object? state) in _registeredCallbacks) { - callbackInfo.Item1.Invoke(callbackInfo.Item2); + callBack.Invoke(state); } } } @@ -53,9 +49,9 @@ private set /// Registers a callback method to be invoked when canceled. /// /// Callback delegate for handling cancellation. - public void Register(Action callback) => _registeredCallbacks.Add(Tuple.Create, object?>((_ => callback()), null)); + public void Register(Action callback) => _registeredCallbacks.Add((_ => callback(), null)); - internal void Register(Action callback, object? state) => _registeredCallbacks.Add(Tuple.Create(callback, state)); + internal void Register(Action callback, object? state) => _registeredCallbacks.Add((callback, state)); /// /// Unregister the callback method.