From 7efc5c284d1bc7e6916338129691ecc236eff961 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 7 May 2020 17:58:07 +0200 Subject: [PATCH 01/58] v1 --- .../Messages/MessageType.cs | 10 ++++ .../Messages/TestSessionCompletePayload.cs | 21 +++++++ .../Interfaces/ITestPlatformEventSource.cs | 49 +++++++++++++++ .../Tracing/TestPlatformEventSource.cs | 56 +++++++++++++++++ .../TestPlatformInstrumentationEvents.cs | 40 +++++++++++++ .../Interfaces/ITestSessionEventsHandler.cs | 19 ++++++ .../Payloads/OnTestSessionEndPayload.cs | 20 +++++++ .../ITranslationLayerRequestSender.cs | 7 +++ .../Interfaces/IVsTestConsoleWrapper2.cs | 23 +++++++ .../Resources/Resources.Designer.cs | 41 ++++++++----- .../Resources/Resources.resx | 3 + .../VsTestConsoleRequestSender.cs | 60 +++++++++++++++++++ .../VsTestConsoleWrapper.cs | 10 +++- 13 files changed, 342 insertions(+), 17 deletions(-) create mode 100644 src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestSessionCompletePayload.cs create mode 100644 src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestSessionEventsHandler.cs create mode 100644 src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/OnTestSessionEndPayload.cs create mode 100644 src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs index eb489480be..ca9ee015a2 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs @@ -123,6 +123,16 @@ public static class MessageType /// public const string CustomTestHostLaunchCallback = "TestExecution.CustomTestHostLaunchCallback"; + /// + /// Test session end + /// + public const string OnTestSessionEnd = "TestExecution.OnTestSessionEnd"; + + /// + /// Test session end callback + /// + public const string OnTestSessionEndCallback = "TestExecution.OnTestSessionEnd"; + /// /// Extensions Initialization /// diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestSessionCompletePayload.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestSessionCompletePayload.cs new file mode 100644 index 0000000000..d280d8c44d --- /dev/null +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestSessionCompletePayload.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel +{ + using System.Collections.Generic; + + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + + /// + /// The test run complete payload. + /// + public class TestSessionCompletePayload + { + /// + /// Gets or sets the attachments. + /// + public ICollection Attachments { get; set; } + } +} diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs index 137924573b..961a9963bb 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs @@ -182,5 +182,54 @@ public interface ITestPlatformEventSource /// Mark the completion of Metrics Dispose. /// void MetricsDisposeStop(); + + /// + /// The session finalization request start. + /// + void SessionFinalizationRequestStart(); + + /// + /// The session finalization request stop. + /// + void SessionFinalizationRequestStop(); + + /// + /// The adapter session finalization start. + /// + /// + /// The number of attachements. + /// + void AdapterSessionFinalizationStart(long numberOfAttachements); + + /// + /// The adapter session finalization stop. + /// + /// + /// The number of attachements. + /// + void AdapterSessionFinalizationStop(long numberOfAttachements); + + /// + /// The session finalization start. + /// + void SessionFinalizationStart(); + + /// + /// The session finalization stop. + /// + /// + /// The number of attachements. + /// + void SessionFinalizationStop(long numberOfAttachements); + + /// + /// Mark the start of translation layer session finalization request. + /// + void TranslationLayerSessionFinalizationStart(); + + /// + /// Mark the completion of translation layer session finalization request. + /// + void TranslationLayerSessionFinalizationStop(); } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs index 10e71e7a91..f0444bbde6 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs @@ -237,5 +237,61 @@ public void MetricsDisposeStop() { this.WriteEvent(TestPlatformInstrumentationEvents.MetricsDisposeStopEventId); } + + /// + [Event(TestPlatformInstrumentationEvents.SessionFinalizationRequestStartEventId)] + public void SessionFinalizationRequestStart() + { + this.WriteEvent(TestPlatformInstrumentationEvents.SessionFinalizationRequestStartEventId); + } + + /// + [Event(TestPlatformInstrumentationEvents.SessionFinalizationRequestStopEventId)] + public void SessionFinalizationRequestStop() + { + this.WriteEvent(TestPlatformInstrumentationEvents.SessionFinalizationRequestStopEventId); + } + + /// + [Event(TestPlatformInstrumentationEvents.AdapterSessionFinalizationStartEventId)] + public void AdapterSessionFinalizationStart(long numberOfAttachements) + { + this.WriteEvent(TestPlatformInstrumentationEvents.AdapterSessionFinalizationStartEventId, numberOfAttachements); + } + + /// + [Event(TestPlatformInstrumentationEvents.AdapterSessionFinalizationStopEventId)] + public void AdapterSessionFinalizationStop(long numberOfAttachements) + { + this.WriteEvent(TestPlatformInstrumentationEvents.AdapterSessionFinalizationStopEventId, numberOfAttachements); + } + + /// + [Event(TestPlatformInstrumentationEvents.SessionFinalizationStartEventId)] + public void SessionFinalizationStart() + { + this.WriteEvent(TestPlatformInstrumentationEvents.SessionFinalizationStartEventId); + } + + /// + [Event(TestPlatformInstrumentationEvents.SessionFinalizationStopEventId)] + public void SessionFinalizationStop(long numberOfAttachements) + { + this.WriteEvent(TestPlatformInstrumentationEvents.SessionFinalizationStopEventId, numberOfAttachements); + } + + /// + [Event(TestPlatformInstrumentationEvents.TranslationLayerSessionFinalizationStartEventId)] + public void TranslationLayerSessionFinalizationStart() + { + this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerSessionFinalizationStartEventId); + } + + /// + [Event(TestPlatformInstrumentationEvents.TranslationLayerSessionFinalizationStopEventId)] + public void TranslationLayerSessionFinalizationStop() + { + this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerSessionFinalizationStopEventId); + } } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs index 629d8cd45c..1eadce444d 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs @@ -157,5 +157,45 @@ internal class TestPlatformInstrumentationEvents /// Event fired on Metrics Dispose completes. /// public const int MetricsDisposeStopEventId = 0x39; + + /// + /// The session finalization start event id. + /// + public const int SessionFinalizationStartEventId = 0x40; + + /// + /// The session finalization stop event id. + /// + public const int SessionFinalizationStopEventId = 0x41; + + /// + /// The session finalization request start event id. + /// + public const int SessionFinalizationRequestStartEventId = 0x42; + + /// + /// The session finalization request stop event id. + /// + public const int SessionFinalizationRequestStopEventId = 0x43; + + /// + /// The adapter session finalization start event id. + /// + public const int AdapterSessionFinalizationStartEventId = 0x44; + + /// + /// The adapter session finalization stop event id. + /// + public const int AdapterSessionFinalizationStopEventId = 0x45; + + /// + /// Events fired on session finalization start of translation layer. + /// + public const int TranslationLayerSessionFinalizationStartEventId = 0x46; + + /// + /// Events fired on session finalization complete in translation layer. + /// + public const int TranslationLayerSessionFinalizationStopEventId = 0x47; } } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestSessionEventsHandler.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestSessionEventsHandler.cs new file mode 100644 index 0000000000..70fde7bac3 --- /dev/null +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestSessionEventsHandler.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client +{ + using System.Collections.Generic; + + /// + /// Interface contract for handling test session complete events + /// + public interface ITestSessionEventsHandler : ITestMessageEventHandler + { + /// + /// Dispatch SessionComplete event to listeners. + /// + /// Attachments reprocessed. + void HandleTestSessionComplete(IEnumerable attachments); + } +} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/OnTestSessionEndPayload.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/OnTestSessionEndPayload.cs new file mode 100644 index 0000000000..b0df025524 --- /dev/null +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/OnTestSessionEndPayload.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Payloads +{ + using System.Collections.Generic; + using System.Runtime.Serialization; + + /// + /// Class used to define the OnTestSessionEndPayload sent by the Vstest.console translation layers into design mode + /// + public class OnTestSessionEndPayload + { + /// + /// Settings used for the discovery request. + /// + [DataMember] + public IEnumerable Attachments { get; set; } + } +} diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs index aabf810570..2d7de0e0e6 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs @@ -110,5 +110,12 @@ internal interface ITranslationLayerRequestSender : IDisposable /// Cancels the discovery of tests /// void CancelDiscovery(); + + /// + /// Provides back all attachements to TestPlatform for additional processing (for example merging) + /// + /// List of attachements + /// + void OnTestSessionEnd(IEnumerable attachments, ITestSessionEventsHandler testSessionEventsHandler); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs new file mode 100644 index 0000000000..11d1980b53 --- /dev/null +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces +{ + using System.Collections.Generic; + + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + + /// + /// Controller for various test operations on the test runner. + /// + public interface IVsTestConsoleWrapper2 : IVsTestConsoleWrapper + { + /// + /// Provides back all attachements to TestPlatform for additional processing (for example merging) + /// + /// List of attachements + /// EventHandler to receive session complete event + void OnTestSessionEnd(IEnumerable attachments, ITestSessionEventsHandler testSessionEventsHandler); + } +} diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs index b0401e605b..e7fa34be5d 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs @@ -10,7 +10,6 @@ namespace Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Resources { using System; - using System.Reflection; /// @@ -20,10 +19,10 @@ namespace Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Res // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - public class Resources { + internal class Resources { private static global::System.Resources.ResourceManager resourceMan; @@ -37,10 +36,11 @@ internal Resources() { /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - public static global::System.Resources.ResourceManager ResourceManager { + internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Resources.Resources", typeof(Resources).GetTypeInfo().Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Resources.Reso" + + "urces", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; @@ -52,7 +52,7 @@ internal Resources() { /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - public static global::System.Globalization.CultureInfo Culture { + internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -60,47 +60,56 @@ internal Resources() { resourceCulture = value; } } - + + /// + /// Looks up a localized string similar to The active Session Finalization was aborted.. + /// + internal static string AbortedSessionFinalization { + get { + return ResourceManager.GetString("AbortedSessionFinalization", resourceCulture); + } + } + /// /// Looks up a localized string similar to The active Tests Discovery was aborted.. /// - public static string AbortedTestsDiscovery { + internal static string AbortedTestsDiscovery { get { return ResourceManager.GetString("AbortedTestsDiscovery", resourceCulture); } } - + /// /// Looks up a localized string similar to The active Tests Run was aborted.. /// - public static string AbortedTestsRun { + internal static string AbortedTestsRun { get { return ResourceManager.GetString("AbortedTestsRun", resourceCulture); } } - + /// /// Looks up a localized string similar to Failed to receive message from vstest.console process. /// - public static string FailedToReceiveMessage { + internal static string FailedToReceiveMessage { get { return ResourceManager.GetString("FailedToReceiveMessage", resourceCulture); } } - + /// /// Looks up a localized string similar to File {0} does not exists. /// - public static string InvalidFilePath { + internal static string InvalidFilePath { get { return ResourceManager.GetString("InvalidFilePath", resourceCulture); } } - + /// /// Looks up a localized string similar to vstest.console process exited abnormally. /// - public static string VsTestProcessExitedAbnormally { + internal static string VsTestProcessExitedAbnormally { get { return ResourceManager.GetString("VsTestProcessExitedAbnormally", resourceCulture); } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx index a52549c171..882efb6704 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + The active Session Finalization was aborted. + The active Tests Discovery was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index c5053dbf7a..7a3f57463b 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -19,6 +19,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Payloads; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using TranslationLayerResources = Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Resources.Resources; @@ -383,6 +384,12 @@ public void EndSession() this.communicationManager.SendMessage(MessageType.SessionEnd); } + /// + public void OnTestSessionEnd(IEnumerable attachments, ITestSessionEventsHandler testSessionEventsHandler) + { + this.SendMessageAndListenAndReportAttachements(attachments, testSessionEventsHandler); + } + /// /// Closes the communication channel /// @@ -717,6 +724,59 @@ private async Task SendMessageAndListenAndReportTestResultsAsync(string messageT this.testPlatformEventSource.TranslationLayerExecutionStop(); } + private void SendMessageAndListenAndReportAttachements(IEnumerable attachments, ITestSessionEventsHandler eventHandler) + { + try + { + var payload = new OnTestSessionEndPayload + { + Attachments = attachments + }; + this.communicationManager.SendMessage(MessageType.OnTestSessionEnd, payload); + var isSessionComplete = false; + + // Cycle through the messages that the vstest.console sends. + // Currently each of the operations are not separate tasks since they should not each take much time. + // This is just a notification. + while (!isSessionComplete) + { + var message = this.TryReceiveMessage(); + + if (string.Equals(MessageType.OnTestSessionEndCallback, message.MessageType)) + { + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("VsTestConsoleRequestSender.SendMessageAndListenAndReportAttachements: Process complete."); + } + + var testSessionCompletePayload = this.dataSerializer.DeserializePayload(message); + + eventHandler.HandleTestSessionComplete(testSessionCompletePayload.Attachments); + isSessionComplete = true; + } + else if (string.Equals(MessageType.TestMessage, message.MessageType)) + { + var testMessagePayload = this.dataSerializer.DeserializePayload(message); + eventHandler.HandleLogMessage(testMessagePayload.MessageLevel, testMessagePayload.Message); + } + } + } + catch (Exception exception) + { + EqtTrace.Error("Aborting Test Session End Operation: {0}", exception); + eventHandler.HandleLogMessage(TestMessageLevel.Error, TranslationLayerResources.AbortedSessionFinalization); + eventHandler.HandleTestSessionComplete(null); + + // Earlier we were closing the connection with vstest.console in case of exceptions + // Removing that code because vstest.console might be in a healthy state and letting the client + // know of the error, so that the TL can wait for the next instruction from the client itself. + // Also, connection termination might not kill the process which could result in files being locked by testhost. + } + + // TODO: do we need events? + this.testPlatformEventSource.TranslationLayerSessionFinalizationStop(); + } + private Message TryReceiveMessage() { Message message = null; diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index 42f587d0f4..378850eda0 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -24,7 +24,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer /// An implementation of to invoke test operations /// via the vstest.console test runner. /// - public class VsTestConsoleWrapper : IVsTestConsoleWrapper + public class VsTestConsoleWrapper : IVsTestConsoleWrapper2 { #region Private Members @@ -273,6 +273,14 @@ public void EndSession() this.sessionStarted = false; } + /// + public void OnTestSessionEnd(IEnumerable attachments, ITestSessionEventsHandler testSessionEventsHandler) + { + this.EnsureInitialized(); + + this.requestSender.OnTestSessionEnd(attachments, testSessionEventsHandler); + } + #endregion private void EnsureInitialized() From 8e88dea41756c2005008c9f482c3429a3a0e0f4c Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 19 May 2020 17:24:17 +0200 Subject: [PATCH 02/58] Merging v1 --- .../Interfaces/IVsTestConsoleWrapper2.cs | 3 ++- .../VsTestConsoleWrapper.cs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs index 11d1980b53..10e4a7379a 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs @@ -18,6 +18,7 @@ public interface IVsTestConsoleWrapper2 : IVsTestConsoleWrapper /// /// List of attachements /// EventHandler to receive session complete event - void OnTestSessionEnd(IEnumerable attachments, ITestSessionEventsHandler testSessionEventsHandler); + void FinalizeMultiTestRuns(IEnumerable attachments, ITestSessionEventsHandler testSessionEventsHandler); + // void FinalizeTests(IEnumerable attachments, ITestSessionEventsHandler testSessionEventsHandler); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index 378850eda0..48d44765d5 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -279,6 +279,7 @@ public void OnTestSessionEnd(IEnumerable attachments, ITestSessio this.EnsureInitialized(); this.requestSender.OnTestSessionEnd(attachments, testSessionEventsHandler); + this.requestSender.FinalizeSession(attachments, testSessionEventsHandler); } #endregion From 1cae4c582a6960e5e8f6d6a4992f8cde21c1f67a Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 21 May 2020 13:46:05 +0200 Subject: [PATCH 03/58] Rename to MultiTestRunsFinalization --- .../Messages/MessageType.cs | 8 ++-- ...ltiTestRunsFinalizationCompletePayload.cs} | 5 +- .../Interfaces/ITestPlatformEventSource.cs | 32 ++++++------- .../Tracing/TestPlatformEventSource.cs | 48 +++++++++---------- .../TestPlatformInstrumentationEvents.cs | 16 +++---- ...tRunsFinalizationCompleteEventsHandler.cs} | 6 +-- ...cs => MultiTestRunsFinalizationPayload.cs} | 4 +- .../ITranslationLayerRequestSender.cs | 4 +- .../Interfaces/IVsTestConsoleWrapper2.cs | 5 +- .../Resources/Resources.Designer.cs | 6 +-- .../Resources/Resources.resx | 4 +- .../VsTestConsoleRequestSender.cs | 26 +++++----- .../VsTestConsoleWrapper.cs | 9 ++-- 13 files changed, 87 insertions(+), 86 deletions(-) rename src/Microsoft.TestPlatform.CommunicationUtilities/Messages/{TestSessionCompletePayload.cs => MultiTestRunsFinalizationCompletePayload.cs} (78%) rename src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/{ITestSessionEventsHandler.cs => IMultiTestRunsFinalizationCompleteEventsHandler.cs} (64%) rename src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/{OnTestSessionEndPayload.cs => MultiTestRunsFinalizationPayload.cs} (75%) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs index 1afc0e0350..d4564a3c45 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs @@ -124,14 +124,14 @@ public static class MessageType public const string CustomTestHostLaunchCallback = "TestExecution.CustomTestHostLaunchCallback"; /// - /// Test session end + /// Multi test runs finalization /// - public const string OnTestSessionEnd = "TestExecution.OnTestSessionEnd"; + public const string MultiTestRunsFinalization = "TestExecution.MultiTestRunsFinalization"; /// - /// Test session end callback + /// Multi test runs finalization callback /// - public const string OnTestSessionEndCallback = "TestExecution.OnTestSessionEnd"; + public const string MultiTestRunsFinalizationCallback = "TestExecution.MultiTestRunsFinalizationCallback"; /// /// Extensions Initialization diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestSessionCompletePayload.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunsFinalizationCompletePayload.cs similarity index 78% rename from src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestSessionCompletePayload.cs rename to src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunsFinalizationCompletePayload.cs index d280d8c44d..457f539d86 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestSessionCompletePayload.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunsFinalizationCompletePayload.cs @@ -6,12 +6,11 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel using System.Collections.Generic; using Microsoft.VisualStudio.TestPlatform.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; /// - /// The test run complete payload. + /// Multi test runs finalization complete payload. /// - public class TestSessionCompletePayload + public class MultiTestRunsFinalizationCompletePayload { /// /// Gets or sets the attachments. diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs index 961a9963bb..db84bd3bd6 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs @@ -184,52 +184,52 @@ public interface ITestPlatformEventSource void MetricsDisposeStop(); /// - /// The session finalization request start. + /// The multi test runs finalization request start. /// - void SessionFinalizationRequestStart(); + void MultiTestRunsFinalizationRequestStart(); /// - /// The session finalization request stop. + /// The multi test runs finalization request stop. /// - void SessionFinalizationRequestStop(); + void MultiTestRunsFinalizationRequestStop(); /// - /// The adapter session finalization start. + /// The adapter multi test runs finalization start. /// /// /// The number of attachements. /// - void AdapterSessionFinalizationStart(long numberOfAttachements); + void AdapterMultiTestRunsFinalizationStart(long numberOfAttachements); /// - /// The adapter session finalization stop. + /// The adapter multi test runs finalization stop. /// /// /// The number of attachements. /// - void AdapterSessionFinalizationStop(long numberOfAttachements); + void AdapterMultiTestRunsFinalizationStop(long numberOfAttachements); /// - /// The session finalization start. + /// The multi test runs finalization start. /// - void SessionFinalizationStart(); + void MultiTestRunsFinalizationStart(); /// - /// The session finalization stop. + /// The multi test runs finalization stop. /// /// /// The number of attachements. /// - void SessionFinalizationStop(long numberOfAttachements); + void MultiTestRunsFinalizationStop(long numberOfAttachements); /// - /// Mark the start of translation layer session finalization request. + /// Mark the start of translation layer multi test runs finalization request. /// - void TranslationLayerSessionFinalizationStart(); + void TranslationLayerMultiTestRunsFinalizationStart(); /// - /// Mark the completion of translation layer session finalization request. + /// Mark the completion of translation layer multi test runs finalization request. /// - void TranslationLayerSessionFinalizationStop(); + void TranslationLayerMultiTestRunsFinalizationStop(); } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs index f0444bbde6..edf6846b19 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs @@ -239,59 +239,59 @@ public void MetricsDisposeStop() } /// - [Event(TestPlatformInstrumentationEvents.SessionFinalizationRequestStartEventId)] - public void SessionFinalizationRequestStart() + [Event(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationRequestStartEventId)] + public void MultiTestRunsFinalizationRequestStart() { - this.WriteEvent(TestPlatformInstrumentationEvents.SessionFinalizationRequestStartEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationRequestStartEventId); } /// - [Event(TestPlatformInstrumentationEvents.SessionFinalizationRequestStopEventId)] - public void SessionFinalizationRequestStop() + [Event(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationRequestStopEventId)] + public void MultiTestRunsFinalizationRequestStop() { - this.WriteEvent(TestPlatformInstrumentationEvents.SessionFinalizationRequestStopEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationRequestStopEventId); } /// - [Event(TestPlatformInstrumentationEvents.AdapterSessionFinalizationStartEventId)] - public void AdapterSessionFinalizationStart(long numberOfAttachements) + [Event(TestPlatformInstrumentationEvents.AdapterMultiTestRunsFinalizationStartEventId)] + public void AdapterMultiTestRunsFinalizationStart(long numberOfAttachements) { - this.WriteEvent(TestPlatformInstrumentationEvents.AdapterSessionFinalizationStartEventId, numberOfAttachements); + this.WriteEvent(TestPlatformInstrumentationEvents.AdapterMultiTestRunsFinalizationStartEventId, numberOfAttachements); } /// - [Event(TestPlatformInstrumentationEvents.AdapterSessionFinalizationStopEventId)] - public void AdapterSessionFinalizationStop(long numberOfAttachements) + [Event(TestPlatformInstrumentationEvents.AdapterMultiTestRunsFinalizationStopEventId)] + public void AdapterMultiTestRunsFinalizationStop(long numberOfAttachements) { - this.WriteEvent(TestPlatformInstrumentationEvents.AdapterSessionFinalizationStopEventId, numberOfAttachements); + this.WriteEvent(TestPlatformInstrumentationEvents.AdapterMultiTestRunsFinalizationStopEventId, numberOfAttachements); } /// - [Event(TestPlatformInstrumentationEvents.SessionFinalizationStartEventId)] - public void SessionFinalizationStart() + [Event(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationStartEventId)] + public void MultiTestRunsFinalizationStart() { - this.WriteEvent(TestPlatformInstrumentationEvents.SessionFinalizationStartEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationStartEventId); } /// - [Event(TestPlatformInstrumentationEvents.SessionFinalizationStopEventId)] - public void SessionFinalizationStop(long numberOfAttachements) + [Event(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationStopEventId)] + public void MultiTestRunsFinalizationStop(long numberOfAttachements) { - this.WriteEvent(TestPlatformInstrumentationEvents.SessionFinalizationStopEventId, numberOfAttachements); + this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationStopEventId, numberOfAttachements); } /// - [Event(TestPlatformInstrumentationEvents.TranslationLayerSessionFinalizationStartEventId)] - public void TranslationLayerSessionFinalizationStart() + [Event(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunsFinalizationStartEventId)] + public void TranslationLayerMultiTestRunsFinalizationStart() { - this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerSessionFinalizationStartEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunsFinalizationStartEventId); } /// - [Event(TestPlatformInstrumentationEvents.TranslationLayerSessionFinalizationStopEventId)] - public void TranslationLayerSessionFinalizationStop() + [Event(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunsFinalizationStopEventId)] + public void TranslationLayerMultiTestRunsFinalizationStop() { - this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerSessionFinalizationStopEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunsFinalizationStopEventId); } } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs index 1eadce444d..9931100f1c 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs @@ -161,41 +161,41 @@ internal class TestPlatformInstrumentationEvents /// /// The session finalization start event id. /// - public const int SessionFinalizationStartEventId = 0x40; + public const int MultiTestRunsFinalizationStartEventId = 0x40; /// /// The session finalization stop event id. /// - public const int SessionFinalizationStopEventId = 0x41; + public const int MultiTestRunsFinalizationStopEventId = 0x41; /// /// The session finalization request start event id. /// - public const int SessionFinalizationRequestStartEventId = 0x42; + public const int MultiTestRunsFinalizationRequestStartEventId = 0x42; /// /// The session finalization request stop event id. /// - public const int SessionFinalizationRequestStopEventId = 0x43; + public const int MultiTestRunsFinalizationRequestStopEventId = 0x43; /// /// The adapter session finalization start event id. /// - public const int AdapterSessionFinalizationStartEventId = 0x44; + public const int AdapterMultiTestRunsFinalizationStartEventId = 0x44; /// /// The adapter session finalization stop event id. /// - public const int AdapterSessionFinalizationStopEventId = 0x45; + public const int AdapterMultiTestRunsFinalizationStopEventId = 0x45; /// /// Events fired on session finalization start of translation layer. /// - public const int TranslationLayerSessionFinalizationStartEventId = 0x46; + public const int TranslationLayerMultiTestRunsFinalizationStartEventId = 0x46; /// /// Events fired on session finalization complete in translation layer. /// - public const int TranslationLayerSessionFinalizationStopEventId = 0x47; + public const int TranslationLayerMultiTestRunsFinalizationStopEventId = 0x47; } } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestSessionEventsHandler.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationCompleteEventsHandler.cs similarity index 64% rename from src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestSessionEventsHandler.cs rename to src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationCompleteEventsHandler.cs index 70fde7bac3..3b18128664 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestSessionEventsHandler.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationCompleteEventsHandler.cs @@ -6,14 +6,14 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client using System.Collections.Generic; /// - /// Interface contract for handling test session complete events + /// Interface contract for handling multi test runs finalization complete events /// - public interface ITestSessionEventsHandler : ITestMessageEventHandler + public interface IMultiTestRunsFinalizationCompleteEventsHandler : ITestMessageEventHandler { /// /// Dispatch SessionComplete event to listeners. /// /// Attachments reprocessed. - void HandleTestSessionComplete(IEnumerable attachments); + void HandleMultiTestRunsFinalizationComplete(IEnumerable attachments); } } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/OnTestSessionEndPayload.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunsFinalizationPayload.cs similarity index 75% rename from src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/OnTestSessionEndPayload.cs rename to src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunsFinalizationPayload.cs index b0df025524..662c6dc6f6 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/OnTestSessionEndPayload.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunsFinalizationPayload.cs @@ -7,9 +7,9 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Payloads using System.Runtime.Serialization; /// - /// Class used to define the OnTestSessionEndPayload sent by the Vstest.console translation layers into design mode + /// Class used to define the MultiTestRunsFinalizationPayload sent by the Vstest.console translation layers into design mode /// - public class OnTestSessionEndPayload + public class MultiTestRunsFinalizationPayload { /// /// Settings used for the discovery request. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs index 2d7de0e0e6..c5187d6b3e 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs @@ -115,7 +115,7 @@ internal interface ITranslationLayerRequestSender : IDisposable /// Provides back all attachements to TestPlatform for additional processing (for example merging) /// /// List of attachements - /// - void OnTestSessionEnd(IEnumerable attachments, ITestSessionEventsHandler testSessionEventsHandler); + /// + void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationCompleteEventsHandler multiTestRunsFinalizationCompleteEventsHandler); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs index 10e4a7379a..adb48aacb7 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs @@ -17,8 +17,7 @@ public interface IVsTestConsoleWrapper2 : IVsTestConsoleWrapper /// Provides back all attachements to TestPlatform for additional processing (for example merging) /// /// List of attachements - /// EventHandler to receive session complete event - void FinalizeMultiTestRuns(IEnumerable attachments, ITestSessionEventsHandler testSessionEventsHandler); - // void FinalizeTests(IEnumerable attachments, ITestSessionEventsHandler testSessionEventsHandler); + /// EventHandler to receive session complete event + void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationCompleteEventsHandler multiTestRunsFinalizationCompleteEventsHandler); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs index e7fa34be5d..97fa3b3bd9 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs @@ -62,11 +62,11 @@ internal Resources() { } /// - /// Looks up a localized string similar to The active Session Finalization was aborted.. + /// Looks up a localized string similar to The active Multi Test Runs Finalization was aborted.. /// - internal static string AbortedSessionFinalization { + internal static string AbortedMultiTestRunsFinalization { get { - return ResourceManager.GetString("AbortedSessionFinalization", resourceCulture); + return ResourceManager.GetString("AbortedMultiTestRunsFinalization", resourceCulture); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx index 882efb6704..c4dbc5499f 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx @@ -117,8 +117,8 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - The active Session Finalization was aborted. + + The active Multi Test Runs Finalization was aborted. The active Tests Discovery was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index d7ae9682f3..b0085b663c 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -385,7 +385,7 @@ public void EndSession() } /// - public void OnTestSessionEnd(IEnumerable attachments, ITestSessionEventsHandler testSessionEventsHandler) + public void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationCompleteEventsHandler testSessionEventsHandler) { this.SendMessageAndListenAndReportAttachements(attachments, testSessionEventsHandler); } @@ -732,35 +732,35 @@ private async Task SendMessageAndListenAndReportTestResultsAsync(string messageT this.testPlatformEventSource.TranslationLayerExecutionStop(); } - private void SendMessageAndListenAndReportAttachements(IEnumerable attachments, ITestSessionEventsHandler eventHandler) + private void SendMessageAndListenAndReportAttachements(IEnumerable attachments, IMultiTestRunsFinalizationCompleteEventsHandler eventHandler) { try { - var payload = new OnTestSessionEndPayload + var payload = new MultiTestRunsFinalizationPayload { Attachments = attachments }; - this.communicationManager.SendMessage(MessageType.OnTestSessionEnd, payload); - var isSessionComplete = false; + this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalization, payload); + var isMultiTestRunsFinalizationComplete = false; // Cycle through the messages that the vstest.console sends. // Currently each of the operations are not separate tasks since they should not each take much time. // This is just a notification. - while (!isSessionComplete) + while (!isMultiTestRunsFinalizationComplete) { var message = this.TryReceiveMessage(); - if (string.Equals(MessageType.OnTestSessionEndCallback, message.MessageType)) + if (string.Equals(MessageType.MultiTestRunsFinalizationCallback, message.MessageType)) { if (EqtTrace.IsInfoEnabled) { EqtTrace.Info("VsTestConsoleRequestSender.SendMessageAndListenAndReportAttachements: Process complete."); } - var testSessionCompletePayload = this.dataSerializer.DeserializePayload(message); + var multiTestRunsFinalizationCompletePayload = this.dataSerializer.DeserializePayload(message); - eventHandler.HandleTestSessionComplete(testSessionCompletePayload.Attachments); - isSessionComplete = true; + eventHandler.HandleMultiTestRunsFinalizationComplete(multiTestRunsFinalizationCompletePayload.Attachments); + isMultiTestRunsFinalizationComplete = true; } else if (string.Equals(MessageType.TestMessage, message.MessageType)) { @@ -772,8 +772,8 @@ private void SendMessageAndListenAndReportAttachements(IEnumerable - public void OnTestSessionEnd(IEnumerable attachments, ITestSessionEventsHandler testSessionEventsHandler) + public void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationCompleteEventsHandler testSessionEventsHandler) { this.EnsureInitialized(); - this.requestSender.OnTestSessionEnd(attachments, testSessionEventsHandler); - this.requestSender.FinalizeSession(attachments, testSessionEventsHandler); + this.requestSender.FinalizeMultiTestRuns(attachments, testSessionEventsHandler); } #endregion From 04aac62b055951c099253ac86c66a089fe54a8d4 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 21 May 2020 18:40:30 +0200 Subject: [PATCH 04/58] New version --- .../IMultiTestRunsFinalizationManager.cs | 24 +++++++++++++++++++ .../MultiTestRunsFinalizationManager.cs | 10 ++++++++ ...MultiTestRunsFinalizationEventsHandler.cs} | 2 +- .../ITranslationLayerRequestSender.cs | 2 +- .../Interfaces/IVsTestConsoleWrapper2.cs | 2 +- .../VsTestConsoleRequestSender.cs | 4 ++-- .../VsTestConsoleWrapper.cs | 5 ++-- 7 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs create mode 100644 src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs rename src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/{IMultiTestRunsFinalizationCompleteEventsHandler.cs => IMultiTestRunsFinalizationEventsHandler.cs} (87%) diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs new file mode 100644 index 0000000000..b67250e839 --- /dev/null +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol +{ + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + using System.Collections.Generic; + + namespace Microsoft.VisualStudio.TestPlatform.Common.Interfaces.Engine.TesthostProtocol + { + /// + /// Orchestrates multi test runs finalization operations for the engine communicating with the test host process. + /// + public interface IMultiTestRunsFinalizationManager + { + /// + /// Discovers tests + /// + /// Settings, parameters for the discovery request + /// EventHandler for handling discovery events from Engine + void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationEventsHandler eventHandler); + } + } +} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs new file mode 100644 index 0000000000..9fad708282 --- /dev/null +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunsFinalization +{ + class MultiTestRunsFinalizationManager + { + } +} diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationCompleteEventsHandler.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs similarity index 87% rename from src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationCompleteEventsHandler.cs rename to src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs index 3b18128664..ef5ec9f229 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationCompleteEventsHandler.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs @@ -8,7 +8,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client /// /// Interface contract for handling multi test runs finalization complete events /// - public interface IMultiTestRunsFinalizationCompleteEventsHandler : ITestMessageEventHandler + public interface IMultiTestRunsFinalizationEventsHandler : ITestMessageEventHandler { /// /// Dispatch SessionComplete event to listeners. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs index c5187d6b3e..9af7ac69f6 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs @@ -116,6 +116,6 @@ internal interface ITranslationLayerRequestSender : IDisposable /// /// List of attachements /// - void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationCompleteEventsHandler multiTestRunsFinalizationCompleteEventsHandler); + void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs index adb48aacb7..674a0dd0f5 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs @@ -18,6 +18,6 @@ public interface IVsTestConsoleWrapper2 : IVsTestConsoleWrapper /// /// List of attachements /// EventHandler to receive session complete event - void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationCompleteEventsHandler multiTestRunsFinalizationCompleteEventsHandler); + void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index b0085b663c..8c3d0f05d1 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -385,7 +385,7 @@ public void EndSession() } /// - public void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationCompleteEventsHandler testSessionEventsHandler) + public void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationEventsHandler testSessionEventsHandler) { this.SendMessageAndListenAndReportAttachements(attachments, testSessionEventsHandler); } @@ -732,7 +732,7 @@ private async Task SendMessageAndListenAndReportTestResultsAsync(string messageT this.testPlatformEventSource.TranslationLayerExecutionStop(); } - private void SendMessageAndListenAndReportAttachements(IEnumerable attachments, IMultiTestRunsFinalizationCompleteEventsHandler eventHandler) + private void SendMessageAndListenAndReportAttachements(IEnumerable attachments, IMultiTestRunsFinalizationEventsHandler eventHandler) { try { diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index 689c28943a..48f7796cfa 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -278,10 +278,11 @@ public void EndSession() #region IVsTestConsoleWrapper2 /// - public void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationCompleteEventsHandler testSessionEventsHandler) + public void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationEventsHandler testSessionEventsHandler) { - this.EnsureInitialized(); + this.testPlatformEventSource.TranslationLayerMultiTestRunsFinalizationStart(); + this.EnsureInitialized(); this.requestSender.FinalizeMultiTestRuns(attachments, testSessionEventsHandler); } From 91c8785959090ecb9be3d78f39a54b6db7aa2c56 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 21 May 2020 18:49:35 +0200 Subject: [PATCH 05/58] More changes --- .../Interfaces/IMultiTestRunsFinalizationEventsHandler.cs | 2 +- .../Resources/xlf/Resources.cs.xlf | 5 +++++ .../Resources/xlf/Resources.de.xlf | 5 +++++ .../Resources/xlf/Resources.es.xlf | 5 +++++ .../Resources/xlf/Resources.fr.xlf | 5 +++++ .../Resources/xlf/Resources.it.xlf | 5 +++++ .../Resources/xlf/Resources.ja.xlf | 5 +++++ .../Resources/xlf/Resources.ko.xlf | 5 +++++ .../Resources/xlf/Resources.pl.xlf | 5 +++++ .../Resources/xlf/Resources.pt-BR.xlf | 5 +++++ .../Resources/xlf/Resources.ru.xlf | 5 +++++ .../Resources/xlf/Resources.tr.xlf | 5 +++++ .../Resources/xlf/Resources.xlf | 5 +++++ .../Resources/xlf/Resources.zh-Hans.xlf | 5 +++++ .../Resources/xlf/Resources.zh-Hant.xlf | 5 +++++ 15 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs index ef5ec9f229..aad25a5359 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs @@ -11,7 +11,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client public interface IMultiTestRunsFinalizationEventsHandler : ITestMessageEventHandler { /// - /// Dispatch SessionComplete event to listeners. + /// Dispatch MultiTestRunsFinalizationComplete event to listeners. /// /// Attachments reprocessed. void HandleMultiTestRunsFinalizationComplete(IEnumerable attachments); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.cs.xlf index ab7c034843..b294113385 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.cs.xlf @@ -61,6 +61,11 @@ Soubor {0} neexistuje. + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.de.xlf index 361f2a9f80..f872f51df0 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.de.xlf @@ -61,6 +61,11 @@ Die Datei "{0}" ist nicht vorhanden. + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.es.xlf index 5566e1cd03..dae24bf8e2 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.es.xlf @@ -61,6 +61,11 @@ El archivo {0} no existe + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.fr.xlf index 5bef4c27d2..4bb65df96e 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.fr.xlf @@ -61,6 +61,11 @@ Le fichier {0} n'existe pas + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.it.xlf index b1e559d790..4cba448970 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.it.xlf @@ -61,6 +61,11 @@ Il file {0} non esiste + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ja.xlf index 8b58d1d21c..fbb25bc10b 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ja.xlf @@ -61,6 +61,11 @@ ファイル {0} が存在しません + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ko.xlf index 028bc0fa22..a66ea99bd5 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ko.xlf @@ -61,6 +61,11 @@ {0} 파일이 없습니다. + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pl.xlf index 7c09aa494f..bb5ca13bac 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pl.xlf @@ -61,6 +61,11 @@ Plik {0} nie istnieje + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pt-BR.xlf index 475cfc8773..42cbe9c639 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pt-BR.xlf @@ -61,6 +61,11 @@ O arquivo {0} não existe + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ru.xlf index 980e35e1fc..2703ec8608 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ru.xlf @@ -61,6 +61,11 @@ Файл {0} не существует. + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.tr.xlf index 2b9f819abc..c7602e8a39 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.tr.xlf @@ -61,6 +61,11 @@ {0} dosyası yok + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.xlf index e63797562a..13c519fae0 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.xlf @@ -23,6 +23,11 @@ File {0} does not exists + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hans.xlf index d566b9b20c..6913dfd7f4 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hans.xlf @@ -61,6 +61,11 @@ 文件 {0} 不存在 + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hant.xlf index b420856a52..17c5464473 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hant.xlf @@ -61,6 +61,11 @@ 檔案 {0} 不存在 + + The active Multi Test Runs Finalization was aborted. + The active Multi Test Runs Finalization was aborted. + + \ No newline at end of file From d799be6e0597b888ae64f3e23f4b5fe9b9caf15a Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 21 May 2020 20:35:00 +0200 Subject: [PATCH 06/58] More changes --- .../IMultiTestRunsFinalizationManager.cs | 25 +++---- .../MultiTestRunsFinalizationEventsHandler.cs | 74 +++++++++++++++++++ .../Interfaces/ITestRequestHandler.cs | 6 ++ .../Messages/MessageType.cs | 2 +- ...TestRunsDataCollectorAttachmentsHandler.cs | 42 +++++++++++ .../ParallelDataCollectionEventsHandler.cs | 28 +------ .../EventHandlers/TestRequestHandler.cs | 34 +++++++++ .../MultiTestRunsFinalizationManager.cs | 34 ++++++++- ...IMultiTestRunsFinalizationEventsHandler.cs | 6 +- .../MultiTestRunsFinalizationPayload.cs | 4 +- .../ITranslationLayerRequestSender.cs | 2 +- .../Interfaces/IVsTestConsoleWrapper2.cs | 2 +- .../VsTestConsoleRequestSender.cs | 7 +- .../VsTestConsoleWrapper.cs | 2 +- 14 files changed, 214 insertions(+), 54 deletions(-) create mode 100644 src/Microsoft.TestPlatform.CommunicationUtilities/EventHandlers/MultiTestRunsFinalizationEventsHandler.cs create mode 100644 src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/MultiTestRunsDataCollectorAttachmentsHandler.cs diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs index b67250e839..e21350c231 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs @@ -1,24 +1,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; +using System.Collections.Generic; + namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol { - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; - using System.Collections.Generic; - - namespace Microsoft.VisualStudio.TestPlatform.Common.Interfaces.Engine.TesthostProtocol + /// + /// Orchestrates multi test runs finalization operations for the engine communicating with the test host process. + /// + public interface IMultiTestRunsFinalizationManager { /// - /// Orchestrates multi test runs finalization operations for the engine communicating with the test host process. + /// Finalizes multi test runs /// - public interface IMultiTestRunsFinalizationManager - { - /// - /// Discovers tests - /// - /// Settings, parameters for the discovery request - /// EventHandler for handling discovery events from Engine - void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationEventsHandler eventHandler); - } + /// Attachments + /// EventHandler for handling multi test runs finalization events from Engine + void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler eventHandler); } } diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/EventHandlers/MultiTestRunsFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/EventHandlers/MultiTestRunsFinalizationEventsHandler.cs new file mode 100644 index 0000000000..bc4ba4b350 --- /dev/null +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/EventHandlers/MultiTestRunsFinalizationEventsHandler.cs @@ -0,0 +1,74 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.EventHandlers +{ + using System.Collections.Generic; + + using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + + /// + /// The multi test finalization event handler. + /// + public class MultiTestRunsFinalizationEventsHandler : IMultiTestRunsFinalizationEventsHandler + { + private ITestRequestHandler requestHandler; + + /// + /// Initializes a new instance of the class. + /// + /// The Request Handler. + public MultiTestRunsFinalizationEventsHandler(ITestRequestHandler requestHandler) + { + this.requestHandler = requestHandler; + } + + /// + /// The handle discovery message. + /// + /// Logging level. + /// Logging message. + public void HandleLogMessage(TestMessageLevel level, string message) + { + switch ((TestMessageLevel)level) + { + case TestMessageLevel.Informational: + EqtTrace.Info(message); + break; + + case TestMessageLevel.Warning: + EqtTrace.Warning(message); + break; + + case TestMessageLevel.Error: + EqtTrace.Error(message); + break; + + default: + EqtTrace.Info(message); + break; + } + + this.requestHandler.SendLog(level, message); + } + + public void HandleMultiTestRunsFinalizationComplete(ICollection attachments) + { + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("Multi test runs finalization completed."); + } + + this.requestHandler.MultiTestRunsFinalizationComplete(attachments); + } + + public void HandleRawMessage(string rawMessage) + { + // No-Op + // TestHost at this point has no functionality where it requires rawmessage + } + } +} diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestHandler.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestHandler.cs index 8908a72fc7..a83897979d 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestHandler.cs @@ -79,6 +79,12 @@ public interface ITestRequestHandler : IDisposable /// The last Chunk. void DiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable lastChunk); + /// + /// The multi test runs finalization complete handler + /// + /// Attachments + void MultiTestRunsFinalizationComplete(ICollection attachments); + /// /// Launches a process with a given process info under debugger /// Adapter get to call into this to launch any additional processes under debugger diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs index d4564a3c45..a5af0cd46a 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs @@ -131,7 +131,7 @@ public static class MessageType /// /// Multi test runs finalization callback /// - public const string MultiTestRunsFinalizationCallback = "TestExecution.MultiTestRunsFinalizationCallback"; + public const string MultiTestRunsFinalizationComplete = "TestExecution.MultiTestRunsFinalizationComplete"; /// /// Extensions Initialization diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/MultiTestRunsDataCollectorAttachmentsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/MultiTestRunsDataCollectorAttachmentsHandler.cs new file mode 100644 index 0000000000..cad95055ff --- /dev/null +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/MultiTestRunsDataCollectorAttachmentsHandler.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; + +namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection +{ + public class MultiTestRunsDataCollectorAttachmentsHandler + { + private readonly IDataCollectorAttachments dataCollectorAttachmentsHandler; + + public MultiTestRunsDataCollectorAttachmentsHandler(IDataCollectorAttachments dataCollectorAttachmentsHandler) + { + this.dataCollectorAttachmentsHandler = dataCollectorAttachmentsHandler; + } + + public void HandleAttachements(ICollection attachments) + { + Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); + if (attachementUri != null) + { + var coverageAttachments = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); + + foreach (var coverageAttachment in coverageAttachments) + { + attachments.Remove(coverageAttachment); + } + + ICollection mergedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(coverageAttachments)); + foreach (var attachment in mergedAttachments) + { + attachments.Add(attachment); + } + } + } + } +} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs index 0f5432cd78..67d9d2df70 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs @@ -3,10 +3,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection { - using System; using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Linq; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; @@ -19,6 +16,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection internal class ParallelDataCollectionEventsHandler : ParallelRunEventsHandler { private readonly ParallelRunDataAggregator runDataAggregator; + private readonly MultiTestRunsDataCollectorAttachmentsHandler attachmentsHandler; public ParallelDataCollectionEventsHandler(IRequestData requestData, IProxyExecutionManager proxyExecutionManager, @@ -27,6 +25,8 @@ public ParallelDataCollectionEventsHandler(IRequestData requestData, ParallelRunDataAggregator runDataAggregator) : this(requestData, proxyExecutionManager, actualRunEventsHandler, parallelProxyExecutionManager, runDataAggregator, JsonDataSerializer.Instance) { + // TODO : use TestPluginCache to iterate over all IDataCollectorAttachments + attachmentsHandler = new MultiTestRunsDataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()); } internal ParallelDataCollectionEventsHandler(IRequestData requestData, @@ -53,27 +53,7 @@ public override void HandleTestRunComplete( if (parallelRunComplete) { - // TODO : use TestPluginCache to iterate over all IDataCollectorAttachments - { - var coverageHandler = new CodeCoverageDataAttachmentsHandler(); - Uri attachementUri = coverageHandler.GetExtensionUri(); - if (attachementUri != null) - { - var coverageAttachments = runDataAggregator.RunContextAttachments - .Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); - - foreach (var coverageAttachment in coverageAttachments) - { - runDataAggregator.RunContextAttachments.Remove(coverageAttachment); - } - - ICollection attachments = coverageHandler.HandleDataCollectionAttachmentSets(new Collection(coverageAttachments)); - foreach (var attachment in attachments) - { - runDataAggregator.RunContextAttachments.Add(attachment); - } - } - } + attachmentsHandler.HandleAttachements(runDataAggregator.RunContextAttachments); var completedArgs = new TestRunCompleteEventArgs(this.runDataAggregator.GetAggregatedRunStats(), this.runDataAggregator.IsCanceled, diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs index 5319d0bb78..18759177dd 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs @@ -5,12 +5,15 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities { using System; using System.Collections.Generic; + using System.Linq; using System.Threading; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.EventHandlers; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.EventHandlers; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunsFinalization; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; @@ -193,6 +196,19 @@ public void DiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventA this.SendData(data); } + /// + public void MultiTestRunsFinalizationComplete(ICollection attachments) + { + var data = this.dataSerializer.SerializePayload( + MessageType.MultiTestRunsFinalizationComplete, + new MultiTestRunsFinalizationCompletePayload + { + Attachments = attachments + }, + this.protocolVersion); + this.SendData(data); + } + /// public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessStartInfo) { @@ -359,6 +375,24 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec break; } + case MessageType.MultiTestRunsFinalization: + { + EqtTrace.Info("Multi test runs finalization started."); + var multiTestRunsFinalizationEventsHandler = new MultiTestRunsFinalizationEventsHandler(this); + var multiTestRunsFinalizationManager = new MultiTestRunsFinalizationManager(new MultiTestRunsDataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler())); + var multiTestRunsFinalizationPayload = this.dataSerializer.DeserializePayload(message); + + jobQueue.QueueJob( + () => + multiTestRunsFinalizationManager + .FinalizeMultiTestRuns( + multiTestRunsFinalizationPayload.Attachments, + multiTestRunsFinalizationEventsHandler), + 0); + + break; + } + case MessageType.CancelTestRun: jobQueue.Pause(); this.testHostManagerFactoryReady.Wait(); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs index 9fad708282..7d338890f8 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs @@ -1,10 +1,38 @@ -using System; +// 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.Collections.Generic; -using System.Text; +using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; +using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol; namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunsFinalization { - class MultiTestRunsFinalizationManager + /// + /// Orchestrates multi test runs finalization operations for the engine communicating with the test host process. + /// + public class MultiTestRunsFinalizationManager : IMultiTestRunsFinalizationManager { + private readonly MultiTestRunsDataCollectorAttachmentsHandler attachmentsHandler; + + /// + /// Initializes a new instance of the class. + /// + public MultiTestRunsFinalizationManager(MultiTestRunsDataCollectorAttachmentsHandler attachmentsHandler) + { + this.attachmentsHandler = attachmentsHandler; + } + + /// + /// Finalizes multi test runs + /// + /// Attachments + /// EventHandler for handling multi test runs finalization events from Engine + public void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler eventHandler) + { + attachmentsHandler.HandleAttachements(attachments); + eventHandler.HandleMultiTestRunsFinalizationComplete(attachments); + } } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs index aad25a5359..ed4cbd7b8d 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs @@ -1,10 +1,10 @@ // 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.Collections.Generic; + namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client { - using System.Collections.Generic; - /// /// Interface contract for handling multi test runs finalization complete events /// @@ -14,6 +14,6 @@ public interface IMultiTestRunsFinalizationEventsHandler : ITestMessageEventHand /// Dispatch MultiTestRunsFinalizationComplete event to listeners. /// /// Attachments reprocessed. - void HandleMultiTestRunsFinalizationComplete(IEnumerable attachments); + void HandleMultiTestRunsFinalizationComplete(ICollection attachments); } } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunsFinalizationPayload.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunsFinalizationPayload.cs index 662c6dc6f6..63f81593e5 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunsFinalizationPayload.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunsFinalizationPayload.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Payloads +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client { using System.Collections.Generic; using System.Runtime.Serialization; @@ -15,6 +15,6 @@ public class MultiTestRunsFinalizationPayload /// Settings used for the discovery request. /// [DataMember] - public IEnumerable Attachments { get; set; } + public ICollection Attachments { get; set; } } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs index 9af7ac69f6..a8e73ab57c 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs @@ -116,6 +116,6 @@ internal interface ITranslationLayerRequestSender : IDisposable /// /// List of attachements /// - void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler); + void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs index 674a0dd0f5..9988ed548a 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs @@ -18,6 +18,6 @@ public interface IVsTestConsoleWrapper2 : IVsTestConsoleWrapper /// /// List of attachements /// EventHandler to receive session complete event - void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler); + void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index 8c3d0f05d1..b01516f499 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -19,7 +19,6 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Payloads; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using TranslationLayerResources = Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Resources.Resources; @@ -385,7 +384,7 @@ public void EndSession() } /// - public void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationEventsHandler testSessionEventsHandler) + public void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler testSessionEventsHandler) { this.SendMessageAndListenAndReportAttachements(attachments, testSessionEventsHandler); } @@ -732,7 +731,7 @@ private async Task SendMessageAndListenAndReportTestResultsAsync(string messageT this.testPlatformEventSource.TranslationLayerExecutionStop(); } - private void SendMessageAndListenAndReportAttachements(IEnumerable attachments, IMultiTestRunsFinalizationEventsHandler eventHandler) + private void SendMessageAndListenAndReportAttachements(ICollection attachments, IMultiTestRunsFinalizationEventsHandler eventHandler) { try { @@ -750,7 +749,7 @@ private void SendMessageAndListenAndReportAttachements(IEnumerable - public void FinalizeMultiTestRuns(IEnumerable attachments, IMultiTestRunsFinalizationEventsHandler testSessionEventsHandler) + public void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler testSessionEventsHandler) { this.testPlatformEventSource.TranslationLayerMultiTestRunsFinalizationStart(); From 872bbcc9a0938e613d3af107232c4ed102ba9239 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Fri, 22 May 2020 13:02:56 +0200 Subject: [PATCH 07/58] Next changes --- .../DesignMode/DesignModeClient.cs | 45 ++++ src/testhost.x86/testhost.x86.csproj | 1 + .../MultiTestRunsFinalizationEventHandler.cs | 86 +++++++ .../EventHandler/RunEventHandler.cs | 11 + .../FinalizeMultiTestRunsTests.cs | 243 ++++++++++++++++++ .../TranslationLayerTests/RunTests.cs | 2 +- .../IntegrationTestBase.cs | 2 +- 7 files changed, 388 insertions(+), 2 deletions(-) create mode 100644 test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunsFinalizationEventHandler.cs create mode 100644 test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index e4366b4c8b..056c992f08 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -17,11 +17,13 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; + using Microsoft.VisualStudio.TestPlatform.Utilities; using CommunicationUtilitiesResources = Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources.Resources; using CoreUtilitiesConstants = Microsoft.VisualStudio.TestPlatform.CoreUtilities.Constants; using ObjectModelConstants = Microsoft.VisualStudio.TestPlatform.ObjectModel.Constants; @@ -199,6 +201,14 @@ private void ProcessRequests(ITestRequestManager testRequestManager) break; } + case MessageType.MultiTestRunsFinalization: + { + var multiTestRunsFinalizationPayload = + this.communicationManager.DeserializePayload(message); + this.FinalizeMultiTestRuns(multiTestRunsFinalizationPayload); + break; + } + case MessageType.CancelDiscovery: { testRequestManager.CancelDiscovery(); @@ -458,6 +468,41 @@ private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITe }); } + private void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload finalizationPayload) + { + lock(this.lockObject) + { + try + { + var handler = new MultiTestRunsDataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()); + handler.HandleAttachements(finalizationPayload.Attachments); + + var payload = new MultiTestRunsFinalizationCompletePayload() + { + Attachments = finalizationPayload.Attachments + }; + + // Send run complete to translation layer + this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationComplete, payload); + } + catch (Exception ex) + { + EqtTrace.Error("DesignModeClient: Exception in StartDiscovery: " + ex); + + var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() }; + this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); + + var payload = new MultiTestRunsFinalizationCompletePayload() + { + Attachments = null + }; + + // Send run complete to translation layer + this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationComplete, payload); + } + } + } + #region IDisposable Support private bool disposedValue = false; // To detect redundant calls diff --git a/src/testhost.x86/testhost.x86.csproj b/src/testhost.x86/testhost.x86.csproj index d35578cbfb..02dea17fb1 100644 --- a/src/testhost.x86/testhost.x86.csproj +++ b/src/testhost.x86/testhost.x86.csproj @@ -8,6 +8,7 @@ testhost.x86 netcoreapp2.1;net451 netcoreapp2.1 + 2.1.15 true AnyCPU true diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunsFinalizationEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunsFinalizationEventHandler.cs new file mode 100644 index 0000000000..b2bad52b2d --- /dev/null +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunsFinalizationEventHandler.cs @@ -0,0 +1,86 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + + /// + public class MultiTestRunsFinalizationEventHandler : IMultiTestRunsFinalizationEventsHandler + { + /// + /// Gets the attachments. + /// + public List Attachments { get; private set; } + + /// + /// Gets the metrics. + /// + public IDictionary Metrics { get; private set; } + + /// + /// Gets the log message. + /// + public string LogMessage { get; private set; } + + public List Errors { get; set; } + + /// + /// Gets the test message level. + /// + public TestMessageLevel TestMessageLevel { get; private set; } + + public MultiTestRunsFinalizationEventHandler() + { + this.Errors = new List(); + this.Attachments = new List(); + } + + public void EnsureSuccess() + { + if (this.Errors.Any()) + { + throw new InvalidOperationException($"Test run reported errors:{Environment.NewLine}{string.Join(Environment.NewLine + Environment.NewLine, this.Errors)}"); + } + } + + public void HandleLogMessage(TestMessageLevel level, string message) + { + this.LogMessage = message; + this.TestMessageLevel = level; + if (level == TestMessageLevel.Error) { + this.Errors.Add(message); + } + } + + public void HandleRawMessage(string rawMessage) + { + // No op + } + + public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessStartInfo) + { + // No op + return -1; + } + + public bool AttachDebuggerToProcess(int pid) + { + // No op + return true; + } + + public void HandleMultiTestRunsFinalizationComplete(ICollection attachments) + { + if(attachments != null) + { + this.Attachments.AddRange(attachments); + } + } + } +} diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs index f3e1793d30..6b694e29a9 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs @@ -18,6 +18,11 @@ public class RunEventHandler : ITestRunEventsHandler2 /// public List TestResults { get; private set; } + /// + /// Gets the attachments. + /// + public List Attachments { get; private set; } + /// /// Gets the metrics. /// @@ -39,6 +44,7 @@ public RunEventHandler() { this.TestResults = new List(); this.Errors = new List(); + this.Attachments = new List(); } public void EnsureSuccess() @@ -69,6 +75,11 @@ public void HandleTestRunComplete( this.TestResults.AddRange(lastChunkArgs.NewTestResults); } + if(runContextAttachments != null) + { + this.Attachments.AddRange(runContextAttachments); + } + this.Metrics = testRunCompleteArgs.Metrics; } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs new file mode 100644 index 0000000000..433eca8a26 --- /dev/null +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs @@ -0,0 +1,243 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests +{ + using Microsoft.TestPlatform.TestUtilities; + using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; + using Microsoft.VisualStudio.TestPlatform.Common.Telemetry; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.IO; + using System.Linq; + using VisualStudio.TestPlatform.ObjectModel.Logging; + + /// + /// The Run Tests using VsTestConsoleWrapper API's + /// + [TestClass] + public class FinalizeMultiTestRunsTests : AcceptanceTestBase + { + private IVsTestConsoleWrapper2 vstestConsoleWrapper; + private RunEventHandler runEventHandler; + private MultiTestRunsFinalizationEventHandler multiTestRunsFinalizationEventHandler; + + private void Setup() + { + this.vstestConsoleWrapper = this.GetVsTestConsoleWrapper(); + this.runEventHandler = new RunEventHandler(); + this.multiTestRunsFinalizationEventHandler = new MultiTestRunsFinalizationEventHandler(); + } + + [TestCleanup] + public void Cleanup() + { + this.vstestConsoleWrapper?.EndSession(); + } + + [TestMethod] + //[NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void RunAllTests(RunnerInfo runnerInfo) + { + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + + // Assert + Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + Assert.AreEqual(2, this.runEventHandler.Attachments.Count); + Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed)); + Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed)); + Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Skipped)); + + this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); + Assert.AreEqual(1, this.multiTestRunsFinalizationEventHandler.Attachments.Count); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runnerInfo) + { + var numOfProcesses = Process.GetProcessesByName("vstest.console").Length; + + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies(), this.GetDefaultRunSettings(), this.runEventHandler); + this.vstestConsoleWrapper?.EndSession(); + + // Assert + Assert.AreEqual(numOfProcesses, Process.GetProcessesByName("vstest.console").Length); + + this.vstestConsoleWrapper = null; + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void RunTestsWithTelemetryOptedIn(RunnerInfo runnerInfo) + { + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + this.vstestConsoleWrapper.RunTests( + this.GetTestAssemblies(), + this.GetDefaultRunSettings(), + new TestPlatformOptions() { CollectMetrics = true }, + this.runEventHandler); + + // Assert + Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + Assert.IsTrue(this.runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TargetDevice)); + Assert.IsTrue(this.runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TargetFramework)); + Assert.IsTrue(this.runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TargetOS)); + Assert.IsTrue(this.runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForRun)); + Assert.IsTrue(this.runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.NumberOfAdapterDiscoveredDuringExecution)); + Assert.IsTrue(this.runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.RunState)); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void RunTestsWithTelemetryOptedOut(RunnerInfo runnerInfo) + { + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + this.vstestConsoleWrapper.RunTests( + this.GetTestAssemblies(), + this.GetDefaultRunSettings(), + new TestPlatformOptions() { CollectMetrics = false }, + this.runEventHandler); + + // Assert + Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + Assert.AreEqual(0, this.runEventHandler.Metrics.Count); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void RunTestsShouldThrowOnStackOverflowException(RunnerInfo runnerInfo) + { + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + if (IntegrationTestEnvironment.BuildConfiguration.Equals("release", StringComparison.OrdinalIgnoreCase)) + { + // On release, x64 builds, recursive calls may be replaced with loops (tail call optimization) + Assert.Inconclusive("On StackOverflowException testhost not exited in release configuration."); + return; + } + + var source = new[] { this.GetAssetFullPath("SimpleTestProject3.dll") }; + + this.vstestConsoleWrapper.RunTests( + source, + this.GetDefaultRunSettings(), + new TestPlatformOptions() { TestCaseFilter = "ExitWithStackoverFlow" }, + this.runEventHandler); + + var errorMessage = runnerInfo.TargetFramework == "net451" + ? "The active test run was aborted. Reason: Test host process crashed : Process is terminated due to StackOverflowException.\r\n" + : "The active test run was aborted. Reason: Test host process crashed : Process is terminating due to StackOverflowException.\r\n"; + + Assert.AreEqual(errorMessage, this.runEventHandler.LogMessage); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource(useCoreRunner: false)] + [NetCoreTargetFrameworkDataSource(useCoreRunner: false)] + public void RunTestsShouldShowProperWarningOnNoTestsForTestCaseFilter(RunnerInfo runnerInfo) + { + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + var testAssemblyName = "SimpleTestProject2.dll"; + var source = new List() { this.GetAssetFullPath(testAssemblyName) }; + + var veryLongTestCaseFilter = + "FullyQualifiedName=VeryLongTestCaseNameeeeeeeeeeeeee" + + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; + + this.vstestConsoleWrapper.RunTests( + source, + this.GetDefaultRunSettings(), + new TestPlatformOptions() { TestCaseFilter = veryLongTestCaseFilter }, + this.runEventHandler); + + var expectedFilter = veryLongTestCaseFilter.Substring(0, 256) + "..."; + + // Assert + StringAssert.StartsWith(this.runEventHandler.LogMessage, $"No test matches the given testcase filter `{expectedFilter}` in"); + StringAssert.EndsWith(this.runEventHandler.LogMessage, testAssemblyName); + + Assert.AreEqual(TestMessageLevel.Warning, this.runEventHandler.TestMessageLevel); + } + + private IList GetTestAssemblies() + { + var testAssemblies = new List + { + this.GetAssetFullPath("SimpleTestProject.dll"), + this.GetAssetFullPath("SimpleTestProject2.dll") + }; + + return testAssemblies; + } + + /// + /// Default RunSettings + /// + /// + public string GetCodeCoverageRunSettings() + { + string traceDataCollectorDir = Path.Combine(IntegrationTestEnvironment.TestPlatformRootDirectory, $@"src\DataCollectors\TraceDataCollector\bin\{IntegrationTestEnvironment.BuildConfiguration}\netstandard2.0"); + if (this.testEnvironment.TargetFramework.Equals(IntegrationTestBase.DesktopRunnerFramework)) + { + traceDataCollectorDir = Path.Combine(IntegrationTestEnvironment.TestPlatformRootDirectory, $@"artifacts\{IntegrationTestEnvironment.BuildConfiguration}\Microsoft.CodeCoverage"); + } + + string runSettingsXml = $@" + + + {FrameworkArgValue} + {traceDataCollectorDir} + + + + + + + + + .*CPPUnitTestFramework.* + + + + + True + True + True + False + + + + + + "; + return runSettingsXml; + } + } +} \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTests.cs index 9be9c83360..87ed476082 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTests.cs @@ -21,7 +21,7 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests [TestClass] public class RunTests : AcceptanceTestBase { - private IVsTestConsoleWrapper vstestConsoleWrapper; + private IVsTestConsoleWrapper2 vstestConsoleWrapper; private RunEventHandler runEventHandler; private void Setup() diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs index 7d25744753..44356520c2 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs @@ -451,7 +451,7 @@ protected virtual string SetVSTestConsoleDLLPathInArgs(string args) /// Returns the VsTestConsole Wrapper. /// /// - public IVsTestConsoleWrapper GetVsTestConsoleWrapper() + public IVsTestConsoleWrapper2 GetVsTestConsoleWrapper() { var logFileName = Path.GetFileName(Path.GetTempFileName()); var logFileDir = Path.Combine(Path.GetTempPath(), "VSTestConsoleWrapperLogs"); From 69340a5bb4e70a8e8d0172d3b01f91ee8b56e012 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Fri, 22 May 2020 13:24:52 +0200 Subject: [PATCH 08/58] Fix --- src/testhost.x86/testhost.x86.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/testhost.x86/testhost.x86.csproj b/src/testhost.x86/testhost.x86.csproj index 02dea17fb1..d35578cbfb 100644 --- a/src/testhost.x86/testhost.x86.csproj +++ b/src/testhost.x86/testhost.x86.csproj @@ -8,7 +8,6 @@ testhost.x86 netcoreapp2.1;net451 netcoreapp2.1 - 2.1.15 true AnyCPU true From e23d24dc3aa77fc71fe7d4c83d0d66495681a637 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Mon, 25 May 2020 09:50:55 +0200 Subject: [PATCH 09/58] test --- .../FinalizeMultiTestRunsTests.cs | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs index 433eca8a26..8cfb2c1a99 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs @@ -39,26 +39,47 @@ public void Cleanup() this.vstestConsoleWrapper?.EndSession(); } - [TestMethod] + //[TestMethod] //[NetFullTargetFrameworkDataSource] - [NetCoreTargetFrameworkDataSource] - public void RunAllTests(RunnerInfo runnerInfo) + //[NetCoreTargetFrameworkDataSource] + //public void RunAllTests(RunnerInfo runnerInfo) + //{ + // AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + // this.Setup(); + + // this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + // this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + + // // Assert + // Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + // Assert.AreEqual(2, this.runEventHandler.Attachments.Count); + // Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed)); + // Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed)); + // Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Skipped)); + + // this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); + // Assert.AreEqual(1, this.multiTestRunsFinalizationEventHandler.Attachments.Count); + //} + + [TestMethod] + public void RunAllTests() { + RunnerInfo runnerInfo = new RunnerInfo(AcceptanceTestBase.DesktopTargetFramework, AcceptanceTestBase.DesktopTargetFramework); AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); this.Setup(); this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); - this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + //this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); // Assert - Assert.AreEqual(6, this.runEventHandler.TestResults.Count); - Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed)); - Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed)); - Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Skipped)); - - this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); - Assert.AreEqual(1, this.multiTestRunsFinalizationEventHandler.Attachments.Count); + Assert.AreEqual(3, this.runEventHandler.TestResults.Count); + Assert.AreEqual(1, this.runEventHandler.Attachments.Count); + //Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed)); + //Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed)); + //Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Skipped)); + + //this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); + //Assert.AreEqual(1, this.multiTestRunsFinalizationEventHandler.Attachments.Count); } [TestMethod] From 6189eb0a906e403807890e61b9f6d72faf27a376 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 2 Jun 2020 10:50:13 +0200 Subject: [PATCH 10/58] More changes --- .../DesignMode/DesignModeClient.cs | 2 +- .../Messages/MessageType.cs | 9 +++- .../EventHandlers/TestRequestHandler.cs | 2 +- .../ITranslationLayerRequestSender.cs | 5 ++ .../Interfaces/IVsTestConsoleWrapper2.cs | 5 ++ .../VsTestConsoleRequestSender.cs | 12 ++++- .../VsTestConsoleWrapper.cs | 6 +++ .../EventHandler/RunEventHandler.cs | 4 +- .../FinalizeMultiTestRunsTests.cs | 51 +++++++------------ 9 files changed, 55 insertions(+), 41 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index 056c992f08..c8522992b0 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -201,7 +201,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager) break; } - case MessageType.MultiTestRunsFinalization: + case MessageType.MultiTestRunsFinalizationStart: { var multiTestRunsFinalizationPayload = this.communicationManager.DeserializePayload(message); diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs index a5af0cd46a..041617694f 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs @@ -126,12 +126,17 @@ public static class MessageType /// /// Multi test runs finalization /// - public const string MultiTestRunsFinalization = "TestExecution.MultiTestRunsFinalization"; + public const string MultiTestRunsFinalizationStart = "MultiTestRunsFinalization.Start"; /// /// Multi test runs finalization callback /// - public const string MultiTestRunsFinalizationComplete = "TestExecution.MultiTestRunsFinalizationComplete"; + public const string MultiTestRunsFinalizationComplete = "MultiTestRunsFinalization.Complete"; + + /// + /// Cancel multi test runs finalization + /// + public const string MultiTestRunsFinalizationCancel = "MultiTestRunsFinalization.Cancel"; /// /// Extensions Initialization diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs index 18759177dd..05a3fed45b 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs @@ -375,7 +375,7 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec break; } - case MessageType.MultiTestRunsFinalization: + case MessageType.MultiTestRunsFinalizationStart: { EqtTrace.Info("Multi test runs finalization started."); var multiTestRunsFinalizationEventsHandler = new MultiTestRunsFinalizationEventsHandler(this); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs index a8e73ab57c..9c19766e17 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs @@ -117,5 +117,10 @@ internal interface ITranslationLayerRequestSender : IDisposable /// List of attachements /// void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler); + + /// + /// Cancels multi test runs finalization + /// + void CancelMultiTestRunsFinalization(); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs index 9988ed548a..5fbc6ce412 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs @@ -19,5 +19,10 @@ public interface IVsTestConsoleWrapper2 : IVsTestConsoleWrapper /// List of attachements /// EventHandler to receive session complete event void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler); + + /// + /// Cancel last multi test runs finalization + /// + void CancelMultiTestRunsFinalization(); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index b01516f499..e546068396 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -389,6 +389,16 @@ public void FinalizeMultiTestRuns(ICollection attachments, IMulti this.SendMessageAndListenAndReportAttachements(attachments, testSessionEventsHandler); } + /// + public void CancelMultiTestRunsFinalization() + { + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("VsTestConsoleRequestSender.CancelMultiTestRunsFinalization: Canceling multi test runs finalization."); + } + this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationCancel); + } + /// /// Closes the communication channel /// @@ -739,7 +749,7 @@ private void SendMessageAndListenAndReportAttachements(ICollection attachments, IMulti this.requestSender.FinalizeMultiTestRuns(attachments, testSessionEventsHandler); } + /// + public void CancelMultiTestRunsFinalization() + { + throw new System.NotImplementedException(); + } + #endregion private void EnsureInitialized() diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs index 6b694e29a9..c4bd80e385 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs @@ -75,9 +75,9 @@ public void HandleTestRunComplete( this.TestResults.AddRange(lastChunkArgs.NewTestResults); } - if(runContextAttachments != null) + if (testRunCompleteArgs.AttachmentSets != null) { - this.Attachments.AddRange(runContextAttachments); + this.Attachments.AddRange(testRunCompleteArgs.AttachmentSets); } this.Metrics = testRunCompleteArgs.Metrics; diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs index 8cfb2c1a99..bb26430a8b 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs @@ -39,47 +39,24 @@ public void Cleanup() this.vstestConsoleWrapper?.EndSession(); } - //[TestMethod] - //[NetFullTargetFrameworkDataSource] - //[NetCoreTargetFrameworkDataSource] - //public void RunAllTests(RunnerInfo runnerInfo) - //{ - // AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); - // this.Setup(); - - // this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); - // this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); - - // // Assert - // Assert.AreEqual(6, this.runEventHandler.TestResults.Count); - // Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - // Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed)); - // Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed)); - // Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Skipped)); - - // this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); - // Assert.AreEqual(1, this.multiTestRunsFinalizationEventHandler.Attachments.Count); - //} - [TestMethod] - public void RunAllTests() + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void FinalizeMultiTestRuns(RunnerInfo runnerInfo) { - RunnerInfo runnerInfo = new RunnerInfo(AcceptanceTestBase.DesktopTargetFramework, AcceptanceTestBase.DesktopTargetFramework); AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); this.Setup(); this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); - //this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + + Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + Assert.AreEqual(2, this.runEventHandler.Attachments.Count); + + this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); // Assert - Assert.AreEqual(3, this.runEventHandler.TestResults.Count); - Assert.AreEqual(1, this.runEventHandler.Attachments.Count); - //Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed)); - //Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed)); - //Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Skipped)); - - //this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); - //Assert.AreEqual(1, this.multiTestRunsFinalizationEventHandler.Attachments.Count); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.multiTestRunsFinalizationEventHandler.Attachments.Count); } [TestMethod] @@ -92,7 +69,13 @@ public void EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runnerInfo AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); this.Setup(); - this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies(), this.GetDefaultRunSettings(), this.runEventHandler); + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + + Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + Assert.AreEqual(2, this.runEventHandler.Attachments.Count); + + this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); this.vstestConsoleWrapper?.EndSession(); // Assert From 97ab1788d681d18d5b3a54aa117621cf8b04c5ff Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 9 Jun 2020 09:45:04 +0200 Subject: [PATCH 11/58] Dmc chagnes --- .../DesignMode/DesignModeClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index c8522992b0..cc42c61894 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -205,7 +205,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager) { var multiTestRunsFinalizationPayload = this.communicationManager.DeserializePayload(message); - this.FinalizeMultiTestRuns(multiTestRunsFinalizationPayload); + this.FinalizeMultiTestRuns(multiTestRunsFinalizationPayload, testRequestManager); break; } @@ -468,7 +468,7 @@ private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITe }); } - private void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload finalizationPayload) + private void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload finalizationPayload, ITestRequestManager testRequestManager) { lock(this.lockObject) { From 23145501dd1311dfc2cabc1629f755fc01c4fdcd Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 9 Jun 2020 14:23:13 +0200 Subject: [PATCH 12/58] next --- .../DesignMode/DesignModeClient.cs | 49 +++--- .../MultiTestRunsFinalizationRequest.cs | 159 ++++++++++++++++++ .../RequestHelper/ITestRequestManager.cs | 11 ++ .../IMultiTestRunsFinalizationManager.cs | 5 + .../EventHandlers/TestRequestHandler.cs | 18 -- .../MultiTestRunsFinalizationManager.cs | 8 + .../IMultTestRunsFinalizationRequest.cs | 21 +++ .../TestPlatformHelpers/TestRequestManager.cs | 56 +++++- 8 files changed, 278 insertions(+), 49 deletions(-) create mode 100644 src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationRequest.cs create mode 100644 src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultTestRunsFinalizationRequest.cs diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index cc42c61894..8d8beeced1 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -205,7 +205,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager) { var multiTestRunsFinalizationPayload = this.communicationManager.DeserializePayload(message); - this.FinalizeMultiTestRuns(multiTestRunsFinalizationPayload, testRequestManager); + this.StartMultiTestRunsFinalization(multiTestRunsFinalizationPayload, testRequestManager); break; } @@ -468,39 +468,32 @@ private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITe }); } - private void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload finalizationPayload, ITestRequestManager testRequestManager) + private void StartMultiTestRunsFinalization(MultiTestRunsFinalizationPayload finalizationPayload, ITestRequestManager testRequestManager) { - lock(this.lockObject) - { - try + Task.Run( + delegate { - var handler = new MultiTestRunsDataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()); - handler.HandleAttachements(finalizationPayload.Attachments); - - var payload = new MultiTestRunsFinalizationCompletePayload() + try { - Attachments = finalizationPayload.Attachments - }; - - // Send run complete to translation layer - this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationComplete, payload); - } - catch (Exception ex) - { - EqtTrace.Error("DesignModeClient: Exception in StartDiscovery: " + ex); + testRequestManager.ResetOptions(); + testRequestManager.FinalizeMultiTestRuns(finalizationPayload); + } + catch (Exception ex) + { + EqtTrace.Error("DesignModeClient: Exception in StartMultiTestRunsFinalization: " + ex); - var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() }; - this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); + var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() }; + this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); - var payload = new MultiTestRunsFinalizationCompletePayload() - { - Attachments = null - }; + var payload = new MultiTestRunsFinalizationCompletePayload() + { + Attachments = null + }; - // Send run complete to translation layer - this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationComplete, payload); - } - } + // Send run complete to translation layer + this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationComplete, payload); + } + }); } #region IDisposable Support diff --git a/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationRequest.cs b/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationRequest.cs new file mode 100644 index 0000000000..cc261fcc27 --- /dev/null +++ b/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationRequest.cs @@ -0,0 +1,159 @@ +using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol; +using System; +using System.Threading; + +namespace Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunsFinalization +{ + public class MultiTestRunsFinalizationRequest : IMultiTestRunsFinalizationRequest + { + public event EventHandler OnRawMessageReceived; + + public void Abort() + { + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("MultiTestRunsFinalizationRequest.Abort: Aborting."); + } + + lock (this.syncObject) + { + if (this.disposed) + { + throw new ObjectDisposedException("MultiTestRunsFinalizationRequest"); + } + + if (this.finalizationInProgress) + { + this.finalizationManager.Abort(); + } + else + { + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("MultiTestRunsFinalizationRequest.Abort: No operation to abort."); + } + + return; + } + } + + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("MultiTestRunsFinalizationRequest.Abort: Aborted."); + } + } + + public void FinalizeMultiTestRunsAsync() + { + throw new NotImplementedException(); + } + + /// + /// Wait for discovery completion + /// + /// The timeout. + bool IRequest.WaitForCompletion(int timeout) + { + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("MultiTestRunsFinalizationRequest.WaitForCompletion: Waiting with timeout {0}.", timeout); + } + + if (this.disposed) + { + throw new ObjectDisposedException("MultiTestRunsFinalizationRequest"); + } + + // This method is not synchronized as it can lead to dead-lock + // (the discoveryCompletionEvent cannot be raised unless that lock is released) + if (this.finalizationCompleted != null) + { + return this.finalizationCompleted.WaitOne(timeout); + } + + return true; + } + + #region IDisposable implementation + + /// + /// Performs application-defined tasks associated with freeing, releasing, or + /// resetting unmanaged resources. + /// + public void Dispose() + { + this.Dispose(true); + + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("MultiTestRunsFinalizationRequest.Dispose: Starting."); + } + + lock (this.syncObject) + { + if (!this.disposed) + { + if (disposing) + { + if (this.finalizationCompleted != null) + { + this.finalizationCompleted.Dispose(); + } + } + + // Indicate that object has been disposed + this.finalizationCompleted = null; + this.disposed = true; + } + } + + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("DiscoveryRequest.Dispose: Completed."); + } + } + + #endregion + + #region privates fields + + /// + /// If this request has been disposed. + /// + private bool disposed = false; + + /// + /// It get set when current discovery request is completed. + /// + private ManualResetEvent finalizationCompleted = new ManualResetEvent(false); + + /// + /// Sync object for various operations + /// + private object syncObject = new Object(); + + /// + /// Whether or not the test discovery is in progress. + /// + private bool finalizationInProgress; + + /// + /// Discovery Start Time + /// + private DateTime finalizationStartTime; + + /// + /// Finalization manager + /// + private IMultiTestRunsFinalizationManager finalizationManager; + + #endregion + } +} diff --git a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs index 45e6a655f6..3d6a4f4386 100644 --- a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs +++ b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs @@ -44,6 +44,12 @@ public interface ITestRequestManager : IDisposable /// Protocol related information void RunTests(TestRunRequestPayload testRunRequestPayLoad, ITestHostLauncher customTestHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig); + /// + /// Finalize multi test runs + /// + /// Multi test runs finalization payload + void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload multiTestRunsFinalizationPayload); + /// /// Cancel the current TestRun request /// @@ -58,5 +64,10 @@ public interface ITestRequestManager : IDisposable /// Cancels the current discovery request /// void CancelDiscovery(); + + /// + /// Cancels the current multi test runs finalization request + /// + void CancelMultiTestRunsFinalizaiton(); } } diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs index e21350c231..b3788c3552 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs @@ -17,5 +17,10 @@ public interface IMultiTestRunsFinalizationManager /// Attachments /// EventHandler for handling multi test runs finalization events from Engine void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler eventHandler); + + /// + /// Aborts multi test runs finalization + /// + void Abort(); } } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs index 05a3fed45b..cb0b7b30a7 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs @@ -375,24 +375,6 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec break; } - case MessageType.MultiTestRunsFinalizationStart: - { - EqtTrace.Info("Multi test runs finalization started."); - var multiTestRunsFinalizationEventsHandler = new MultiTestRunsFinalizationEventsHandler(this); - var multiTestRunsFinalizationManager = new MultiTestRunsFinalizationManager(new MultiTestRunsDataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler())); - var multiTestRunsFinalizationPayload = this.dataSerializer.DeserializePayload(message); - - jobQueue.QueueJob( - () => - multiTestRunsFinalizationManager - .FinalizeMultiTestRuns( - multiTestRunsFinalizationPayload.Attachments, - multiTestRunsFinalizationEventsHandler), - 0); - - break; - } - case MessageType.CancelTestRun: jobQueue.Pause(); this.testHostManagerFactoryReady.Wait(); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs index 7d338890f8..63c0a2594e 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs @@ -34,5 +34,13 @@ public void FinalizeMultiTestRuns(ICollection attachments, IMulti attachmentsHandler.HandleAttachements(attachments); eventHandler.HandleMultiTestRunsFinalizationComplete(attachments); } + + /// + /// Aborts multi test runs finalization + /// + public void Abort() + { + throw new System.NotImplementedException(); + } } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultTestRunsFinalizationRequest.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultTestRunsFinalizationRequest.cs new file mode 100644 index 0000000000..533f8f3841 --- /dev/null +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultTestRunsFinalizationRequest.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client +{ + /// + /// IMultiTestRunsFinalizationRequest + /// + public interface IMultiTestRunsFinalizationRequest : IRequest + { + /// + /// Starts tests discovery async. + /// + void FinalizeMultiTestRunsAsync(); + + /// + /// Aborts the discovery request + /// + void Abort(); + } +} diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 778006ebf5..051491605d 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -62,6 +62,12 @@ internal class TestRequestManager : ITestRequestManager /// private IDiscoveryRequest currentDiscoveryRequest; + /// + /// Maintains the current active multi test runs finalization request + /// Assumption : There can only be one active discovery request. + /// + private IMultiTestRunsFinalizationRequest currentMultiTestRunsFinalizationRequest; + #region Constructor public TestRequestManager() @@ -160,9 +166,7 @@ public void DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscove // Collect Commands this.LogCommandsTelemetryPoints(requestData); } - - - + // create discovery request var criteria = new DiscoveryCriteria(discoveryPayload.Sources, batchSize, this.commandLineOptions.TestStatsEventTimeout, runsettings) { @@ -301,6 +305,43 @@ public void RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc } } + /// + /// Discover Tests given a list of sources, run settings. + /// + /// Discovery payload + /// EventHandler for discovered tests + /// Protocol related information + /// True, if successful + public void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload multiTestRunsFinalizationPayload) + { + EqtTrace.Info("TestRequestManager.FinalizeMultiTestRuns: Multi test runs finalization started."); + + // Make sure to run the run request inside a lock as the below section is not thread-safe + // There can be only one discovery, execution or finalization request at a given point in time + lock (this.syncObject) + { + try + { + EqtTrace.Info("TestRequestManager.FinalizeMultiTestRuns: Synchronization context taken"); + + this.currentMultiTestRunsFinalizationRequest = this.testPlatform.CreateDiscoveryRequest(requestData, criteria, discoveryPayload.TestPlatformOptions); + this.currentMultiTestRunsFinalizationRequest.FinalizeMultiTestRunsAsync(); + this.currentMultiTestRunsFinalizationRequest.WaitForCompletion(); + } + finally + { + if (this.currentMultiTestRunsFinalizationRequest != null) + { + this.currentMultiTestRunsFinalizationRequest.Dispose(); + this.currentMultiTestRunsFinalizationRequest = null; + } + + EqtTrace.Info("TestRequestManager.FinalizeMultiTestRuns: Multi test runs finalization completed."); + this.testPlatformEventSource.MultiTestRunsFinalizationRequestStop(); + } + } + } + private void LogTelemetryForLegacySettings(IRequestData requestData, string runsettings) { requestData.MetricsCollection.Add(TelemetryDataConstants.TestSettingsUsed, InferRunSettingsHelper.IsTestSettingsEnabled(runsettings)); @@ -333,6 +374,15 @@ public void CancelDiscovery() this.currentDiscoveryRequest?.Abort(); } + /// + /// Cancel the multi test runs finalization. + /// + public void CancelMultiTestRunsFinalization() + { + EqtTrace.Info("TestRequestManager.CancelMultiTestRunsFinalization: Sending cancel request."); + this.currentMultiTestRunsFinalizationRequest?.Abort(); + } + /// /// Aborts the test run. /// From e7b839f19ab2f51035777801a05f340b8f1dd178 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Wed, 10 Jun 2020 09:08:13 +0200 Subject: [PATCH 13/58] small changes --- .../MultiTestRunsFinalizationRequest.cs | 2 +- .../IMultiTestRunsFinalizationManager.cs | 4 ++-- .../MultiTestRunsFinalizationManager.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename src/Microsoft.TestPlatform.Common/Interfaces/Engine/{TesthostProtocol => }/IMultiTestRunsFinalizationManager.cs (87%) diff --git a/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationRequest.cs b/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationRequest.cs index cc261fcc27..8aaff82166 100644 --- a/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationRequest.cs +++ b/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationRequest.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; using System; using System.Threading; diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunsFinalizationManager.cs similarity index 87% rename from src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs rename to src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunsFinalizationManager.cs index b3788c3552..140ab2f289 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/TesthostProtocol/IMultiTestRunsFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunsFinalizationManager.cs @@ -4,10 +4,10 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using System.Collections.Generic; -namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine { /// - /// Orchestrates multi test runs finalization operations for the engine communicating with the test host process. + /// Orchestrates multi test runs finalization operations. /// public interface IMultiTestRunsFinalizationManager { diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs index 63c0a2594e..a3d8939c74 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs @@ -5,7 +5,7 @@ using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunsFinalization { From 6aa2912a2071d4628693a321bc439b998c2bfc9f Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Wed, 10 Jun 2020 17:10:30 +0200 Subject: [PATCH 14/58] compiled --- .../DesignMode/DesignModeClient.cs | 4 +- .../MultiTestRunsFinalizationEventsHandler.cs | 43 ++--- .../MultiTestRunsFinalizationRequest.cs | 159 ------------------ .../RequestHelper/ITestRequestManager.cs | 5 +- .../IMultiTestRunsFinalizationManager.cs | 10 +- ...TestRunsDataCollectorAttachmentsHandler.cs | 5 +- .../ParallelDataCollectionEventsHandler.cs | 4 +- .../MultiTestRunsFinalizationManager.cs | 49 ++++-- .../IMultTestRunsFinalizationRequest.cs | 21 --- .../IDataCollectorAttachments.cs | 3 +- .../CodeCoverageDataAttachmentsHandler.cs | 26 ++- .../TestPlatformHelpers/TestRequestManager.cs | 49 +++--- ...CodeCoverageDataAttachmentsHandlerTests.cs | 7 +- ...llyQualifiedTestsArgumentProcessorTests.cs | 19 ++- .../ListTestsArgumentProcessorTests.cs | 17 +- .../RunSpecificTestsArgumentProcessorTests.cs | 47 +++--- .../RunTestsArgumentProcessorTests.cs | 17 +- .../TestRequestManagerTests.cs | 58 ++++--- 18 files changed, 220 insertions(+), 323 deletions(-) rename src/{Microsoft.TestPlatform.CommunicationUtilities/EventHandlers => Microsoft.TestPlatform.Client/MultiTestRunsFinalization}/MultiTestRunsFinalizationEventsHandler.cs (61%) delete mode 100644 src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationRequest.cs delete mode 100644 src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultTestRunsFinalizationRequest.cs diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index 8d8beeced1..9fd465c7a0 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode using System.Net; using System.Threading; using System.Threading.Tasks; - + using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunsFinalization; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; @@ -476,7 +476,7 @@ private void StartMultiTestRunsFinalization(MultiTestRunsFinalizationPayload fin try { testRequestManager.ResetOptions(); - testRequestManager.FinalizeMultiTestRuns(finalizationPayload); + testRequestManager.FinalizeMultiTestRuns(finalizationPayload, new MultiTestRunsFinalizationEventsHandler(this.communicationManager)); } catch (Exception ex) { diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/EventHandlers/MultiTestRunsFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationEventsHandler.cs similarity index 61% rename from src/Microsoft.TestPlatform.CommunicationUtilities/EventHandlers/MultiTestRunsFinalizationEventsHandler.cs rename to src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationEventsHandler.cs index bc4ba4b350..67dcab7c2c 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/EventHandlers/MultiTestRunsFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationEventsHandler.cs @@ -1,29 +1,29 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.EventHandlers +namespace Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunsFinalization { - using System.Collections.Generic; - using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; + using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using System.Collections.Generic; /// /// The multi test finalization event handler. /// public class MultiTestRunsFinalizationEventsHandler : IMultiTestRunsFinalizationEventsHandler { - private ITestRequestHandler requestHandler; + private ICommunicationManager communicationManager; /// /// Initializes a new instance of the class. /// /// The Request Handler. - public MultiTestRunsFinalizationEventsHandler(ITestRequestHandler requestHandler) + public MultiTestRunsFinalizationEventsHandler(ICommunicationManager communicationManager) { - this.requestHandler = requestHandler; + this.communicationManager = communicationManager; } /// @@ -33,26 +33,8 @@ public MultiTestRunsFinalizationEventsHandler(ITestRequestHandler requestHandler /// Logging message. public void HandleLogMessage(TestMessageLevel level, string message) { - switch ((TestMessageLevel)level) - { - case TestMessageLevel.Informational: - EqtTrace.Info(message); - break; - - case TestMessageLevel.Warning: - EqtTrace.Warning(message); - break; - - case TestMessageLevel.Error: - EqtTrace.Error(message); - break; - - default: - EqtTrace.Info(message); - break; - } - - this.requestHandler.SendLog(level, message); + var testMessagePayload = new TestMessagePayload { MessageLevel = level, Message = message }; + this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); } public void HandleMultiTestRunsFinalizationComplete(ICollection attachments) @@ -62,13 +44,18 @@ public void HandleMultiTestRunsFinalizationComplete(ICollection a EqtTrace.Info("Multi test runs finalization completed."); } - this.requestHandler.MultiTestRunsFinalizationComplete(attachments); + var payload = new MultiTestRunsFinalizationCompletePayload() + { + Attachments = null + }; + + // Send run complete to translation layer + this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationComplete, payload); } public void HandleRawMessage(string rawMessage) { // No-Op - // TestHost at this point has no functionality where it requires rawmessage } } } diff --git a/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationRequest.cs b/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationRequest.cs deleted file mode 100644 index 8aaff82166..0000000000 --- a/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationRequest.cs +++ /dev/null @@ -1,159 +0,0 @@ -using Microsoft.VisualStudio.TestPlatform.ObjectModel; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; -using System; -using System.Threading; - -namespace Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunsFinalization -{ - public class MultiTestRunsFinalizationRequest : IMultiTestRunsFinalizationRequest - { - public event EventHandler OnRawMessageReceived; - - public void Abort() - { - if (EqtTrace.IsVerboseEnabled) - { - EqtTrace.Verbose("MultiTestRunsFinalizationRequest.Abort: Aborting."); - } - - lock (this.syncObject) - { - if (this.disposed) - { - throw new ObjectDisposedException("MultiTestRunsFinalizationRequest"); - } - - if (this.finalizationInProgress) - { - this.finalizationManager.Abort(); - } - else - { - if (EqtTrace.IsInfoEnabled) - { - EqtTrace.Info("MultiTestRunsFinalizationRequest.Abort: No operation to abort."); - } - - return; - } - } - - if (EqtTrace.IsInfoEnabled) - { - EqtTrace.Info("MultiTestRunsFinalizationRequest.Abort: Aborted."); - } - } - - public void FinalizeMultiTestRunsAsync() - { - throw new NotImplementedException(); - } - - /// - /// Wait for discovery completion - /// - /// The timeout. - bool IRequest.WaitForCompletion(int timeout) - { - if (EqtTrace.IsVerboseEnabled) - { - EqtTrace.Verbose("MultiTestRunsFinalizationRequest.WaitForCompletion: Waiting with timeout {0}.", timeout); - } - - if (this.disposed) - { - throw new ObjectDisposedException("MultiTestRunsFinalizationRequest"); - } - - // This method is not synchronized as it can lead to dead-lock - // (the discoveryCompletionEvent cannot be raised unless that lock is released) - if (this.finalizationCompleted != null) - { - return this.finalizationCompleted.WaitOne(timeout); - } - - return true; - } - - #region IDisposable implementation - - /// - /// Performs application-defined tasks associated with freeing, releasing, or - /// resetting unmanaged resources. - /// - public void Dispose() - { - this.Dispose(true); - - GC.SuppressFinalize(this); - } - - private void Dispose(bool disposing) - { - if (EqtTrace.IsVerboseEnabled) - { - EqtTrace.Verbose("MultiTestRunsFinalizationRequest.Dispose: Starting."); - } - - lock (this.syncObject) - { - if (!this.disposed) - { - if (disposing) - { - if (this.finalizationCompleted != null) - { - this.finalizationCompleted.Dispose(); - } - } - - // Indicate that object has been disposed - this.finalizationCompleted = null; - this.disposed = true; - } - } - - if (EqtTrace.IsInfoEnabled) - { - EqtTrace.Info("DiscoveryRequest.Dispose: Completed."); - } - } - - #endregion - - #region privates fields - - /// - /// If this request has been disposed. - /// - private bool disposed = false; - - /// - /// It get set when current discovery request is completed. - /// - private ManualResetEvent finalizationCompleted = new ManualResetEvent(false); - - /// - /// Sync object for various operations - /// - private object syncObject = new Object(); - - /// - /// Whether or not the test discovery is in progress. - /// - private bool finalizationInProgress; - - /// - /// Discovery Start Time - /// - private DateTime finalizationStartTime; - - /// - /// Finalization manager - /// - private IMultiTestRunsFinalizationManager finalizationManager; - - #endregion - } -} diff --git a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs index 3d6a4f4386..813f9f416e 100644 --- a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs +++ b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs @@ -48,7 +48,8 @@ public interface ITestRequestManager : IDisposable /// Finalize multi test runs /// /// Multi test runs finalization payload - void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload multiTestRunsFinalizationPayload); + /// Multi test runs finalization events handler + void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload multiTestRunsFinalizationPayload, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationEventsHandler); /// /// Cancel the current TestRun request @@ -68,6 +69,6 @@ public interface ITestRequestManager : IDisposable /// /// Cancels the current multi test runs finalization request /// - void CancelMultiTestRunsFinalizaiton(); + void CancelMultiTestRunsFinalization(); } } diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunsFinalizationManager.cs index 140ab2f289..64d14e8f56 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunsFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunsFinalizationManager.cs @@ -3,6 +3,8 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine { @@ -16,11 +18,7 @@ public interface IMultiTestRunsFinalizationManager /// /// Attachments /// EventHandler for handling multi test runs finalization events from Engine - void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler eventHandler); - - /// - /// Aborts multi test runs finalization - /// - void Abort(); + /// Cancellation token + Task FinalizeMultiTestRunsAsync(ICollection attachments, IMultiTestRunsFinalizationEventsHandler eventHandler, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/MultiTestRunsDataCollectorAttachmentsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/MultiTestRunsDataCollectorAttachmentsHandler.cs index cad95055ff..b83b6d327a 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/MultiTestRunsDataCollectorAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/MultiTestRunsDataCollectorAttachmentsHandler.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Threading; namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection { @@ -19,7 +20,7 @@ public MultiTestRunsDataCollectorAttachmentsHandler(IDataCollectorAttachments da this.dataCollectorAttachmentsHandler = dataCollectorAttachmentsHandler; } - public void HandleAttachements(ICollection attachments) + public void HandleAttachements(ICollection attachments, CancellationToken cancellationToken) { Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); if (attachementUri != null) @@ -31,7 +32,7 @@ public void HandleAttachements(ICollection attachments) attachments.Remove(coverageAttachment); } - ICollection mergedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(coverageAttachments)); + ICollection mergedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(coverageAttachments), cancellationToken); foreach (var attachment in mergedAttachments) { attachments.Add(attachment); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs index 67d9d2df70..3b645be321 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs @@ -4,7 +4,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection { using System.Collections.Generic; - + using System.Threading; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel; @@ -53,7 +53,7 @@ public override void HandleTestRunComplete( if (parallelRunComplete) { - attachmentsHandler.HandleAttachements(runDataAggregator.RunContextAttachments); + attachmentsHandler.HandleAttachements(runDataAggregator.RunContextAttachments, CancellationToken.None); var completedArgs = new TestRunCompleteEventArgs(this.runDataAggregator.GetAggregatedRunStats(), this.runDataAggregator.IsCanceled, diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs index a3d8939c74..036077669b 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs @@ -1,7 +1,10 @@ // 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.Generic; +using System.Threading; +using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; @@ -29,18 +32,44 @@ public MultiTestRunsFinalizationManager(MultiTestRunsDataCollectorAttachmentsHan /// /// Attachments /// EventHandler for handling multi test runs finalization events from Engine - public void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler eventHandler) + /// Cancellation token + public async Task FinalizeMultiTestRunsAsync(ICollection attachments, IMultiTestRunsFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) { - attachmentsHandler.HandleAttachements(attachments); - eventHandler.HandleMultiTestRunsFinalizationComplete(attachments); - } + try + { + cancellationToken.ThrowIfCancellationRequested(); + + var taskCompletionSource = new TaskCompletionSource(); + cancellationToken.Register(() => + { + taskCompletionSource.TrySetCanceled(); + }); + + Task task = Task.Run(() => + { + attachmentsHandler.HandleAttachements(attachments, cancellationToken); + eventHandler.HandleMultiTestRunsFinalizationComplete(attachments); + }); + + var completedTask = await Task.WhenAny(task, taskCompletionSource.Task); + + if (completedTask == task) + { + eventHandler.HandleMultiTestRunsFinalizationComplete(attachments); + } + else + { + eventHandler.HandleMultiTestRunsFinalizationComplete(null); + } + } + catch (Exception e) + { + EqtTrace.Error("MultiTestRunsFinalizationManager: Exception in FinalizeMultiTestRunsAsync: " + e); + + eventHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); + eventHandler.HandleMultiTestRunsFinalizationComplete(null); + } - /// - /// Aborts multi test runs finalization - /// - public void Abort() - { - throw new System.NotImplementedException(); } } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultTestRunsFinalizationRequest.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultTestRunsFinalizationRequest.cs deleted file mode 100644 index 533f8f3841..0000000000 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultTestRunsFinalizationRequest.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client -{ - /// - /// IMultiTestRunsFinalizationRequest - /// - public interface IMultiTestRunsFinalizationRequest : IRequest - { - /// - /// Starts tests discovery async. - /// - void FinalizeMultiTestRunsAsync(); - - /// - /// Aborts the discovery request - /// - void Abort(); - } -} diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs index e0cd5e97c9..6c1ed58acc 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs @@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection { using System; using System.Collections.Generic; + using System.Threading; /// /// Interface for data collectors add-ins that choose to handle attachment(s) generated @@ -15,7 +16,7 @@ public interface IDataCollectorAttachments /// Gets the attachment set after Test Run Session /// /// Gets the attachment set after Test Run Session - ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments); + ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, CancellationToken cancellationToken); /// /// Gets the attachment Uri, which is handled by current Collector diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index d75d81ce88..822dded6a0 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -9,6 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities using System.IO; using System.Linq; using System.Reflection; + using System.Threading; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; @@ -30,12 +31,12 @@ public Uri GetExtensionUri() return CodeCoverageDataCollectorUri; } - public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments) + public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, CancellationToken cancellationToken) { if (dataCollectionAttachments != null && dataCollectionAttachments.Any()) { var codeCoverageFiles = dataCollectionAttachments.Select(coverageAttachment => coverageAttachment.Attachments[0].Uri.LocalPath).ToArray(); - var outputFile = MergeCodeCoverageFiles(codeCoverageFiles); + var outputFile = MergeCodeCoverageFiles(codeCoverageFiles, cancellationToken); var attachmentSet = new AttachmentSet(CodeCoverageDataCollectorUri, CoverageFriendlyName); if (!string.IsNullOrEmpty(outputFile)) @@ -51,7 +52,7 @@ public ICollection HandleDataCollectionAttachmentSets(ICollection return new Collection(); } - private string MergeCodeCoverageFiles(IList files) + private string MergeCodeCoverageFiles(IList files, CancellationToken cancellationToken) { string fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + CoverageFileExtension); string outputfileName = files[0]; @@ -61,6 +62,7 @@ private string MergeCodeCoverageFiles(IList files) try { + cancellationToken.ThrowIfCancellationRequested(); Assembly assembly = new PlatformAssemblyLoadContext().LoadAssemblyFromPath(assemblyPath); var type = assembly.GetType(CodeCoverageAnalysisAssemblyName + "." + CoverageInfoTypeName); @@ -70,9 +72,13 @@ private string MergeCodeCoverageFiles(IList files) { for (int i = 1; i < files.Count; i++) { + cancellationToken.ThrowIfCancellationRequested(); methodInfo.Invoke(null, new object[] { files[i], outputfileName, fileName, true }); - File.Copy(fileName, outputfileName, true); + cancellationToken.ThrowIfCancellationRequested(); + File.Copy(fileName, outputfileName, true); + + cancellationToken.ThrowIfCancellationRequested(); File.Delete(files[i]); } @@ -81,6 +87,18 @@ private string MergeCodeCoverageFiles(IList files) return outputfileName; } + catch (OperationCanceledException) + { + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("CodeCoverageDataCollectorAttachmentsHandler: operation was cancelled."); + } + throw; + } + catch (ObjectDisposedException) + { + throw; + } catch (Exception ex) { if (EqtTrace.IsErrorEnabled) diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 051491605d..885b020e3f 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -8,10 +8,12 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers using System.IO; using System.Linq; using System.Reflection; + using System.Threading; using System.Threading.Tasks; using System.Xml; using System.Xml.XPath; using Microsoft.VisualStudio.TestPlatform.Client; + using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunsFinalization; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.CommandLine.Internal; using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities; @@ -24,9 +26,11 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunsFinalization; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; @@ -49,6 +53,7 @@ internal class TestRequestManager : ITestRequestManager private readonly Task metricsPublisher; private bool isDisposed; private IProcessHelper processHelper; + private IMultiTestRunsFinalizationManager finalizationManager; /// /// Maintains the current active execution request @@ -63,10 +68,10 @@ internal class TestRequestManager : ITestRequestManager private IDiscoveryRequest currentDiscoveryRequest; /// - /// Maintains the current active multi test runs finalization request - /// Assumption : There can only be one active discovery request. + /// Maintains the current active multi test runs finalization cancellation token source + /// Assumption : There can only be one active finalization request. /// - private IMultiTestRunsFinalizationRequest currentMultiTestRunsFinalizationRequest; + private CancellationTokenSource currentFinalizationCancellationTokenSource; #region Constructor @@ -78,11 +83,12 @@ public TestRequestManager() TestPlatformEventSource.Instance, new InferHelper(AssemblyMetadataProvider.Instance), MetricsPublisherFactory.GetMetricsPublisher(IsTelemetryOptedIn(), CommandLineOptions.Instance.IsDesignMode), - new ProcessHelper()) + new ProcessHelper(), + new MultiTestRunsFinalizationManager(new CrossPlatEngine.DataCollection.MultiTestRunsDataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()))) { } - internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform testPlatform, TestRunResultAggregator testRunResultAggregator, ITestPlatformEventSource testPlatformEventSource, InferHelper inferHelper, Task metricsPublisher, IProcessHelper processHelper) + internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform testPlatform, TestRunResultAggregator testRunResultAggregator, ITestPlatformEventSource testPlatformEventSource, InferHelper inferHelper, Task metricsPublisher, IProcessHelper processHelper, IMultiTestRunsFinalizationManager finalizationManager) { this.testPlatform = testPlatform; this.commandLineOptions = commandLineOptions; @@ -91,6 +97,7 @@ internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform this.inferHelper = inferHelper; this.metricsPublisher = metricsPublisher; this.processHelper = processHelper; + this.finalizationManager = finalizationManager; } #endregion @@ -312,7 +319,7 @@ public void RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc /// EventHandler for discovered tests /// Protocol related information /// True, if successful - public void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload multiTestRunsFinalizationPayload) + public void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload finalizationPayload, IMultiTestRunsFinalizationEventsHandler finalizationEventsHandler) { EqtTrace.Info("TestRequestManager.FinalizeMultiTestRuns: Multi test runs finalization started."); @@ -323,17 +330,19 @@ public void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload multiTestRuns try { EqtTrace.Info("TestRequestManager.FinalizeMultiTestRuns: Synchronization context taken"); + this.testPlatformEventSource.MultiTestRunsFinalizationRequestStart(); + + this.currentFinalizationCancellationTokenSource = new CancellationTokenSource(); - this.currentMultiTestRunsFinalizationRequest = this.testPlatform.CreateDiscoveryRequest(requestData, criteria, discoveryPayload.TestPlatformOptions); - this.currentMultiTestRunsFinalizationRequest.FinalizeMultiTestRunsAsync(); - this.currentMultiTestRunsFinalizationRequest.WaitForCompletion(); + Task task = this.finalizationManager.FinalizeMultiTestRunsAsync(finalizationPayload.Attachments, finalizationEventsHandler, this.currentFinalizationCancellationTokenSource.Token); + task.Wait(); } finally { - if (this.currentMultiTestRunsFinalizationRequest != null) + if (this.currentFinalizationCancellationTokenSource != null) { - this.currentMultiTestRunsFinalizationRequest.Dispose(); - this.currentMultiTestRunsFinalizationRequest = null; + this.currentFinalizationCancellationTokenSource.Dispose(); + this.currentFinalizationCancellationTokenSource = null; } EqtTrace.Info("TestRequestManager.FinalizeMultiTestRuns: Multi test runs finalization completed."); @@ -375,21 +384,21 @@ public void CancelDiscovery() } /// - /// Cancel the multi test runs finalization. + /// Aborts the test run. /// - public void CancelMultiTestRunsFinalization() + public void AbortTestRun() { - EqtTrace.Info("TestRequestManager.CancelMultiTestRunsFinalization: Sending cancel request."); - this.currentMultiTestRunsFinalizationRequest?.Abort(); + EqtTrace.Info("TestRequestManager.AbortTestRun: Sending abort request."); + this.currentTestRunRequest?.Abort(); } /// - /// Aborts the test run. + /// Cancel the multi test runs finalization. /// - public void AbortTestRun() + public void CancelMultiTestRunsFinalization() { - EqtTrace.Info("TestRequestManager.AbortTestRun: Sending abort request."); - this.currentTestRunRequest?.Abort(); + EqtTrace.Info("TestRequestManager.CancelMultiTestRunsFinalization: Sending cancel request."); + this.currentFinalizationCancellationTokenSource?.Cancel(); } #endregion diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs index 7d63ed0a18..9e55591dcb 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs @@ -7,6 +7,7 @@ namespace Microsoft.TestPlatform.Utilities.UnitTests using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.ObjectModel; + using System.Threading; [TestClass] public class CodeCoverageDataAttachmentsHandlerTests @@ -23,12 +24,12 @@ public void HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoAttachme { Collection attachment = new Collection(); ICollection resultAttachmentSets = - coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment); + coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 0); - resultAttachmentSets = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(null); + resultAttachmentSets = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(null, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 0); @@ -41,7 +42,7 @@ public void HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoCodeCove var attachmentSet = new AttachmentSet(new Uri("//badrui//"), string.Empty); ICollection resultAttachmentSets = - coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment); + coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 0); diff --git a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs index ca191e2c8f..34d411989a 100644 --- a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs @@ -18,6 +18,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using Microsoft.VisualStudio.TestPlatform.CommandLine.Publisher; using Microsoft.VisualStudio.TestPlatform.CommandLineUtilities; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -44,6 +45,7 @@ public class ListFullyQualifiedTestsArgumentProcessorTests private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; + private Mock mockFinalizationManager; private static ListFullyQualifiedTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestManager, IOutput output) { @@ -78,6 +80,7 @@ public ListFullyQualifiedTestsArgumentProcessorTests() this.mockAssemblyMetadataProvider.Setup(x => x.GetFrameWork(It.IsAny())).Returns(new FrameworkName(Constants.DotNetFramework40)); this.inferHelper = new InferHelper(this.mockAssemblyMetadataProvider.Object); this.mockProcessHelper = new Mock(); + this.mockFinalizationManager = new Mock(); } /// @@ -124,7 +127,7 @@ public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() { CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object; CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, this.mockFileHelper.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager, null); executor.Initialize(this.dummyTestFilePath); @@ -136,7 +139,7 @@ public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() public void ExecutorExecuteForNoSourcesShouldReturnFail() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => executor.Execute()); @@ -153,7 +156,7 @@ public void ExecutorExecuteShouldThrowTestPlatformException() this.ResetAndAddSourceToCommandLineOptions(true); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager, null); @@ -170,7 +173,7 @@ public void ExecutorExecuteShouldThrowSettingsException() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(true); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); @@ -189,7 +192,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationException() this.ResetAndAddSourceToCommandLineOptions(true); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); @@ -207,7 +210,7 @@ public void ExecutorExecuteShouldThrowOtherExceptions() this.ResetAndAddSourceToCommandLineOptions(true); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager, null); @@ -299,7 +302,7 @@ private void RunListFullyQualifiedTestArgumentProcessorWithTraits(Mock mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; + private Mock mockFinalizationManager; private static ListTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestManager, IOutput output) { @@ -76,6 +78,7 @@ public ListTestsArgumentProcessorTests() this.mockAssemblyMetadataProvider.Setup(x => x.GetFrameWork(It.IsAny())).Returns(new FrameworkName(Constants.DotNetFramework40)); this.inferHelper = new InferHelper(this.mockAssemblyMetadataProvider.Object); this.mockProcessHelper = new Mock(); + this.mockFinalizationManager = new Mock(); } /// @@ -125,7 +128,7 @@ public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() { CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object; CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, this.mockFileHelper.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager, null); executor.Initialize(this.dummyTestFilePath); @@ -138,7 +141,7 @@ public void ExecutorExecuteForNoSourcesShouldReturnFail() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => executor.Execute()); @@ -155,7 +158,7 @@ public void ExecutorExecuteShouldThrowTestPlatformException() this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => executor.Execute()); @@ -172,7 +175,7 @@ public void ExecutorExecuteShouldThrowSettingsException() this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => listTestsArgumentExecutor.Execute()); @@ -189,7 +192,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationException() this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => listTestsArgumentExecutor.Execute()); @@ -206,7 +209,7 @@ public void ExecutorExecuteShouldThrowOtherExceptions() this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => executor.Execute()); @@ -263,7 +266,7 @@ private void RunListTestArgumentProcessorExecuteWithMockSetup(Mock mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; + private Mock mockFinalizationManager; private RunSpecificTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestManager) { @@ -67,6 +69,7 @@ public RunSpecificTestsArgumentProcessorTests() this.mockProcessHelper = new Mock(); this.mockProcessHelper.Setup(x => x.GetCurrentProcessId()).Returns(1234); this.mockProcessHelper.Setup(x => x.GetProcessName(It.IsAny())).Returns("dotnet.exe"); + this.mockFinalizationManager = new Mock(); } [TestMethod] @@ -111,7 +114,7 @@ public void InitializeShouldThrowIfArgumentIsNull() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => { executor.Initialize(null); }); @@ -122,7 +125,7 @@ public void InitializeShouldThrowIfArgumentIsEmpty() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => { executor.Initialize(String.Empty); }); @@ -133,7 +136,7 @@ public void InitializeShouldThrowIfArgumentIsWhiteSpace() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => { executor.Initialize(" "); }); @@ -144,7 +147,7 @@ public void InitializeShouldThrowIfArgumentsAreEmpty() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => { executor.Initialize(" , "); }); @@ -155,7 +158,7 @@ public void ExecutorShouldSplitTestsSeparatedByComma() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -166,7 +169,7 @@ public void ExecutorExecuteForNoSourcesShouldThrowCommandLineException() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -189,7 +192,7 @@ public void ExecutorExecuteForValidSourceWithTestCaseFilterShouldRunTests() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); CommandLineOptions.Instance.TestCaseFilterValue = "Filter"; @@ -214,7 +217,7 @@ public void ExecutorExecuteShouldThrowTestPlatformExceptionThrownDuringDiscovery mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -232,7 +235,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationExceptionThrownDuringDisco mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -250,7 +253,7 @@ public void ExecutorExecuteShouldThrowSettingsExceptionThrownDuringDiscovery() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -273,7 +276,7 @@ public void ExecutorExecuteShouldThrowTestPlatformExceptionThrownDuringExecution mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -298,7 +301,7 @@ public void ExecutorExecuteShouldThrowSettingsExceptionThrownDuringExecution() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -324,7 +327,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationExceptionThrownDuringExecu this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -345,7 +348,7 @@ public void ExecutorExecuteShouldForValidSourcesAndNoTestsDiscoveredShouldLogWar mockDiscoveryRequest.Setup(dr => dr.DiscoverAsync()).Raises(dr => dr.OnDiscoveredTests += null, new DiscoveredTestsEventArgs(new List())); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -366,7 +369,7 @@ public void ExecutorExecuteShouldForValidSourcesAndNoTestsDiscoveredShouldLogApp mockDiscoveryRequest.Setup(dr => dr.DiscoverAsync()).Raises(dr => dr.OnDiscoveredTests += null, new DiscoveredTestsEventArgs(new List())); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -393,7 +396,7 @@ public void ExecutorExecuteShouldForValidSourcesAndValidSelectedTestsRunsTestsAn mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -419,7 +422,7 @@ public void ExecutorShouldRunTestsWhenTestsAreCommaSeparated() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1, Test2"); @@ -446,7 +449,7 @@ public void ExecutorShouldRunTestsWhenTestsAreFiltered() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -472,7 +475,7 @@ public void ExecutorShouldWarnWhenTestsAreNotAvailable() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1, Test2"); @@ -499,7 +502,7 @@ public void ExecutorShouldRunTestsWhenTestsAreCommaSeparatedWithEscape() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1(a\\,b), Test2(c\\,d)"); @@ -529,7 +532,7 @@ public void ExecutorShouldDisplayWarningIfNoTestsAreExecuted() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -558,7 +561,7 @@ public void ExecutorShouldNotDisplayWarningIfTestsAreExecuted() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); diff --git a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs index 3143356d41..b14404d302 100644 --- a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs @@ -23,6 +23,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities; @@ -47,6 +48,7 @@ public class RunTestsArgumentProcessorTests private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; + private Mock mockFinalizationManager; public RunTestsArgumentProcessorTests() { @@ -64,6 +66,7 @@ public RunTestsArgumentProcessorTests() .Returns(Architecture.X86); this.mockAssemblyMetadataProvider.Setup(x => x.GetFrameWork(It.IsAny())).Returns(new FrameworkName(Constants.DotNetFramework40)); this.mockProcessHelper = new Mock(); + this.mockFinalizationManager = new Mock(); } [TestMethod] @@ -109,7 +112,7 @@ public void ExecutorExecuteShouldReturnSuccessWithoutExecutionInDesignMode() CommandLineOptions.Instance.Reset(); CommandLineOptions.Instance.IsDesignMode = true; - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = new RunTestsArgumentExecutor(CommandLineOptions.Instance, runSettingsProvider, testRequestManager, this.mockOutput.Object); Assert.AreEqual(ArgumentProcessorResult.Success, executor.Execute()); @@ -119,7 +122,7 @@ public void ExecutorExecuteShouldReturnSuccessWithoutExecutionInDesignMode() public void ExecutorExecuteForNoSourcesShouldThrowCommandLineException() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -148,7 +151,7 @@ public void ExecutorExecuteShouldThrowTestPlatformException() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -164,7 +167,7 @@ public void ExecutorExecuteShouldThrowSettingsException() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -180,7 +183,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationException() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -196,7 +199,7 @@ public void ExecutorExecuteShouldThrowOtherExceptions() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -251,7 +254,7 @@ private ArgumentProcessorResult RunRunArgumentProcessorExecuteWithMockSetup(ITes this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); var executor = GetExecutor(testRequestManager); return executor.Execute(); diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index 6f5bdca8cc..0dafd5eef6 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -35,8 +35,9 @@ namespace vstest.console.UnitTests.TestPlatformHelpers using vstest.console.UnitTests.TestDoubles; using Microsoft.VisualStudio.TestPlatform.Utilities; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; - [TestClass] + [TestClass] public class TestRequestManagerTests { private DummyLoggerEvents mockLoggerEvents; @@ -55,6 +56,7 @@ public class TestRequestManagerTests private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; + private Mock mockFinalizationManager; private const string DefaultRunsettings = @" @@ -86,7 +88,8 @@ public TestRequestManagerTests() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); this.mockMetricsCollection = new Mock(); this.mockRequestData = new Mock(); this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(this.mockMetricsCollection.Object); @@ -100,6 +103,7 @@ public TestRequestManagerTests() .Returns(new FrameworkName(Constants.DotNetFramework40)); this.mockProcessHelper.Setup(x => x.GetCurrentProcessId()).Returns(1234); this.mockProcessHelper.Setup(x => x.GetProcessName(It.IsAny())).Returns("dotnet.exe"); + this.mockFinalizationManager = new Mock(); } [TestCleanup] @@ -122,7 +126,8 @@ public void TestRequestManagerShouldNotInitializeConsoleLoggerIfDesignModeIsSet( new Mock().Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); Assert.IsFalse(this.mockLoggerEvents.EventsSubscribed()); } @@ -203,8 +208,9 @@ public void DiscoverTestsShouldCallTestPlatformAndSucceed() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); this.testRequestManager.DiscoverTests(payload, mockDiscoveryRegistrar.Object, this.protocolConfig); @@ -253,7 +259,8 @@ public void DiscoverTestsShouldPassSameProtocolConfigInRequestData() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); // Act this.testRequestManager.DiscoverTests(payload, mockDiscoveryRegistrar.Object, mockProtocolConfig); @@ -300,7 +307,8 @@ public void DiscoverTestsShouldCollectMetrics() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); // Act @@ -349,7 +357,8 @@ public void DiscoverTestsShouldCollectTargetDeviceLocalMachineIfTargetDeviceStri this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); // Act @@ -392,7 +401,8 @@ public void DiscoverTestsShouldCollectTargetDeviceIfTargetDeviceIsDevice() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); // Act @@ -435,7 +445,8 @@ public void DiscoverTestsShouldCollectTargetDeviceIfTargetDeviceIsEmulator() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); // Act @@ -478,7 +489,8 @@ public void DiscoverTestsShouldCollectCommands() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); CommandLineOptions.Instance.Parallel = true; CommandLineOptions.Instance.EnableCodeCoverage = true; @@ -533,7 +545,8 @@ public void DiscoverTestsShouldCollectTestSettings() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); CommandLineOptions.Instance.SettingsFile = @"c://temp/.testsettings"; @@ -580,7 +593,8 @@ public void DiscoverTestsShouldCollectVsmdiFile() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); CommandLineOptions.Instance.SettingsFile = @"c://temp/.vsmdi"; @@ -627,7 +641,8 @@ public void DiscoverTestsShouldCollectTestRunConfigFile() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); CommandLineOptions.Instance.SettingsFile = @"c://temp/.testrunConfig"; @@ -949,7 +964,8 @@ public void RunTestsShouldCollectCommands() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); CommandLineOptions.Instance.Parallel = true; CommandLineOptions.Instance.EnableCodeCoverage = true; @@ -1016,7 +1032,8 @@ public void RunTestsShouldCollectTelemetryForLegacySettings() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); // Act. this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, mockProtocolConfig); @@ -1065,7 +1082,8 @@ public void RunTestsShouldCollectTelemetryForTestSettingsEmbeddedInsideRunSettin this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); // Act. this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, mockProtocolConfig); @@ -1112,7 +1130,8 @@ public void RunTestsShouldCollectMetrics() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); // Act. this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, mockProtocolConfig); @@ -1159,7 +1178,8 @@ public void RunTestsWithSourcesShouldCallTestPlatformAndSucceed() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - this.mockProcessHelper.Object); + this.mockProcessHelper.Object, + this.mockFinalizationManager.Object); this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig); From 29d618d802ee72933dbcf3931916db15f3d3c947 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Wed, 10 Jun 2020 17:25:21 +0200 Subject: [PATCH 15/58] More changes --- .../DesignMode/DesignModeClient.cs | 6 ++++++ .../Interfaces/ITestRequestHandler.cs | 6 ------ .../EventHandlers/TestRequestHandler.cs | 15 --------------- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index 9fd465c7a0..64e03580af 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -227,6 +227,12 @@ private void ProcessRequests(ITestRequestManager testRequestManager) break; } + case MessageType.MultiTestRunsFinalizationCancel: + { + testRequestManager.CancelMultiTestRunsFinalization(); + break; + } + case MessageType.CustomTestHostLaunchCallback: { this.onCustomTestHostLaunchAckReceived?.Invoke(message); diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestHandler.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestHandler.cs index a83897979d..8908a72fc7 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestHandler.cs @@ -79,12 +79,6 @@ public interface ITestRequestHandler : IDisposable /// The last Chunk. void DiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable lastChunk); - /// - /// The multi test runs finalization complete handler - /// - /// Attachments - void MultiTestRunsFinalizationComplete(ICollection attachments); - /// /// Launches a process with a given process info under debugger /// Adapter get to call into this to launch any additional processes under debugger diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs index cb0b7b30a7..2436f0a9f5 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs @@ -11,9 +11,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.EventHandlers; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.EventHandlers; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunsFinalization; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; @@ -196,19 +194,6 @@ public void DiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventA this.SendData(data); } - /// - public void MultiTestRunsFinalizationComplete(ICollection attachments) - { - var data = this.dataSerializer.SerializePayload( - MessageType.MultiTestRunsFinalizationComplete, - new MultiTestRunsFinalizationCompletePayload - { - Attachments = attachments - }, - this.protocolVersion); - this.SendData(data); - } - /// public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessStartInfo) { From 44c5fdc3ae0707b244307fb28c0260a904631bdb Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Wed, 10 Jun 2020 20:27:42 +0200 Subject: [PATCH 16/58] acceptance tests green --- .../MultiTestRunsFinalizationEventsHandler.cs | 2 +- .../MultiTestRunsFinalizationManager.cs | 6 +----- .../CodeCoverageDataAttachmentsHandler.cs | 8 ++++++-- .../TranslationLayerTests/FinalizeMultiTestRunsTests.cs | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationEventsHandler.cs index 67dcab7c2c..e9111ad903 100644 --- a/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationEventsHandler.cs @@ -46,7 +46,7 @@ public void HandleMultiTestRunsFinalizationComplete(ICollection a var payload = new MultiTestRunsFinalizationCompletePayload() { - Attachments = null + Attachments = attachments }; // Send run complete to translation layer diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs index 036077669b..77ba2d5331 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs @@ -53,11 +53,7 @@ public async Task FinalizeMultiTestRunsAsync(ICollection attachme var completedTask = await Task.WhenAny(task, taskCompletionSource.Task); - if (completedTask == task) - { - eventHandler.HandleMultiTestRunsFinalizationComplete(attachments); - } - else + if (completedTask != task) { eventHandler.HandleMultiTestRunsFinalizationComplete(null); } diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index 822dded6a0..f2ceeac7f2 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -89,14 +89,18 @@ private string MergeCodeCoverageFiles(IList files, CancellationToken can } catch (OperationCanceledException) { - if (EqtTrace.IsInfoEnabled) + if (EqtTrace.IsWarningEnabled) { - EqtTrace.Info("CodeCoverageDataCollectorAttachmentsHandler: operation was cancelled."); + EqtTrace.Warning("CodeCoverageDataCollectorAttachmentsHandler: operation was cancelled."); } throw; } catch (ObjectDisposedException) { + if (EqtTrace.IsWarningEnabled) + { + EqtTrace.Warning("CodeCoverageDataCollectorAttachmentsHandler: object disposed."); + } throw; } catch (Exception ex) diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs index bb26430a8b..f2093e7b7f 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs @@ -56,6 +56,7 @@ public void FinalizeMultiTestRuns(RunnerInfo runnerInfo) this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); // Assert + multiTestRunsFinalizationEventHandler.EnsureSuccess(); Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.multiTestRunsFinalizationEventHandler.Attachments.Count); } From 39f3f84f1da86402ac39dbf1464537dc7a48e533 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 11 Jun 2020 10:20:33 +0200 Subject: [PATCH 17/58] Review comments #1 --- .../DesignMode/DesignModeClient.cs | 27 +++++------ .../MultiTestRunFinalizationEventsHandler.cs} | 40 ++++++++++------ .../RequestHelper/ITestRequestManager.cs | 12 ++--- ...cs => IMultiTestRunFinalizationManager.cs} | 10 ++-- .../JsonDataSerializer.cs | 2 +- .../Messages/MessageType.cs | 12 ++--- ...ultiTestRunFinalizationCompletePayload.cs} | 6 +-- .../Interfaces/ITestPlatformEventSource.cs | 32 ++++++------- .../Tracing/TestPlatformEventSource.cs | 48 +++++++++---------- .../TestPlatformInstrumentationEvents.cs | 16 +++---- .../Adapter/FrameworkHandle.cs | 2 +- .../DataCollectorAttachmentsHandler.cs | 46 ++++++++++++++++++ ...TestRunsDataCollectorAttachmentsHandler.cs | 43 ----------------- .../ParallelDataCollectionEventsHandler.cs | 4 +- .../MultiTestRunFinalizationManager.cs} | 26 +++++----- .../Adapter/Interfaces/IFrameworkHandle.cs | 2 +- ...IMultiTestRunFinalizationEventsHandler.cs} | 8 ++-- ....cs => MultiTestRunFinalizationPayload.cs} | 4 +- .../ITranslationLayerRequestSender.cs | 8 ++-- .../Interfaces/IVsTestConsoleWrapper2.cs | 8 ++-- .../Resources/Resources.Designer.cs | 4 +- .../Resources/Resources.resx | 2 +- .../Resources/xlf/Resources.cs.xlf | 2 +- .../Resources/xlf/Resources.de.xlf | 2 +- .../Resources/xlf/Resources.es.xlf | 2 +- .../Resources/xlf/Resources.fr.xlf | 2 +- .../Resources/xlf/Resources.it.xlf | 2 +- .../Resources/xlf/Resources.ja.xlf | 2 +- .../Resources/xlf/Resources.ko.xlf | 2 +- .../Resources/xlf/Resources.pl.xlf | 2 +- .../Resources/xlf/Resources.pt-BR.xlf | 2 +- .../Resources/xlf/Resources.ru.xlf | 2 +- .../Resources/xlf/Resources.tr.xlf | 2 +- .../Resources/xlf/Resources.xlf | 2 +- .../Resources/xlf/Resources.zh-Hans.xlf | 2 +- .../Resources/xlf/Resources.zh-Hant.xlf | 2 +- .../VsTestConsoleRequestSender.cs | 32 ++++++------- .../VsTestConsoleWrapper.cs | 8 ++-- .../TestPlatformHelpers/TestRequestManager.cs | 32 ++++++------- ...> MultiTestRunFinalizationEventHandler.cs} | 6 +-- ...sTests.cs => FinalizeMultiTestRunTests.cs} | 16 +++---- ...llyQualifiedTestsArgumentProcessorTests.cs | 4 +- .../ListTestsArgumentProcessorTests.cs | 4 +- .../RunSpecificTestsArgumentProcessorTests.cs | 4 +- .../RunTestsArgumentProcessorTests.cs | 4 +- .../TestRequestManagerTests.cs | 4 +- 46 files changed, 257 insertions(+), 247 deletions(-) rename src/Microsoft.TestPlatform.Client/{MultiTestRunsFinalization/MultiTestRunsFinalizationEventsHandler.cs => MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs} (57%) rename src/Microsoft.TestPlatform.Common/Interfaces/Engine/{IMultiTestRunsFinalizationManager.cs => IMultiTestRunFinalizationManager.cs} (63%) rename src/Microsoft.TestPlatform.CommunicationUtilities/Messages/{MultiTestRunsFinalizationCompletePayload.cs => MultiTestRunFinalizationCompletePayload.cs} (73%) create mode 100644 src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs delete mode 100644 src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/MultiTestRunsDataCollectorAttachmentsHandler.cs rename src/Microsoft.TestPlatform.CrossPlatEngine/{MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs => MultiTestRunFinalization/MultiTestRunFinalizationManager.cs} (63%) rename src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/{IMultiTestRunsFinalizationEventsHandler.cs => IMultiTestRunFinalizationEventsHandler.cs} (55%) rename src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/{MultiTestRunsFinalizationPayload.cs => MultiTestRunFinalizationPayload.cs} (75%) rename test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/{MultiTestRunsFinalizationEventHandler.cs => MultiTestRunFinalizationEventHandler.cs} (90%) rename test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/{FinalizeMultiTestRunsTests.cs => FinalizeMultiTestRunTests.cs} (94%) diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index 64e03580af..f83ff7d0bc 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode using System.Net; using System.Threading; using System.Threading.Tasks; - using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunsFinalization; + using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; @@ -17,13 +17,11 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; - using Microsoft.VisualStudio.TestPlatform.Utilities; using CommunicationUtilitiesResources = Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources.Resources; using CoreUtilitiesConstants = Microsoft.VisualStudio.TestPlatform.CoreUtilities.Constants; using ObjectModelConstants = Microsoft.VisualStudio.TestPlatform.ObjectModel.Constants; @@ -201,11 +199,11 @@ private void ProcessRequests(ITestRequestManager testRequestManager) break; } - case MessageType.MultiTestRunsFinalizationStart: + case MessageType.MultiTestRunFinalizationStart: { - var multiTestRunsFinalizationPayload = - this.communicationManager.DeserializePayload(message); - this.StartMultiTestRunsFinalization(multiTestRunsFinalizationPayload, testRequestManager); + var multiTestRunFinalizationPayload = + this.communicationManager.DeserializePayload(message); + this.StartMultiTestRunFinalization(multiTestRunFinalizationPayload, testRequestManager); break; } @@ -227,9 +225,9 @@ private void ProcessRequests(ITestRequestManager testRequestManager) break; } - case MessageType.MultiTestRunsFinalizationCancel: + case MessageType.MultiTestRunFinalizationCancel: { - testRequestManager.CancelMultiTestRunsFinalization(); + testRequestManager.CancelMultiTestRunFinalization(); break; } @@ -474,30 +472,29 @@ private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITe }); } - private void StartMultiTestRunsFinalization(MultiTestRunsFinalizationPayload finalizationPayload, ITestRequestManager testRequestManager) + private void StartMultiTestRunFinalization(MultiTestRunFinalizationPayload finalizationPayload, ITestRequestManager testRequestManager) { Task.Run( delegate { try { - testRequestManager.ResetOptions(); - testRequestManager.FinalizeMultiTestRuns(finalizationPayload, new MultiTestRunsFinalizationEventsHandler(this.communicationManager)); + testRequestManager.FinalizeMultiTestRun(finalizationPayload, new MultiTestRunFinalizationEventsHandler(this.communicationManager)); } catch (Exception ex) { - EqtTrace.Error("DesignModeClient: Exception in StartMultiTestRunsFinalization: " + ex); + EqtTrace.Error("DesignModeClient: Exception in StartMultiTestRunFinalization: " + ex); var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() }; this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); - var payload = new MultiTestRunsFinalizationCompletePayload() + var payload = new MultiTestRunFinalizationCompletePayload() { Attachments = null }; // Send run complete to translation layer - this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationComplete, payload); + this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationComplete, payload); } }); } diff --git a/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs similarity index 57% rename from src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationEventsHandler.cs rename to src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs index e9111ad903..e2c59074db 100644 --- a/src/Microsoft.TestPlatform.Client/MultiTestRunsFinalization/MultiTestRunsFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunsFinalization +namespace Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization { using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; @@ -13,15 +13,17 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunsFinalization /// /// The multi test finalization event handler. /// - public class MultiTestRunsFinalizationEventsHandler : IMultiTestRunsFinalizationEventsHandler + public class MultiTestRunFinalizationEventsHandler : IMultiTestRunFinalizationEventsHandler { - private ICommunicationManager communicationManager; + private readonly ICommunicationManager communicationManager; + private bool finalizationCompleteSent; + private readonly object syncObject = new object(); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The Request Handler. - public MultiTestRunsFinalizationEventsHandler(ICommunicationManager communicationManager) + public MultiTestRunFinalizationEventsHandler(ICommunicationManager communicationManager) { this.communicationManager = communicationManager; } @@ -37,20 +39,28 @@ public void HandleLogMessage(TestMessageLevel level, string message) this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); } - public void HandleMultiTestRunsFinalizationComplete(ICollection attachments) + public void HandleMultiTestRunFinalizationComplete(ICollection attachments) { - if (EqtTrace.IsInfoEnabled) + lock(this.syncObject) { - EqtTrace.Info("Multi test runs finalization completed."); - } + if(!finalizationCompleteSent) + { + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("Multi test run finalization completed."); + } - var payload = new MultiTestRunsFinalizationCompletePayload() - { - Attachments = attachments - }; + var payload = new MultiTestRunFinalizationCompletePayload() + { + Attachments = attachments + }; - // Send run complete to translation layer - this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationComplete, payload); + // Send run complete to translation layer + this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationComplete, payload); + + finalizationCompleteSent = true; + } + } } public void HandleRawMessage(string rawMessage) diff --git a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs index 813f9f416e..380484ab7f 100644 --- a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs +++ b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs @@ -45,11 +45,11 @@ public interface ITestRequestManager : IDisposable void RunTests(TestRunRequestPayload testRunRequestPayLoad, ITestHostLauncher customTestHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig); /// - /// Finalize multi test runs + /// Finalize multi test run /// - /// Multi test runs finalization payload - /// Multi test runs finalization events handler - void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload multiTestRunsFinalizationPayload, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationEventsHandler); + /// Multi test run finalization payload + /// Multi test run finalization events handler + void FinalizeMultiTestRun(MultiTestRunFinalizationPayload multiTestRunFinalizationPayload, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationEventsHandler); /// /// Cancel the current TestRun request @@ -67,8 +67,8 @@ public interface ITestRequestManager : IDisposable void CancelDiscovery(); /// - /// Cancels the current multi test runs finalization request + /// Cancels the current multi test run finalization request /// - void CancelMultiTestRunsFinalization(); + void CancelMultiTestRunFinalization(); } } diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs similarity index 63% rename from src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunsFinalizationManager.cs rename to src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs index 64d14e8f56..892c2336bb 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunsFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs @@ -9,16 +9,16 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine { /// - /// Orchestrates multi test runs finalization operations. + /// Orchestrates multi test run finalization operations. /// - public interface IMultiTestRunsFinalizationManager + public interface IMultiTestRunFinalizationManager { /// - /// Finalizes multi test runs + /// Finalizes multi test run /// /// Attachments - /// EventHandler for handling multi test runs finalization events from Engine + /// EventHandler for handling multi test run finalization events from Engine /// Cancellation token - Task FinalizeMultiTestRunsAsync(ICollection attachments, IMultiTestRunsFinalizationEventsHandler eventHandler, CancellationToken cancellationToken); + Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs index d0aa538ebe..4923e98e4a 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs @@ -47,7 +47,7 @@ private JsonDataSerializer() // MemoryTraceWriter can help diagnose serialization issues. Enable it for // debug builds only. // Note that MemoryTraceWriter is not thread safe, please don't use it in parallel - // test runs. See https://github.com/JamesNK/Newtonsoft.Json/issues/1279 + // test run. See https://github.com/JamesNK/Newtonsoft.Json/issues/1279 payloadSerializer.TraceWriter = new MemoryTraceWriter(); payloadSerializer2.TraceWriter = new MemoryTraceWriter(); #endif diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs index 041617694f..bb23393f03 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs @@ -124,19 +124,19 @@ public static class MessageType public const string CustomTestHostLaunchCallback = "TestExecution.CustomTestHostLaunchCallback"; /// - /// Multi test runs finalization + /// Multi test run finalization /// - public const string MultiTestRunsFinalizationStart = "MultiTestRunsFinalization.Start"; + public const string MultiTestRunFinalizationStart = "MultiTestRunFinalization.Start"; /// - /// Multi test runs finalization callback + /// Multi test run finalization callback /// - public const string MultiTestRunsFinalizationComplete = "MultiTestRunsFinalization.Complete"; + public const string MultiTestRunFinalizationComplete = "MultiTestRunFinalization.Complete"; /// - /// Cancel multi test runs finalization + /// Cancel multi test run finalization /// - public const string MultiTestRunsFinalizationCancel = "MultiTestRunsFinalization.Cancel"; + public const string MultiTestRunFinalizationCancel = "MultiTestRunFinalization.Cancel"; /// /// Extensions Initialization diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunsFinalizationCompletePayload.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationCompletePayload.cs similarity index 73% rename from src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunsFinalizationCompletePayload.cs rename to src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationCompletePayload.cs index 457f539d86..d20d55e61a 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunsFinalizationCompletePayload.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationCompletePayload.cs @@ -1,4 +1,4 @@ -// 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. namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel @@ -8,9 +8,9 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel using Microsoft.VisualStudio.TestPlatform.ObjectModel; /// - /// Multi test runs finalization complete payload. + /// Multi test run finalization complete payload. /// - public class MultiTestRunsFinalizationCompletePayload + public class MultiTestRunFinalizationCompletePayload { /// /// Gets or sets the attachments. diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs index db84bd3bd6..41a0d7b7ce 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs @@ -184,52 +184,52 @@ public interface ITestPlatformEventSource void MetricsDisposeStop(); /// - /// The multi test runs finalization request start. + /// The multi test run finalization request start. /// - void MultiTestRunsFinalizationRequestStart(); + void MultiTestRunFinalizationRequestStart(); /// - /// The multi test runs finalization request stop. + /// The multi test run finalization request stop. /// - void MultiTestRunsFinalizationRequestStop(); + void MultiTestRunFinalizationRequestStop(); /// - /// The adapter multi test runs finalization start. + /// The adapter multi test run finalization start. /// /// /// The number of attachements. /// - void AdapterMultiTestRunsFinalizationStart(long numberOfAttachements); + void AdapterMultiTestRunFinalizationStart(long numberOfAttachements); /// - /// The adapter multi test runs finalization stop. + /// The adapter multi test run finalization stop. /// /// /// The number of attachements. /// - void AdapterMultiTestRunsFinalizationStop(long numberOfAttachements); + void AdapterMultiTestRunFinalizationStop(long numberOfAttachements); /// - /// The multi test runs finalization start. + /// The multi test run finalization start. /// - void MultiTestRunsFinalizationStart(); + void MultiTestRunFinalizationStart(); /// - /// The multi test runs finalization stop. + /// The multi test run finalization stop. /// /// /// The number of attachements. /// - void MultiTestRunsFinalizationStop(long numberOfAttachements); + void MultiTestRunFinalizationStop(long numberOfAttachements); /// - /// Mark the start of translation layer multi test runs finalization request. + /// Mark the start of translation layer multi test run finalization request. /// - void TranslationLayerMultiTestRunsFinalizationStart(); + void TranslationLayerMultiTestRunFinalizationStart(); /// - /// Mark the completion of translation layer multi test runs finalization request. + /// Mark the completion of translation layer multi test run finalization request. /// - void TranslationLayerMultiTestRunsFinalizationStop(); + void TranslationLayerMultiTestRunFinalizationStop(); } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs index edf6846b19..7a615cf53e 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs @@ -239,59 +239,59 @@ public void MetricsDisposeStop() } /// - [Event(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationRequestStartEventId)] - public void MultiTestRunsFinalizationRequestStart() + [Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationRequestStartEventId)] + public void MultiTestRunFinalizationRequestStart() { - this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationRequestStartEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationRequestStartEventId); } /// - [Event(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationRequestStopEventId)] - public void MultiTestRunsFinalizationRequestStop() + [Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationRequestStopEventId)] + public void MultiTestRunFinalizationRequestStop() { - this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationRequestStopEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationRequestStopEventId); } /// - [Event(TestPlatformInstrumentationEvents.AdapterMultiTestRunsFinalizationStartEventId)] - public void AdapterMultiTestRunsFinalizationStart(long numberOfAttachements) + [Event(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStartEventId)] + public void AdapterMultiTestRunFinalizationStart(long numberOfAttachements) { - this.WriteEvent(TestPlatformInstrumentationEvents.AdapterMultiTestRunsFinalizationStartEventId, numberOfAttachements); + this.WriteEvent(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStartEventId, numberOfAttachements); } /// - [Event(TestPlatformInstrumentationEvents.AdapterMultiTestRunsFinalizationStopEventId)] - public void AdapterMultiTestRunsFinalizationStop(long numberOfAttachements) + [Event(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStopEventId)] + public void AdapterMultiTestRunFinalizationStop(long numberOfAttachements) { - this.WriteEvent(TestPlatformInstrumentationEvents.AdapterMultiTestRunsFinalizationStopEventId, numberOfAttachements); + this.WriteEvent(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStopEventId, numberOfAttachements); } /// - [Event(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationStartEventId)] - public void MultiTestRunsFinalizationStart() + [Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId)] + public void MultiTestRunFinalizationStart() { - this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationStartEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId); } /// - [Event(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationStopEventId)] - public void MultiTestRunsFinalizationStop(long numberOfAttachements) + [Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStopEventId)] + public void MultiTestRunFinalizationStop(long numberOfAttachements) { - this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunsFinalizationStopEventId, numberOfAttachements); + this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStopEventId, numberOfAttachements); } /// - [Event(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunsFinalizationStartEventId)] - public void TranslationLayerMultiTestRunsFinalizationStart() + [Event(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunFinalizationStartEventId)] + public void TranslationLayerMultiTestRunFinalizationStart() { - this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunsFinalizationStartEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunFinalizationStartEventId); } /// - [Event(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunsFinalizationStopEventId)] - public void TranslationLayerMultiTestRunsFinalizationStop() + [Event(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunFinalizationStopEventId)] + public void TranslationLayerMultiTestRunFinalizationStop() { - this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunsFinalizationStopEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunFinalizationStopEventId); } } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs index 9931100f1c..498eb86b25 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs @@ -161,41 +161,41 @@ internal class TestPlatformInstrumentationEvents /// /// The session finalization start event id. /// - public const int MultiTestRunsFinalizationStartEventId = 0x40; + public const int MultiTestRunFinalizationStartEventId = 0x40; /// /// The session finalization stop event id. /// - public const int MultiTestRunsFinalizationStopEventId = 0x41; + public const int MultiTestRunFinalizationStopEventId = 0x41; /// /// The session finalization request start event id. /// - public const int MultiTestRunsFinalizationRequestStartEventId = 0x42; + public const int MultiTestRunFinalizationRequestStartEventId = 0x42; /// /// The session finalization request stop event id. /// - public const int MultiTestRunsFinalizationRequestStopEventId = 0x43; + public const int MultiTestRunFinalizationRequestStopEventId = 0x43; /// /// The adapter session finalization start event id. /// - public const int AdapterMultiTestRunsFinalizationStartEventId = 0x44; + public const int AdapterMultiTestRunFinalizationStartEventId = 0x44; /// /// The adapter session finalization stop event id. /// - public const int AdapterMultiTestRunsFinalizationStopEventId = 0x45; + public const int AdapterMultiTestRunFinalizationStopEventId = 0x45; /// /// Events fired on session finalization start of translation layer. /// - public const int TranslationLayerMultiTestRunsFinalizationStartEventId = 0x46; + public const int TranslationLayerMultiTestRunFinalizationStartEventId = 0x46; /// /// Events fired on session finalization complete in translation layer. /// - public const int TranslationLayerMultiTestRunsFinalizationStopEventId = 0x47; + public const int TranslationLayerMultiTestRunFinalizationStopEventId = 0x47; } } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Adapter/FrameworkHandle.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Adapter/FrameworkHandle.cs index ca8ba14780..fb5fb90129 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Adapter/FrameworkHandle.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Adapter/FrameworkHandle.cs @@ -59,7 +59,7 @@ public FrameworkHandle(ITestCaseEventsHandler testCaseEventsHandler, ITestRunCac /// - /// Give a hint to the execution framework to enable the shutdown of execution process after the test run is complete. This should be used only in out of process test runs when IRunContext.KeepAlive is true + /// Give a hint to the execution framework to enable the shutdown of execution process after the test run is complete. This should be used only in out of process test run when IRunContext.KeepAlive is true /// and should be used only when absolutely required as using it degrades the performance of the subsequent run. /// It throws InvalidOperationException when it is attempted to be enabled when keepAlive is false. /// diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs new file mode 100644 index 0000000000..40037744b1 --- /dev/null +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading; + +namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection +{ + public class DataCollectorAttachmentsHandler + { + private readonly IDataCollectorAttachments[] dataCollectorAttachmentsHandlers; + + public DataCollectorAttachmentsHandler(params IDataCollectorAttachments[] dataCollectorAttachmentsHandlers) + { + this.dataCollectorAttachmentsHandlers = dataCollectorAttachmentsHandlers; + } + + public void HandleAttachements(ICollection attachments, CancellationToken cancellationToken) + { + foreach(var dataCollectorAttachmentsHandler in dataCollectorAttachmentsHandlers) + { + Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); + if (attachementUri != null) + { + var coverageAttachments = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); + + foreach (var coverageAttachment in coverageAttachments) + { + attachments.Remove(coverageAttachment); + } + + ICollection mergedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(coverageAttachments), cancellationToken); + foreach (var attachment in mergedAttachments) + { + attachments.Add(attachment); + } + } + } + } + } +} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/MultiTestRunsDataCollectorAttachmentsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/MultiTestRunsDataCollectorAttachmentsHandler.cs deleted file mode 100644 index b83b6d327a..0000000000 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/MultiTestRunsDataCollectorAttachmentsHandler.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.VisualStudio.TestPlatform.ObjectModel; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Threading; - -namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection -{ - public class MultiTestRunsDataCollectorAttachmentsHandler - { - private readonly IDataCollectorAttachments dataCollectorAttachmentsHandler; - - public MultiTestRunsDataCollectorAttachmentsHandler(IDataCollectorAttachments dataCollectorAttachmentsHandler) - { - this.dataCollectorAttachmentsHandler = dataCollectorAttachmentsHandler; - } - - public void HandleAttachements(ICollection attachments, CancellationToken cancellationToken) - { - Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); - if (attachementUri != null) - { - var coverageAttachments = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); - - foreach (var coverageAttachment in coverageAttachments) - { - attachments.Remove(coverageAttachment); - } - - ICollection mergedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(coverageAttachments), cancellationToken); - foreach (var attachment in mergedAttachments) - { - attachments.Add(attachment); - } - } - } - } -} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs index 3b645be321..770554cac0 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs @@ -16,7 +16,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection internal class ParallelDataCollectionEventsHandler : ParallelRunEventsHandler { private readonly ParallelRunDataAggregator runDataAggregator; - private readonly MultiTestRunsDataCollectorAttachmentsHandler attachmentsHandler; + private readonly DataCollectorAttachmentsHandler attachmentsHandler; public ParallelDataCollectionEventsHandler(IRequestData requestData, IProxyExecutionManager proxyExecutionManager, @@ -26,7 +26,7 @@ public ParallelDataCollectionEventsHandler(IRequestData requestData, this(requestData, proxyExecutionManager, actualRunEventsHandler, parallelProxyExecutionManager, runDataAggregator, JsonDataSerializer.Instance) { // TODO : use TestPluginCache to iterate over all IDataCollectorAttachments - attachmentsHandler = new MultiTestRunsDataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()); + attachmentsHandler = new DataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()); } internal ParallelDataCollectionEventsHandler(IRequestData requestData, diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs similarity index 63% rename from src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs rename to src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index 77ba2d5331..398ef08071 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunsFinalization/MultiTestRunsFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -10,30 +10,30 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; -namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunsFinalization +namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization { /// - /// Orchestrates multi test runs finalization operations for the engine communicating with the test host process. + /// Orchestrates multi test run finalization operations for the engine communicating with the test host process. /// - public class MultiTestRunsFinalizationManager : IMultiTestRunsFinalizationManager + public class MultiTestRunFinalizationManager : IMultiTestRunFinalizationManager { - private readonly MultiTestRunsDataCollectorAttachmentsHandler attachmentsHandler; + private readonly DataCollectorAttachmentsHandler attachmentsHandler; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public MultiTestRunsFinalizationManager(MultiTestRunsDataCollectorAttachmentsHandler attachmentsHandler) + public MultiTestRunFinalizationManager(DataCollectorAttachmentsHandler attachmentsHandler) { this.attachmentsHandler = attachmentsHandler; } /// - /// Finalizes multi test runs + /// Finalizes multi test run /// /// Attachments - /// EventHandler for handling multi test runs finalization events from Engine + /// EventHandler for handling multi test run finalization events from Engine /// Cancellation token - public async Task FinalizeMultiTestRunsAsync(ICollection attachments, IMultiTestRunsFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) + public async Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) { try { @@ -48,22 +48,22 @@ public async Task FinalizeMultiTestRunsAsync(ICollection attachme Task task = Task.Run(() => { attachmentsHandler.HandleAttachements(attachments, cancellationToken); - eventHandler.HandleMultiTestRunsFinalizationComplete(attachments); + eventHandler.HandleMultiTestRunFinalizationComplete(attachments); }); var completedTask = await Task.WhenAny(task, taskCompletionSource.Task); if (completedTask != task) { - eventHandler.HandleMultiTestRunsFinalizationComplete(null); + eventHandler.HandleMultiTestRunFinalizationComplete(null); } } catch (Exception e) { - EqtTrace.Error("MultiTestRunsFinalizationManager: Exception in FinalizeMultiTestRunsAsync: " + e); + EqtTrace.Error("MultiTestRunFinalizationManager: Exception in FinalizeMultiTestRunAsync: " + e); eventHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); - eventHandler.HandleMultiTestRunsFinalizationComplete(null); + eventHandler.HandleMultiTestRunFinalizationComplete(null); } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Adapter/Interfaces/IFrameworkHandle.cs b/src/Microsoft.TestPlatform.ObjectModel/Adapter/Interfaces/IFrameworkHandle.cs index 4e71e2e870..947b857477 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Adapter/Interfaces/IFrameworkHandle.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Adapter/Interfaces/IFrameworkHandle.cs @@ -12,7 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter public interface IFrameworkHandle : ITestExecutionRecorder, IMessageLogger { /// - /// Gets or sets a value indicating whether the execution framework enables the shutdown of execution process after the test run is complete. This should be used only in out of process test runs when IRunContext.KeepAlive is true + /// Gets or sets a value indicating whether the execution framework enables the shutdown of execution process after the test run is complete. This should be used only in out of process test run when IRunContext.KeepAlive is true /// and should be used only when absolutely required as using it degrades the performance of the subsequent run. /// It throws InvalidOperationException when it is attempted to be enabled when keepAlive is false. /// diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs similarity index 55% rename from src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs rename to src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs index ed4cbd7b8d..93484152da 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunsFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs @@ -6,14 +6,14 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client { /// - /// Interface contract for handling multi test runs finalization complete events + /// Interface contract for handling multi test run finalization complete events /// - public interface IMultiTestRunsFinalizationEventsHandler : ITestMessageEventHandler + public interface IMultiTestRunFinalizationEventsHandler : ITestMessageEventHandler { /// - /// Dispatch MultiTestRunsFinalizationComplete event to listeners. + /// Dispatch MultiTestRunFinalizationComplete event to listeners. /// /// Attachments reprocessed. - void HandleMultiTestRunsFinalizationComplete(ICollection attachments); + void HandleMultiTestRunFinalizationComplete(ICollection attachments); } } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunsFinalizationPayload.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs similarity index 75% rename from src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunsFinalizationPayload.cs rename to src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs index 63f81593e5..5066f0e3a9 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunsFinalizationPayload.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs @@ -7,9 +7,9 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client using System.Runtime.Serialization; /// - /// Class used to define the MultiTestRunsFinalizationPayload sent by the Vstest.console translation layers into design mode + /// Class used to define the MultiTestRunFinalizationPayload sent by the Vstest.console translation layers into design mode /// - public class MultiTestRunsFinalizationPayload + public class MultiTestRunFinalizationPayload { /// /// Settings used for the discovery request. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs index 9c19766e17..4200918f0c 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs @@ -115,12 +115,12 @@ internal interface ITranslationLayerRequestSender : IDisposable /// Provides back all attachements to TestPlatform for additional processing (for example merging) /// /// List of attachements - /// - void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler); + /// + void FinalizeMultiTestRun(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler); /// - /// Cancels multi test runs finalization + /// Cancels multi test run finalization /// - void CancelMultiTestRunsFinalization(); + void CancelMultiTestRunFinalization(); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs index 5fbc6ce412..2eb0ccff72 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs @@ -17,12 +17,12 @@ public interface IVsTestConsoleWrapper2 : IVsTestConsoleWrapper /// Provides back all attachements to TestPlatform for additional processing (for example merging) /// /// List of attachements - /// EventHandler to receive session complete event - void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler); + /// EventHandler to receive session complete event + void FinalizeMultiTestRun(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler); /// - /// Cancel last multi test runs finalization + /// Cancel last multi test run finalization /// - void CancelMultiTestRunsFinalization(); + void CancelMultiTestRunFinalization(); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs index 97fa3b3bd9..d1cee45a68 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs @@ -64,9 +64,9 @@ internal Resources() { /// /// Looks up a localized string similar to The active Multi Test Runs Finalization was aborted.. /// - internal static string AbortedMultiTestRunsFinalization { + internal static string AbortedMultiTestRunFinalization { get { - return ResourceManager.GetString("AbortedMultiTestRunsFinalization", resourceCulture); + return ResourceManager.GetString("AbortedMultiTestRunFinalization", resourceCulture); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx index c4dbc5499f..ff17cc093a 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx @@ -117,7 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.cs.xlf index b294113385..819e22e1d4 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.cs.xlf @@ -61,7 +61,7 @@ Soubor {0} neexistuje. - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.de.xlf index f872f51df0..0b8284ad05 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.de.xlf @@ -61,7 +61,7 @@ Die Datei "{0}" ist nicht vorhanden. - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.es.xlf index dae24bf8e2..c3f256ea4f 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.es.xlf @@ -61,7 +61,7 @@ El archivo {0} no existe - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.fr.xlf index 4bb65df96e..9a0dfc259c 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.fr.xlf @@ -61,7 +61,7 @@ Le fichier {0} n'existe pas - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.it.xlf index 4cba448970..1928a75bf6 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.it.xlf @@ -61,7 +61,7 @@ Il file {0} non esiste - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ja.xlf index fbb25bc10b..0c65c579e2 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ja.xlf @@ -61,7 +61,7 @@ ファイル {0} が存在しません - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ko.xlf index a66ea99bd5..273ff35d2c 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ko.xlf @@ -61,7 +61,7 @@ {0} 파일이 없습니다. - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pl.xlf index bb5ca13bac..59a2514c1a 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pl.xlf @@ -61,7 +61,7 @@ Plik {0} nie istnieje - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pt-BR.xlf index 42cbe9c639..a2dfe8395f 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pt-BR.xlf @@ -61,7 +61,7 @@ O arquivo {0} não existe - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ru.xlf index 2703ec8608..d4c27e0dc4 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ru.xlf @@ -61,7 +61,7 @@ Файл {0} не существует. - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.tr.xlf index c7602e8a39..8bc197a0b0 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.tr.xlf @@ -61,7 +61,7 @@ {0} dosyası yok - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.xlf index 13c519fae0..1772dac841 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.xlf @@ -23,7 +23,7 @@ File {0} does not exists - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hans.xlf index 6913dfd7f4..6824d9b9db 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hans.xlf @@ -61,7 +61,7 @@ 文件 {0} 不存在 - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hant.xlf index 17c5464473..2d27648708 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hant.xlf @@ -61,7 +61,7 @@ 檔案 {0} 不存在 - + The active Multi Test Runs Finalization was aborted. The active Multi Test Runs Finalization was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index e546068396..e4532e2191 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -384,19 +384,19 @@ public void EndSession() } /// - public void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler testSessionEventsHandler) + public void FinalizeMultiTestRun(ICollection attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler) { this.SendMessageAndListenAndReportAttachements(attachments, testSessionEventsHandler); } /// - public void CancelMultiTestRunsFinalization() + public void CancelMultiTestRunFinalization() { if (EqtTrace.IsInfoEnabled) { - EqtTrace.Info("VsTestConsoleRequestSender.CancelMultiTestRunsFinalization: Canceling multi test runs finalization."); + EqtTrace.Info("VsTestConsoleRequestSender.CancelMultiTestRunFinalization: Canceling multi test run finalization."); } - this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationCancel); + this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationCancel); } /// @@ -741,35 +741,35 @@ private async Task SendMessageAndListenAndReportTestResultsAsync(string messageT this.testPlatformEventSource.TranslationLayerExecutionStop(); } - private void SendMessageAndListenAndReportAttachements(ICollection attachments, IMultiTestRunsFinalizationEventsHandler eventHandler) + private void SendMessageAndListenAndReportAttachements(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler) { try { - var payload = new MultiTestRunsFinalizationPayload + var payload = new MultiTestRunFinalizationPayload { Attachments = attachments }; - this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationStart, payload); - var isMultiTestRunsFinalizationComplete = false; + this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationStart, payload); + var isMultiTestRunFinalizationComplete = false; // Cycle through the messages that the vstest.console sends. // Currently each of the operations are not separate tasks since they should not each take much time. // This is just a notification. - while (!isMultiTestRunsFinalizationComplete) + while (!isMultiTestRunFinalizationComplete) { var message = this.TryReceiveMessage(); - if (string.Equals(MessageType.MultiTestRunsFinalizationComplete, message.MessageType)) + if (string.Equals(MessageType.MultiTestRunFinalizationComplete, message.MessageType)) { if (EqtTrace.IsInfoEnabled) { EqtTrace.Info("VsTestConsoleRequestSender.SendMessageAndListenAndReportAttachements: Process complete."); } - var multiTestRunsFinalizationCompletePayload = this.dataSerializer.DeserializePayload(message); + var multiTestRunFinalizationCompletePayload = this.dataSerializer.DeserializePayload(message); - eventHandler.HandleMultiTestRunsFinalizationComplete(multiTestRunsFinalizationCompletePayload.Attachments); - isMultiTestRunsFinalizationComplete = true; + eventHandler.HandleMultiTestRunFinalizationComplete(multiTestRunFinalizationCompletePayload.Attachments); + isMultiTestRunFinalizationComplete = true; } else if (string.Equals(MessageType.TestMessage, message.MessageType)) { @@ -781,8 +781,8 @@ private void SendMessageAndListenAndReportAttachements(ICollection - public void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler testSessionEventsHandler) + public void FinalizeMultiTestRun(ICollection attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler) { - this.testPlatformEventSource.TranslationLayerMultiTestRunsFinalizationStart(); + this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStart(); this.EnsureInitialized(); - this.requestSender.FinalizeMultiTestRuns(attachments, testSessionEventsHandler); + this.requestSender.FinalizeMultiTestRun(attachments, testSessionEventsHandler); } /// - public void CancelMultiTestRunsFinalization() + public void CancelMultiTestRunFinalization() { throw new System.NotImplementedException(); } diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 885b020e3f..0bcd0337d6 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -13,7 +13,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers using System.Xml; using System.Xml.XPath; using Microsoft.VisualStudio.TestPlatform.Client; - using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunsFinalization; + using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.CommandLine.Internal; using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities; @@ -26,7 +26,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunsFinalization; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; @@ -53,7 +53,7 @@ internal class TestRequestManager : ITestRequestManager private readonly Task metricsPublisher; private bool isDisposed; private IProcessHelper processHelper; - private IMultiTestRunsFinalizationManager finalizationManager; + private IMultiTestRunFinalizationManager finalizationManager; /// /// Maintains the current active execution request @@ -68,7 +68,7 @@ internal class TestRequestManager : ITestRequestManager private IDiscoveryRequest currentDiscoveryRequest; /// - /// Maintains the current active multi test runs finalization cancellation token source + /// Maintains the current active multi test run finalization cancellation token source /// Assumption : There can only be one active finalization request. /// private CancellationTokenSource currentFinalizationCancellationTokenSource; @@ -84,11 +84,11 @@ public TestRequestManager() new InferHelper(AssemblyMetadataProvider.Instance), MetricsPublisherFactory.GetMetricsPublisher(IsTelemetryOptedIn(), CommandLineOptions.Instance.IsDesignMode), new ProcessHelper(), - new MultiTestRunsFinalizationManager(new CrossPlatEngine.DataCollection.MultiTestRunsDataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()))) + new MultiTestRunFinalizationManager(new CrossPlatEngine.DataCollection.DataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()))) { } - internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform testPlatform, TestRunResultAggregator testRunResultAggregator, ITestPlatformEventSource testPlatformEventSource, InferHelper inferHelper, Task metricsPublisher, IProcessHelper processHelper, IMultiTestRunsFinalizationManager finalizationManager) + internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform testPlatform, TestRunResultAggregator testRunResultAggregator, ITestPlatformEventSource testPlatformEventSource, InferHelper inferHelper, Task metricsPublisher, IProcessHelper processHelper, IMultiTestRunFinalizationManager finalizationManager) { this.testPlatform = testPlatform; this.commandLineOptions = commandLineOptions; @@ -319,9 +319,9 @@ public void RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc /// EventHandler for discovered tests /// Protocol related information /// True, if successful - public void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload finalizationPayload, IMultiTestRunsFinalizationEventsHandler finalizationEventsHandler) + public void FinalizeMultiTestRun(MultiTestRunFinalizationPayload finalizationPayload, IMultiTestRunFinalizationEventsHandler finalizationEventsHandler) { - EqtTrace.Info("TestRequestManager.FinalizeMultiTestRuns: Multi test runs finalization started."); + EqtTrace.Info("TestRequestManager.FinalizeMultiTestRun: Multi test run finalization started."); // Make sure to run the run request inside a lock as the below section is not thread-safe // There can be only one discovery, execution or finalization request at a given point in time @@ -329,12 +329,12 @@ public void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload finalizationP { try { - EqtTrace.Info("TestRequestManager.FinalizeMultiTestRuns: Synchronization context taken"); - this.testPlatformEventSource.MultiTestRunsFinalizationRequestStart(); + EqtTrace.Info("TestRequestManager.FinalizeMultiTestRun: Synchronization context taken"); + this.testPlatformEventSource.MultiTestRunFinalizationRequestStart(); this.currentFinalizationCancellationTokenSource = new CancellationTokenSource(); - Task task = this.finalizationManager.FinalizeMultiTestRunsAsync(finalizationPayload.Attachments, finalizationEventsHandler, this.currentFinalizationCancellationTokenSource.Token); + Task task = this.finalizationManager.FinalizeMultiTestRunAsync(finalizationPayload.Attachments, finalizationEventsHandler, this.currentFinalizationCancellationTokenSource.Token); task.Wait(); } finally @@ -345,8 +345,8 @@ public void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload finalizationP this.currentFinalizationCancellationTokenSource = null; } - EqtTrace.Info("TestRequestManager.FinalizeMultiTestRuns: Multi test runs finalization completed."); - this.testPlatformEventSource.MultiTestRunsFinalizationRequestStop(); + EqtTrace.Info("TestRequestManager.FinalizeMultiTestRun: Multi test run finalization completed."); + this.testPlatformEventSource.MultiTestRunFinalizationRequestStop(); } } } @@ -393,11 +393,11 @@ public void AbortTestRun() } /// - /// Cancel the multi test runs finalization. + /// Cancel the multi test run finalization. /// - public void CancelMultiTestRunsFinalization() + public void CancelMultiTestRunFinalization() { - EqtTrace.Info("TestRequestManager.CancelMultiTestRunsFinalization: Sending cancel request."); + EqtTrace.Info("TestRequestManager.CancelMultiTestRunFinalization: Sending cancel request."); this.currentFinalizationCancellationTokenSource?.Cancel(); } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunsFinalizationEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs similarity index 90% rename from test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunsFinalizationEventHandler.cs rename to test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs index b2bad52b2d..0a1b77a832 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunsFinalizationEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs @@ -11,7 +11,7 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; /// - public class MultiTestRunsFinalizationEventHandler : IMultiTestRunsFinalizationEventsHandler + public class MultiTestRunFinalizationEventHandler : IMultiTestRunFinalizationEventsHandler { /// /// Gets the attachments. @@ -35,7 +35,7 @@ public class MultiTestRunsFinalizationEventHandler : IMultiTestRunsFinalizationE /// public TestMessageLevel TestMessageLevel { get; private set; } - public MultiTestRunsFinalizationEventHandler() + public MultiTestRunFinalizationEventHandler() { this.Errors = new List(); this.Attachments = new List(); @@ -75,7 +75,7 @@ public bool AttachDebuggerToProcess(int pid) return true; } - public void HandleMultiTestRunsFinalizationComplete(ICollection attachments) + public void HandleMultiTestRunFinalizationComplete(ICollection attachments) { if(attachments != null) { diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunTests.cs similarity index 94% rename from test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs rename to test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunTests.cs index f2093e7b7f..12fd9ae8a7 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunTests.cs @@ -20,17 +20,17 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests /// The Run Tests using VsTestConsoleWrapper API's /// [TestClass] - public class FinalizeMultiTestRunsTests : AcceptanceTestBase + public class FinalizeMultiTestRunTests : AcceptanceTestBase { private IVsTestConsoleWrapper2 vstestConsoleWrapper; private RunEventHandler runEventHandler; - private MultiTestRunsFinalizationEventHandler multiTestRunsFinalizationEventHandler; + private MultiTestRunFinalizationEventHandler multiTestRunFinalizationEventHandler; private void Setup() { this.vstestConsoleWrapper = this.GetVsTestConsoleWrapper(); this.runEventHandler = new RunEventHandler(); - this.multiTestRunsFinalizationEventHandler = new MultiTestRunsFinalizationEventHandler(); + this.multiTestRunFinalizationEventHandler = new MultiTestRunFinalizationEventHandler(); } [TestCleanup] @@ -42,7 +42,7 @@ public void Cleanup() [TestMethod] [NetFullTargetFrameworkDataSource] [NetCoreTargetFrameworkDataSource] - public void FinalizeMultiTestRuns(RunnerInfo runnerInfo) + public void FinalizeMultiTestRun(RunnerInfo runnerInfo) { AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); this.Setup(); @@ -53,11 +53,11 @@ public void FinalizeMultiTestRuns(RunnerInfo runnerInfo) Assert.AreEqual(6, this.runEventHandler.TestResults.Count); Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); + this.vstestConsoleWrapper.FinalizeMultiTestRun(runEventHandler.Attachments, multiTestRunFinalizationEventHandler); // Assert - multiTestRunsFinalizationEventHandler.EnsureSuccess(); - Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.multiTestRunsFinalizationEventHandler.Attachments.Count); + multiTestRunFinalizationEventHandler.EnsureSuccess(); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.multiTestRunFinalizationEventHandler.Attachments.Count); } [TestMethod] @@ -76,7 +76,7 @@ public void EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runnerInfo Assert.AreEqual(6, this.runEventHandler.TestResults.Count); Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); + this.vstestConsoleWrapper.FinalizeMultiTestRun(runEventHandler.Attachments, multiTestRunFinalizationEventHandler); this.vstestConsoleWrapper?.EndSession(); // Assert diff --git a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs index 34d411989a..1c7cdef211 100644 --- a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs @@ -45,7 +45,7 @@ public class ListFullyQualifiedTestsArgumentProcessorTests private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; - private Mock mockFinalizationManager; + private Mock mockFinalizationManager; private static ListFullyQualifiedTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestManager, IOutput output) { @@ -80,7 +80,7 @@ public ListFullyQualifiedTestsArgumentProcessorTests() this.mockAssemblyMetadataProvider.Setup(x => x.GetFrameWork(It.IsAny())).Returns(new FrameworkName(Constants.DotNetFramework40)); this.inferHelper = new InferHelper(this.mockAssemblyMetadataProvider.Object); this.mockProcessHelper = new Mock(); - this.mockFinalizationManager = new Mock(); + this.mockFinalizationManager = new Mock(); } /// diff --git a/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs index 86f2346f96..28812f3a3b 100644 --- a/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs @@ -43,7 +43,7 @@ public class ListTestsArgumentProcessorTests private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; - private Mock mockFinalizationManager; + private Mock mockFinalizationManager; private static ListTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestManager, IOutput output) { @@ -78,7 +78,7 @@ public ListTestsArgumentProcessorTests() this.mockAssemblyMetadataProvider.Setup(x => x.GetFrameWork(It.IsAny())).Returns(new FrameworkName(Constants.DotNetFramework40)); this.inferHelper = new InferHelper(this.mockAssemblyMetadataProvider.Object); this.mockProcessHelper = new Mock(); - this.mockFinalizationManager = new Mock(); + this.mockFinalizationManager = new Mock(); } /// diff --git a/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs index 082628a886..13a57eb932 100644 --- a/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs @@ -44,7 +44,7 @@ public class RunSpecificTestsArgumentProcessorTests private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; - private Mock mockFinalizationManager; + private Mock mockFinalizationManager; private RunSpecificTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestManager) { @@ -69,7 +69,7 @@ public RunSpecificTestsArgumentProcessorTests() this.mockProcessHelper = new Mock(); this.mockProcessHelper.Setup(x => x.GetCurrentProcessId()).Returns(1234); this.mockProcessHelper.Setup(x => x.GetProcessName(It.IsAny())).Returns("dotnet.exe"); - this.mockFinalizationManager = new Mock(); + this.mockFinalizationManager = new Mock(); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs index b14404d302..ac7d49b522 100644 --- a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs @@ -48,7 +48,7 @@ public class RunTestsArgumentProcessorTests private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; - private Mock mockFinalizationManager; + private Mock mockFinalizationManager; public RunTestsArgumentProcessorTests() { @@ -66,7 +66,7 @@ public RunTestsArgumentProcessorTests() .Returns(Architecture.X86); this.mockAssemblyMetadataProvider.Setup(x => x.GetFrameWork(It.IsAny())).Returns(new FrameworkName(Constants.DotNetFramework40)); this.mockProcessHelper = new Mock(); - this.mockFinalizationManager = new Mock(); + this.mockFinalizationManager = new Mock(); } [TestMethod] diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index 0dafd5eef6..02a16c39cc 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -56,7 +56,7 @@ public class TestRequestManagerTests private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; - private Mock mockFinalizationManager; + private Mock mockFinalizationManager; private const string DefaultRunsettings = @" @@ -103,7 +103,7 @@ public TestRequestManagerTests() .Returns(new FrameworkName(Constants.DotNetFramework40)); this.mockProcessHelper.Setup(x => x.GetCurrentProcessId()).Returns(1234); this.mockProcessHelper.Setup(x => x.GetProcessName(It.IsAny())).Returns("dotnet.exe"); - this.mockFinalizationManager = new Mock(); + this.mockFinalizationManager = new Mock(); } [TestCleanup] From d56baf6504a724d4d6298d37cb5ed8ee2c55a4c3 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 11 Jun 2020 11:17:29 +0200 Subject: [PATCH 18/58] Resolving more comments --- .../MultiTestRunFinalizationEventsHandler.cs | 28 ++++++------------- .../Interfaces/ITestPlatformEventSource.cs | 17 ++--------- .../Tracing/TestPlatformEventSource.cs | 18 ++---------- .../TestPlatformInstrumentationEvents.cs | 14 ++-------- .../DataCollectorAttachmentsHandler.cs | 10 +++---- .../MultiTestRunFinalizationManager.cs | 21 ++++++++++---- .../VsTestConsoleRequestSender.cs | 4 +-- .../TestPlatformHelpers/TestRequestManager.cs | 2 +- 8 files changed, 39 insertions(+), 75 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs index e2c59074db..78cc89e1be 100644 --- a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs @@ -16,8 +16,6 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization public class MultiTestRunFinalizationEventsHandler : IMultiTestRunFinalizationEventsHandler { private readonly ICommunicationManager communicationManager; - private bool finalizationCompleteSent; - private readonly object syncObject = new object(); /// /// Initializes a new instance of the class. @@ -41,26 +39,18 @@ public void HandleLogMessage(TestMessageLevel level, string message) public void HandleMultiTestRunFinalizationComplete(ICollection attachments) { - lock(this.syncObject) + if (EqtTrace.IsInfoEnabled) { - if(!finalizationCompleteSent) - { - if (EqtTrace.IsInfoEnabled) - { - EqtTrace.Info("Multi test run finalization completed."); - } - - var payload = new MultiTestRunFinalizationCompletePayload() - { - Attachments = attachments - }; + EqtTrace.Info("Multi test run finalization completed."); + } - // Send run complete to translation layer - this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationComplete, payload); + var payload = new MultiTestRunFinalizationCompletePayload() + { + Attachments = attachments + }; - finalizationCompleteSent = true; - } - } + // Send run complete to translation layer + this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationComplete, payload); } public void HandleRawMessage(string rawMessage) diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs index 41a0d7b7ce..a287b0cf6d 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs @@ -194,25 +194,12 @@ public interface ITestPlatformEventSource void MultiTestRunFinalizationRequestStop(); /// - /// The adapter multi test run finalization start. - /// - /// - /// The number of attachements. - /// - void AdapterMultiTestRunFinalizationStart(long numberOfAttachements); - - /// - /// The adapter multi test run finalization stop. + /// The multi test run finalization start. /// /// /// The number of attachements. /// - void AdapterMultiTestRunFinalizationStop(long numberOfAttachements); - - /// - /// The multi test run finalization start. - /// - void MultiTestRunFinalizationStart(); + void MultiTestRunFinalizationStart(long numberOfAttachements); /// /// The multi test run finalization stop. diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs index 7a615cf53e..7cda495578 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs @@ -252,25 +252,11 @@ public void MultiTestRunFinalizationRequestStop() this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationRequestStopEventId); } - /// - [Event(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStartEventId)] - public void AdapterMultiTestRunFinalizationStart(long numberOfAttachements) - { - this.WriteEvent(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStartEventId, numberOfAttachements); - } - - /// - [Event(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStopEventId)] - public void AdapterMultiTestRunFinalizationStop(long numberOfAttachements) - { - this.WriteEvent(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStopEventId, numberOfAttachements); - } - /// [Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId)] - public void MultiTestRunFinalizationStart() + public void MultiTestRunFinalizationStart(long numberOfAttachements) { - this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId, numberOfAttachements); } /// diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs index 498eb86b25..2fa7f1e87a 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs @@ -178,24 +178,14 @@ internal class TestPlatformInstrumentationEvents /// public const int MultiTestRunFinalizationRequestStopEventId = 0x43; - /// - /// The adapter session finalization start event id. - /// - public const int AdapterMultiTestRunFinalizationStartEventId = 0x44; - - /// - /// The adapter session finalization stop event id. - /// - public const int AdapterMultiTestRunFinalizationStopEventId = 0x45; - /// /// Events fired on session finalization start of translation layer. /// - public const int TranslationLayerMultiTestRunFinalizationStartEventId = 0x46; + public const int TranslationLayerMultiTestRunFinalizationStartEventId = 0x44; /// /// Events fired on session finalization complete in translation layer. /// - public const int TranslationLayerMultiTestRunFinalizationStopEventId = 0x47; + public const int TranslationLayerMultiTestRunFinalizationStopEventId = 0x45; } } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs index 40037744b1..639bd48ef9 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs @@ -27,15 +27,15 @@ public void HandleAttachements(ICollection attachments, Cancellat Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); if (attachementUri != null) { - var coverageAttachments = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); + var attachmentsToBeProcessed = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); - foreach (var coverageAttachment in coverageAttachments) + foreach (var attachment in attachmentsToBeProcessed) { - attachments.Remove(coverageAttachment); + attachments.Remove(attachment); } - ICollection mergedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(coverageAttachments), cancellationToken); - foreach (var attachment in mergedAttachments) + ICollection processedAttachements = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), cancellationToken); + foreach (var attachment in processedAttachements) { attachments.Add(attachment); } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index 398ef08071..baf4626add 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; @@ -18,13 +19,15 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinali public class MultiTestRunFinalizationManager : IMultiTestRunFinalizationManager { private readonly DataCollectorAttachmentsHandler attachmentsHandler; + private readonly ITestPlatformEventSource testPlatformEventSource; /// /// Initializes a new instance of the class. /// - public MultiTestRunFinalizationManager(DataCollectorAttachmentsHandler attachmentsHandler) + public MultiTestRunFinalizationManager(DataCollectorAttachmentsHandler attachmentsHandler, ITestPlatformEventSource testPlatformEventSource) { - this.attachmentsHandler = attachmentsHandler; + this.attachmentsHandler = attachmentsHandler ?? throw new ArgumentNullException(nameof(attachmentsHandler)); + this.testPlatformEventSource = testPlatformEventSource ?? throw new ArgumentNullException(nameof(testPlatformEventSource)); } /// @@ -39,6 +42,8 @@ public async Task FinalizeMultiTestRunAsync(ICollection attachmen { cancellationToken.ThrowIfCancellationRequested(); + testPlatformEventSource.MultiTestRunFinalizationStart(attachments.Count); + var taskCompletionSource = new TaskCompletionSource(); cancellationToken.Register(() => { @@ -47,15 +52,20 @@ public async Task FinalizeMultiTestRunAsync(ICollection attachmen Task task = Task.Run(() => { - attachmentsHandler.HandleAttachements(attachments, cancellationToken); - eventHandler.HandleMultiTestRunFinalizationComplete(attachments); + attachmentsHandler.HandleAttachements(attachments, cancellationToken); }); var completedTask = await Task.WhenAny(task, taskCompletionSource.Task); - if (completedTask != task) + if (completedTask == task) + { + eventHandler.HandleMultiTestRunFinalizationComplete(attachments); + testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); + } + else { eventHandler.HandleMultiTestRunFinalizationComplete(null); + testPlatformEventSource.MultiTestRunFinalizationStop(0); } } catch (Exception e) @@ -64,6 +74,7 @@ public async Task FinalizeMultiTestRunAsync(ICollection attachmen eventHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); eventHandler.HandleMultiTestRunFinalizationComplete(null); + testPlatformEventSource.MultiTestRunFinalizationStop(0); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index e4532e2191..beb8efce4e 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -386,7 +386,7 @@ public void EndSession() /// public void FinalizeMultiTestRun(ICollection attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler) { - this.SendMessageAndListenAndReportAttachements(attachments, testSessionEventsHandler); + this.SendMessageAndListenAndReportAttachments(attachments, testSessionEventsHandler); } /// @@ -741,7 +741,7 @@ private async Task SendMessageAndListenAndReportTestResultsAsync(string messageT this.testPlatformEventSource.TranslationLayerExecutionStop(); } - private void SendMessageAndListenAndReportAttachements(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler) + private void SendMessageAndListenAndReportAttachments(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler) { try { diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 0bcd0337d6..5f57eeb7ca 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -84,7 +84,7 @@ public TestRequestManager() new InferHelper(AssemblyMetadataProvider.Instance), MetricsPublisherFactory.GetMetricsPublisher(IsTelemetryOptedIn(), CommandLineOptions.Instance.IsDesignMode), new ProcessHelper(), - new MultiTestRunFinalizationManager(new CrossPlatEngine.DataCollection.DataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()))) + new MultiTestRunFinalizationManager(new CrossPlatEngine.DataCollection.DataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()), TestPlatformEventSource.Instance)) { } From c5a7134b3da9c31e6e0cee3def5b0094dda900c2 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 11 Jun 2020 12:39:47 +0200 Subject: [PATCH 19/58] Tests for design mode client --- .../DesignMode/DesignModeClientTests.cs | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs index 98befe71f8..e34ec2335c 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs @@ -9,6 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.UnitTests.DesignMode using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.Client.DesignMode; + using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.Common.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; @@ -405,6 +406,81 @@ public void DesignModeClientConnectShouldSendTestMessageAndDiscoverCompleteOnTes this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.DiscoveryComplete, It.IsAny()), Times.Once()); } + [TestMethod] + public void DesignModeClientConnectShouldSendTestMessageAndFinalizationCompleteOnExceptionInFinalization() + { + var payload = new MultiTestRunFinalizationPayload(); + var startFinalization = new Message { MessageType = MessageType.MultiTestRunFinalizationStart, Payload = JToken.FromObject(payload) }; + this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startFinalization); + this.mockCommunicationManager + .Setup(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny())) + .Callback(() => complateEvent.Set()); + this.mockTestRequestManager.Setup( + rm => rm.FinalizeMultiTestRun( + It.IsAny(), + It.IsAny())) + .Throws(new Exception()); + + this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); + + Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "Finalization not completed."); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Once()); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.Is(p => p.Attachments == null)), Times.Once()); + } + + [TestMethod] + public void DesignModeClientConnectShouldSendTestMessageAndDiscoverCompleteOnTestPlatformExceptionInFinalization() + { + var payload = new MultiTestRunFinalizationPayload(); + var startFinalization = new Message { MessageType = MessageType.MultiTestRunFinalizationStart, Payload = JToken.FromObject(payload) }; + this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startFinalization); + this.mockCommunicationManager + .Setup(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny())) + .Callback(() => complateEvent.Set()); + this.mockTestRequestManager.Setup( + rm => rm.FinalizeMultiTestRun( + It.IsAny(), + It.IsAny())) + .Throws(new TestPlatformException("Hello world")); + + this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); + + Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "Finalization not completed."); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Once()); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.Is(p => p.Attachments == null)), Times.Once()); + } + + [TestMethod] + public void DesignModeClientConnectShouldCallRequestManagerForFinalizationStart() + { + var payload = new MultiTestRunFinalizationPayload(); + var startFinalization = new Message { MessageType = MessageType.MultiTestRunFinalizationStart, Payload = JToken.FromObject(payload) }; + this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startFinalization); + + this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); + + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Never); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny()), Times.Never); + this.mockTestRequestManager.Verify(rm => rm.FinalizeMultiTestRun(It.IsAny(), It.IsAny())); + } + + [TestMethod] + public void DesignModeClientConnectShouldCallRequestManagerForFinalizationCancel() + { + var cancelFinalization = new Message { MessageType = MessageType.MultiTestRunFinalizationCancel }; + this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(cancelFinalization); + + this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); + + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Never); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny()), Times.Never); + this.mockTestRequestManager.Verify(rm => rm.CancelMultiTestRunFinalization()); + } + [TestMethod] public void DesignModeClientConnectShouldSendTestMessageAndExecutionCompleteOnExceptionInTestRun() { From daaef855543dc1c3bdc46964cda9b756f43193fd Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 11 Jun 2020 13:02:51 +0200 Subject: [PATCH 20/58] Tests for events handler --- ...tiTestRunFinalizationEventsHandlerTests.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs new file mode 100644 index 0000000000..26d50e6edc --- /dev/null +++ b/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +namespace Microsoft.TestPlatform.Client.UnitTests.MultiTestRunFinalization +{ + using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization; + using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; + using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + using Moq; + + [TestClass] + public class MultiTestRunFinalizationEventsHandlerTests + { + private readonly Mock mockCommunicationManager; + private readonly IMultiTestRunFinalizationEventsHandler handler; + + public MultiTestRunFinalizationEventsHandlerTests() + { + this.mockCommunicationManager = new Mock(); + this.handler = new MultiTestRunFinalizationEventsHandler(mockCommunicationManager.Object); + } + + [TestMethod] + public void EventsHandlerHandleLogMessageShouldSendTestMessage() + { + string message = "error message"; + + handler.HandleLogMessage(TestMessageLevel.Error, message); + + mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.Is(p => p.MessageLevel == TestMessageLevel.Error && p.Message == message))); + } + + [TestMethod] + public void EventsHandlerHandleMultiTestRunFinalizationCompleteShouldSendFinalizationCompleteMessage() + { + var attachments = new[] { new AttachmentSet(new System.Uri("http://www.bing.com/"), "code coverage") }; + + handler.HandleMultiTestRunFinalizationComplete(attachments); + + mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.Is(p => p.Attachments == attachments))); + } + + [TestMethod] + public void EventsHandlerHandleRawMessageShouldDoNothing() + { + handler.HandleRawMessage("any"); + + mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny()), Times.Never); + mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny(), It.IsAny()), Times.Never); + } + } +} From 7d7d8a15cea8e98f25743deaaa494e740404c07b Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 11 Jun 2020 13:08:39 +0200 Subject: [PATCH 21/58] revert not related changes --- .../JsonDataSerializer.cs | 2 +- .../Adapter/FrameworkHandle.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs index 4923e98e4a..d0aa538ebe 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs @@ -47,7 +47,7 @@ private JsonDataSerializer() // MemoryTraceWriter can help diagnose serialization issues. Enable it for // debug builds only. // Note that MemoryTraceWriter is not thread safe, please don't use it in parallel - // test run. See https://github.com/JamesNK/Newtonsoft.Json/issues/1279 + // test runs. See https://github.com/JamesNK/Newtonsoft.Json/issues/1279 payloadSerializer.TraceWriter = new MemoryTraceWriter(); payloadSerializer2.TraceWriter = new MemoryTraceWriter(); #endif diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Adapter/FrameworkHandle.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Adapter/FrameworkHandle.cs index fb5fb90129..ca8ba14780 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Adapter/FrameworkHandle.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Adapter/FrameworkHandle.cs @@ -59,7 +59,7 @@ public FrameworkHandle(ITestCaseEventsHandler testCaseEventsHandler, ITestRunCac /// - /// Give a hint to the execution framework to enable the shutdown of execution process after the test run is complete. This should be used only in out of process test run when IRunContext.KeepAlive is true + /// Give a hint to the execution framework to enable the shutdown of execution process after the test run is complete. This should be used only in out of process test runs when IRunContext.KeepAlive is true /// and should be used only when absolutely required as using it degrades the performance of the subsequent run. /// It throws InvalidOperationException when it is attempted to be enabled when keepAlive is false. /// From 5ae0b3a193c38a9b8deb3981d511117004fdf962 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Fri, 12 Jun 2020 21:36:02 +0200 Subject: [PATCH 22/58] More changes --- .../DataCollectorAttachmentsHandler.cs | 18 ++++++++++-------- .../EventHandlers/TestRequestHandler.cs | 1 - .../Adapter/Interfaces/IFrameworkHandle.cs | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs index 639bd48ef9..d4da660a77 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs @@ -28,16 +28,18 @@ public void HandleAttachements(ICollection attachments, Cancellat if (attachementUri != null) { var attachmentsToBeProcessed = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); - - foreach (var attachment in attachmentsToBeProcessed) + if(attachmentsToBeProcessed.Any()) { - attachments.Remove(attachment); - } + foreach (var attachment in attachmentsToBeProcessed) + { + attachments.Remove(attachment); + } - ICollection processedAttachements = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), cancellationToken); - foreach (var attachment in processedAttachements) - { - attachments.Add(attachment); + ICollection processedAttachements = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), cancellationToken); + foreach (var attachment in processedAttachements) + { + attachments.Add(attachment); + } } } } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs index 2436f0a9f5..5319d0bb78 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs @@ -5,7 +5,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities { using System; using System.Collections.Generic; - using System.Linq; using System.Threading; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.EventHandlers; diff --git a/src/Microsoft.TestPlatform.ObjectModel/Adapter/Interfaces/IFrameworkHandle.cs b/src/Microsoft.TestPlatform.ObjectModel/Adapter/Interfaces/IFrameworkHandle.cs index 947b857477..4e71e2e870 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Adapter/Interfaces/IFrameworkHandle.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Adapter/Interfaces/IFrameworkHandle.cs @@ -12,7 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter public interface IFrameworkHandle : ITestExecutionRecorder, IMessageLogger { /// - /// Gets or sets a value indicating whether the execution framework enables the shutdown of execution process after the test run is complete. This should be used only in out of process test run when IRunContext.KeepAlive is true + /// Gets or sets a value indicating whether the execution framework enables the shutdown of execution process after the test run is complete. This should be used only in out of process test runs when IRunContext.KeepAlive is true /// and should be used only when absolutely required as using it degrades the performance of the subsequent run. /// It throws InvalidOperationException when it is attempted to be enabled when keepAlive is false. /// From a9eee9c556dd73b574026e81a21d230e7097af41 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Sat, 13 Jun 2020 01:30:56 +0200 Subject: [PATCH 23/58] Compiling OK, tests OK --- .../IMultiTestRunFinalizationManager.cs | 2 +- .../Parallel/ParallelProxyExecutionManager.cs | 7 ++- ...ProxyExecutionManagerWithDataCollection.cs | 7 ++- .../DataCollectorAttachmentsHandler.cs | 48 ------------------- .../ParallelDataCollectionEventsHandler.cs | 13 +++-- .../MultiTestRunFinalizationManager.cs | 44 +++++++++++++---- .../IDataCollectorAttachments.cs | 1 + .../ITranslationLayerRequestSender.cs | 13 ++--- .../ITranslationLayerRequestSenderAsync.cs | 9 ++++ .../Interfaces/IVsTestConsoleWrapper.cs | 11 ++++- .../Interfaces/IVsTestConsoleWrapper2.cs | 28 ----------- .../Interfaces/IVsTestConsoleWrapperAsync.cs | 9 ++++ .../VsTestConsoleRequestSender.cs | 20 +++----- .../VsTestConsoleWrapper.cs | 13 ++--- .../VsTestConsoleWrapperAsync.cs | 10 ++++ .../TestPlatformHelpers/TestRequestManager.cs | 2 +- .../FinalizeMultiTestRunTests.cs | 13 ++--- .../TranslationLayerTests/RunTests.cs | 2 +- .../IntegrationTestBase.cs | 2 +- 19 files changed, 121 insertions(+), 133 deletions(-) delete mode 100644 src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs delete mode 100644 src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs index 892c2336bb..7a82cd3ccd 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs @@ -11,7 +11,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine /// /// Orchestrates multi test run finalization operations. /// - public interface IMultiTestRunFinalizationManager + internal interface IMultiTestRunFinalizationManager { /// /// Finalizes multi test run diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs index 3e0e0da772..922541e63c 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs @@ -256,12 +256,15 @@ private ParallelRunEventsHandler GetEventsHandler(IProxyExecutionManager concurr { if (concurrentManager is ProxyExecutionManagerWithDataCollection) { + var concurrentManagerWithDataCollection = concurrentManager as ProxyExecutionManagerWithDataCollection; + return new ParallelDataCollectionEventsHandler( this.requestData, - concurrentManager, + concurrentManagerWithDataCollection, this.currentRunEventsHandler, this, - this.currentRunDataAggregator); + this.currentRunDataAggregator, + concurrentManagerWithDataCollection.CancellationToken); } return new ParallelRunEventsHandler( diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManagerWithDataCollection.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManagerWithDataCollection.cs index 6aa6684e2d..179a6df370 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManagerWithDataCollection.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManagerWithDataCollection.cs @@ -5,7 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client { using System; using System.Collections.Generic; - + using System.Threading; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces; @@ -70,6 +70,11 @@ internal IProxyDataCollectionManager ProxyDataCollectionManager get; private set; } + /// + /// Gets the cancellation token for execution. + /// + internal CancellationToken CancellationToken => CancellationTokenSource.Token; + /// /// Ensure that the Execution component of engine is ready for execution usually by loading extensions. /// Skip default adapters flag. diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs deleted file mode 100644 index d4da660a77..0000000000 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.VisualStudio.TestPlatform.ObjectModel; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Threading; - -namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection -{ - public class DataCollectorAttachmentsHandler - { - private readonly IDataCollectorAttachments[] dataCollectorAttachmentsHandlers; - - public DataCollectorAttachmentsHandler(params IDataCollectorAttachments[] dataCollectorAttachmentsHandlers) - { - this.dataCollectorAttachmentsHandlers = dataCollectorAttachmentsHandlers; - } - - public void HandleAttachements(ICollection attachments, CancellationToken cancellationToken) - { - foreach(var dataCollectorAttachmentsHandler in dataCollectorAttachmentsHandlers) - { - Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); - if (attachementUri != null) - { - var attachmentsToBeProcessed = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); - if(attachmentsToBeProcessed.Any()) - { - foreach (var attachment in attachmentsToBeProcessed) - { - attachments.Remove(attachment); - } - - ICollection processedAttachements = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), cancellationToken); - foreach (var attachment in processedAttachements) - { - attachments.Add(attachment); - } - } - } - } - } - } -} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs index 770554cac0..aa3e56de62 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs @@ -7,7 +7,9 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection using System.Threading; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; + using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; @@ -16,17 +18,20 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection internal class ParallelDataCollectionEventsHandler : ParallelRunEventsHandler { private readonly ParallelRunDataAggregator runDataAggregator; - private readonly DataCollectorAttachmentsHandler attachmentsHandler; + private readonly IMultiTestRunFinalizationManager finalizationManager; + private readonly CancellationToken cancellationToken; public ParallelDataCollectionEventsHandler(IRequestData requestData, IProxyExecutionManager proxyExecutionManager, ITestRunEventsHandler actualRunEventsHandler, IParallelProxyExecutionManager parallelProxyExecutionManager, - ParallelRunDataAggregator runDataAggregator) : + ParallelRunDataAggregator runDataAggregator, + CancellationToken cancellationToken) : this(requestData, proxyExecutionManager, actualRunEventsHandler, parallelProxyExecutionManager, runDataAggregator, JsonDataSerializer.Instance) { // TODO : use TestPluginCache to iterate over all IDataCollectorAttachments - attachmentsHandler = new DataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()); + this.finalizationManager = new MultiTestRunFinalizationManager(TestPlatformEventSource.Instance, new CodeCoverageDataAttachmentsHandler()); + this.cancellationToken = cancellationToken; } internal ParallelDataCollectionEventsHandler(IRequestData requestData, @@ -53,7 +58,7 @@ public override void HandleTestRunComplete( if (parallelRunComplete) { - attachmentsHandler.HandleAttachements(runDataAggregator.RunContextAttachments, CancellationToken.None); + finalizationManager.FinalizeMultiTestRunAsync(runDataAggregator.RunContextAttachments, null, cancellationToken).Wait(); var completedArgs = new TestRunCompleteEventArgs(this.runDataAggregator.GetAggregatedRunStats(), this.runDataAggregator.IsCanceled, diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index baf4626add..3099fc2ccb 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -3,12 +3,14 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; -using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization @@ -18,16 +20,16 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinali /// public class MultiTestRunFinalizationManager : IMultiTestRunFinalizationManager { - private readonly DataCollectorAttachmentsHandler attachmentsHandler; private readonly ITestPlatformEventSource testPlatformEventSource; + private readonly IDataCollectorAttachments[] dataCollectorAttachmentsHandlers; /// /// Initializes a new instance of the class. /// - public MultiTestRunFinalizationManager(DataCollectorAttachmentsHandler attachmentsHandler, ITestPlatformEventSource testPlatformEventSource) + public MultiTestRunFinalizationManager(ITestPlatformEventSource testPlatformEventSource, params IDataCollectorAttachments[] dataCollectorAttachmentsHandlers) { - this.attachmentsHandler = attachmentsHandler ?? throw new ArgumentNullException(nameof(attachmentsHandler)); this.testPlatformEventSource = testPlatformEventSource ?? throw new ArgumentNullException(nameof(testPlatformEventSource)); + this.dataCollectorAttachmentsHandlers = dataCollectorAttachmentsHandlers ?? throw new ArgumentNullException(nameof(dataCollectorAttachmentsHandlers)); } /// @@ -52,19 +54,19 @@ public async Task FinalizeMultiTestRunAsync(ICollection attachmen Task task = Task.Run(() => { - attachmentsHandler.HandleAttachements(attachments, cancellationToken); + HandleAttachements(attachments, cancellationToken); }); var completedTask = await Task.WhenAny(task, taskCompletionSource.Task); if (completedTask == task) { - eventHandler.HandleMultiTestRunFinalizationComplete(attachments); + eventHandler?.HandleMultiTestRunFinalizationComplete(attachments); testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); } else { - eventHandler.HandleMultiTestRunFinalizationComplete(null); + eventHandler?.HandleMultiTestRunFinalizationComplete(null); testPlatformEventSource.MultiTestRunFinalizationStop(0); } } @@ -72,11 +74,35 @@ public async Task FinalizeMultiTestRunAsync(ICollection attachmen { EqtTrace.Error("MultiTestRunFinalizationManager: Exception in FinalizeMultiTestRunAsync: " + e); - eventHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); - eventHandler.HandleMultiTestRunFinalizationComplete(null); + eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); + eventHandler?.HandleMultiTestRunFinalizationComplete(null); testPlatformEventSource.MultiTestRunFinalizationStop(0); } + } + private void HandleAttachements(ICollection attachments, CancellationToken cancellationToken) + { + foreach (var dataCollectorAttachmentsHandler in dataCollectorAttachmentsHandlers) + { + Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); + if (attachementUri != null) + { + var attachmentsToBeProcessed = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); + if (attachmentsToBeProcessed.Any()) + { + foreach (var attachment in attachmentsToBeProcessed) + { + attachments.Remove(attachment); + } + + ICollection processedAttachements = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), cancellationToken); + foreach (var attachment in processedAttachements) + { + attachments.Add(attachment); + } + } + } + } } } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs index 6c1ed58acc..eff8238976 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs @@ -17,6 +17,7 @@ public interface IDataCollectorAttachments /// /// Gets the attachment set after Test Run Session ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, CancellationToken cancellationToken); + // TODO: add new method /// /// Gets the attachment Uri, which is handled by current Collector diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs index 4200918f0c..224edbe0aa 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs @@ -5,7 +5,8 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces { using System; using System.Collections.Generic; - + using System.Threading; + using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; @@ -115,12 +116,8 @@ internal interface ITranslationLayerRequestSender : IDisposable /// Provides back all attachements to TestPlatform for additional processing (for example merging) /// /// List of attachements - /// - void FinalizeMultiTestRun(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler); - - /// - /// Cancels multi test run finalization - /// - void CancelMultiTestRunFinalization(); + /// Events handler + /// Cancellation token + Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs index a49ce93fab..babfee4518 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs @@ -5,6 +5,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces { using System; using System.Collections.Generic; + using System.Threading; using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -76,5 +77,13 @@ internal interface ITranslationLayerRequestSenderAsync : IDisposable /// See . /// void OnProcessExited(); + + /// + /// Provides back all attachements to TestPlatform for additional processing (for example merging) + /// + /// List of attachements + /// Events handler + /// Cancellation token + Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs index b1469d3f8d..acc2ab836b 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs @@ -4,7 +4,8 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces { using System.Collections.Generic; - + using System.Threading; + using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; @@ -119,6 +120,14 @@ public interface IVsTestConsoleWrapper /// Custom test host launcher for the run. void RunTestsWithCustomTestHost(IEnumerable testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); + /// + /// Provides back all attachements to TestPlatform for additional processing (for example merging) + /// + /// List of attachements + /// EventHandler to receive session complete event + /// Cancellation token + Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); + /// /// Cancel the last test run. /// diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs deleted file mode 100644 index 2eb0ccff72..0000000000 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces -{ - using System.Collections.Generic; - - using Microsoft.VisualStudio.TestPlatform.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; - - /// - /// Controller for various test operations on the test runner. - /// - public interface IVsTestConsoleWrapper2 : IVsTestConsoleWrapper - { - /// - /// Provides back all attachements to TestPlatform for additional processing (for example merging) - /// - /// List of attachements - /// EventHandler to receive session complete event - void FinalizeMultiTestRun(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler); - - /// - /// Cancel last multi test run finalization - /// - void CancelMultiTestRunFinalization(); - } -} diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs index a303a3504f..d3b705150b 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs @@ -4,6 +4,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces { using System.Collections.Generic; + using System.Threading; using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -81,6 +82,14 @@ public interface IVsTestConsoleWrapperAsync /// Task RunTestsWithCustomTestHostAsync(IEnumerable testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); + /// + /// Provides back all attachements to TestPlatform for additional processing (for example merging) + /// + /// List of attachements + /// EventHandler to receive session complete event + /// Cancellation token + Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); + /// /// See . /// diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index beb8efce4e..5516f33c0b 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -384,19 +384,9 @@ public void EndSession() } /// - public void FinalizeMultiTestRun(ICollection attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler) + public Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) { - this.SendMessageAndListenAndReportAttachments(attachments, testSessionEventsHandler); - } - - /// - public void CancelMultiTestRunFinalization() - { - if (EqtTrace.IsInfoEnabled) - { - EqtTrace.Info("VsTestConsoleRequestSender.CancelMultiTestRunFinalization: Canceling multi test run finalization."); - } - this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationCancel); + return this.SendMessageAndListenAndReportFinalizationResultAsync(attachments, testSessionEventsHandler, cancellationToken); } /// @@ -741,7 +731,7 @@ private async Task SendMessageAndListenAndReportTestResultsAsync(string messageT this.testPlatformEventSource.TranslationLayerExecutionStop(); } - private void SendMessageAndListenAndReportAttachments(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler) + private async Task SendMessageAndListenAndReportFinalizationResultAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) { try { @@ -752,12 +742,14 @@ private void SendMessageAndListenAndReportAttachments(ICollection this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationStart, payload); var isMultiTestRunFinalizationComplete = false; + cancellationToken.Register(() => this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationCancel)); + // Cycle through the messages that the vstest.console sends. // Currently each of the operations are not separate tasks since they should not each take much time. // This is just a notification. while (!isMultiTestRunFinalizationComplete) { - var message = this.TryReceiveMessage(); + var message = await this.TryReceiveMessageAsync(); if (string.Equals(MessageType.MultiTestRunFinalizationComplete, message.MessageType)) { diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index d46256d3e6..d5145f5f65 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -7,7 +7,8 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer using System.Diagnostics; using System.Globalization; using System.Linq; - + using System.Threading; + using System.Threading.Tasks; using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing; @@ -24,7 +25,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer /// An implementation of to invoke test operations /// via the vstest.console test runner. /// - public class VsTestConsoleWrapper : IVsTestConsoleWrapper2 + public class VsTestConsoleWrapper : IVsTestConsoleWrapper { #region Private Members @@ -273,17 +274,13 @@ public void EndSession() this.sessionStarted = false; } - #endregion - - #region IVsTestConsoleWrapper2 - /// - public void FinalizeMultiTestRun(ICollection attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler) + public Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) { this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStart(); this.EnsureInitialized(); - this.requestSender.FinalizeMultiTestRun(attachments, testSessionEventsHandler); + return requestSender.FinalizeMultiTestRunAsync(attachments, testSessionEventsHandler, cancellationToken); } /// diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs index ca0a357c75..fc0f9a40fe 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs @@ -6,6 +6,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer using System.Collections.Generic; using System.Diagnostics; using System.Linq; + using System.Threading; using System.Threading.Tasks; using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; @@ -222,6 +223,15 @@ public async Task RunTestsWithCustomTestHostAsync(IEnumerable testCase await this.requestSender.StartTestRunWithCustomHostAsync(testCaseList, runSettings, options, testRunEventsHandler, customTestHostLauncher); } + /// + public async Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) + { + this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStart(); + + await this.EnsureInitializedAsync(); + await requestSender.FinalizeMultiTestRunAsync(attachments, testSessionEventsHandler, cancellationToken); + } + /// public void CancelTestRun() { diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 5f57eeb7ca..5ef58e6190 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -84,7 +84,7 @@ public TestRequestManager() new InferHelper(AssemblyMetadataProvider.Instance), MetricsPublisherFactory.GetMetricsPublisher(IsTelemetryOptedIn(), CommandLineOptions.Instance.IsDesignMode), new ProcessHelper(), - new MultiTestRunFinalizationManager(new CrossPlatEngine.DataCollection.DataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()), TestPlatformEventSource.Instance)) + new MultiTestRunFinalizationManager(TestPlatformEventSource.Instance, new CodeCoverageDataAttachmentsHandler())) { } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunTests.cs index 12fd9ae8a7..546d93efdc 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunTests.cs @@ -6,7 +6,6 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests using Microsoft.TestPlatform.TestUtilities; using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; using Microsoft.VisualStudio.TestPlatform.Common.Telemetry; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; @@ -14,6 +13,8 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests using System.Diagnostics; using System.IO; using System.Linq; + using System.Threading; + using System.Threading.Tasks; using VisualStudio.TestPlatform.ObjectModel.Logging; /// @@ -22,7 +23,7 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests [TestClass] public class FinalizeMultiTestRunTests : AcceptanceTestBase { - private IVsTestConsoleWrapper2 vstestConsoleWrapper; + private IVsTestConsoleWrapper vstestConsoleWrapper; private RunEventHandler runEventHandler; private MultiTestRunFinalizationEventHandler multiTestRunFinalizationEventHandler; @@ -42,7 +43,7 @@ public void Cleanup() [TestMethod] [NetFullTargetFrameworkDataSource] [NetCoreTargetFrameworkDataSource] - public void FinalizeMultiTestRun(RunnerInfo runnerInfo) + public async Task FinalizeMultiTestRun(RunnerInfo runnerInfo) { AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); this.Setup(); @@ -53,7 +54,7 @@ public void FinalizeMultiTestRun(RunnerInfo runnerInfo) Assert.AreEqual(6, this.runEventHandler.TestResults.Count); Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - this.vstestConsoleWrapper.FinalizeMultiTestRun(runEventHandler.Attachments, multiTestRunFinalizationEventHandler); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, multiTestRunFinalizationEventHandler, CancellationToken.None); // Assert multiTestRunFinalizationEventHandler.EnsureSuccess(); @@ -63,7 +64,7 @@ public void FinalizeMultiTestRun(RunnerInfo runnerInfo) [TestMethod] [NetFullTargetFrameworkDataSource] [NetCoreTargetFrameworkDataSource] - public void EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runnerInfo) + public async Task EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runnerInfo) { var numOfProcesses = Process.GetProcessesByName("vstest.console").Length; @@ -76,7 +77,7 @@ public void EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runnerInfo Assert.AreEqual(6, this.runEventHandler.TestResults.Count); Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - this.vstestConsoleWrapper.FinalizeMultiTestRun(runEventHandler.Attachments, multiTestRunFinalizationEventHandler); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, multiTestRunFinalizationEventHandler, CancellationToken.None); this.vstestConsoleWrapper?.EndSession(); // Assert diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTests.cs index 87ed476082..9be9c83360 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTests.cs @@ -21,7 +21,7 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests [TestClass] public class RunTests : AcceptanceTestBase { - private IVsTestConsoleWrapper2 vstestConsoleWrapper; + private IVsTestConsoleWrapper vstestConsoleWrapper; private RunEventHandler runEventHandler; private void Setup() diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs index 44356520c2..7d25744753 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs @@ -451,7 +451,7 @@ protected virtual string SetVSTestConsoleDLLPathInArgs(string args) /// Returns the VsTestConsole Wrapper. /// /// - public IVsTestConsoleWrapper2 GetVsTestConsoleWrapper() + public IVsTestConsoleWrapper GetVsTestConsoleWrapper() { var logFileName = Path.GetFileName(Path.GetTempFileName()); var logFileDir = Path.Combine(Path.GetTempPath(), "VSTestConsoleWrapperLogs"); From 08b646a75eec6b3b5d6a42815553bb3a94a8daaa Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Mon, 15 Jun 2020 11:56:30 +0200 Subject: [PATCH 24/58] Unit tests for manager --- .../IMultiTestRunFinalizationManager.cs | 11 +- .../ParallelDataCollectionEventsHandler.cs | 5 +- .../MultiTestRunFinalizationManager.cs | 32 +- .../MultiTestRunFinalizationManagerTests.cs | 478 ++++++++++++++++++ 4 files changed, 513 insertions(+), 13 deletions(-) create mode 100644 test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs index 7a82cd3ccd..b09c6f9339 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs @@ -3,6 +3,7 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Threading; using System.Threading.Tasks; @@ -14,11 +15,19 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine internal interface IMultiTestRunFinalizationManager { /// - /// Finalizes multi test run + /// Finalizes multi test run and provides results through handler /// /// Attachments /// EventHandler for handling multi test run finalization events from Engine /// Cancellation token Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken); + + /// + /// Finalizes multi test + /// + /// Attachments + /// EventHandler for handling multi test run finalization events from Engine + /// Cancellation token + Task> FinalizeMultiTestRunAsync(ICollection attachments, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs index aa3e56de62..ed9d614743 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs @@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection { using System.Collections.Generic; + using System.Collections.ObjectModel; using System.Threading; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; @@ -58,13 +59,13 @@ public override void HandleTestRunComplete( if (parallelRunComplete) { - finalizationManager.FinalizeMultiTestRunAsync(runDataAggregator.RunContextAttachments, null, cancellationToken).Wait(); + Collection attachments = finalizationManager.FinalizeMultiTestRunAsync(runDataAggregator.RunContextAttachments, cancellationToken).Result; var completedArgs = new TestRunCompleteEventArgs(this.runDataAggregator.GetAggregatedRunStats(), this.runDataAggregator.IsCanceled, this.runDataAggregator.IsAborted, this.runDataAggregator.GetAggregatedException(), - this.runDataAggregator.RunContextAttachments, + attachments, this.runDataAggregator.ElapsedTime); // Add Metrics from Test Host diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index 3099fc2ccb..2eb388eeeb 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -32,19 +32,25 @@ public MultiTestRunFinalizationManager(ITestPlatformEventSource testPlatformEven this.dataCollectorAttachmentsHandlers = dataCollectorAttachmentsHandlers ?? throw new ArgumentNullException(nameof(dataCollectorAttachmentsHandlers)); } - /// - /// Finalizes multi test run - /// - /// Attachments - /// EventHandler for handling multi test run finalization events from Engine - /// Cancellation token + /// public async Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) + { + await InternalFinalizeMultiTestRunAsync(new Collection(attachments.ToList()), eventHandler, cancellationToken); + } + + /// + public Task> FinalizeMultiTestRunAsync(ICollection attachments, CancellationToken cancellationToken) + { + return InternalFinalizeMultiTestRunAsync(new Collection(attachments.ToList()), null, cancellationToken); + } + + private async Task> InternalFinalizeMultiTestRunAsync(Collection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) { try { - cancellationToken.ThrowIfCancellationRequested(); + testPlatformEventSource.MultiTestRunFinalizationStart(attachments?.Count ?? 0); - testPlatformEventSource.MultiTestRunFinalizationStart(attachments.Count); + cancellationToken.ThrowIfCancellationRequested(); var taskCompletionSource = new TaskCompletionSource(); cancellationToken.Register(() => @@ -54,21 +60,26 @@ public async Task FinalizeMultiTestRunAsync(ICollection attachmen Task task = Task.Run(() => { - HandleAttachements(attachments, cancellationToken); + HandleAttachements(attachments, cancellationToken); }); var completedTask = await Task.WhenAny(task, taskCompletionSource.Task); if (completedTask == task) { + await task; eventHandler?.HandleMultiTestRunFinalizationComplete(attachments); testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); + return attachments; } else { + eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Informational, "Finalization was cancelled."); eventHandler?.HandleMultiTestRunFinalizationComplete(null); - testPlatformEventSource.MultiTestRunFinalizationStop(0); + testPlatformEventSource.MultiTestRunFinalizationStop(0); } + + return null; } catch (Exception e) { @@ -77,6 +88,7 @@ public async Task FinalizeMultiTestRunAsync(ICollection attachmen eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); eventHandler?.HandleMultiTestRunFinalizationComplete(null); testPlatformEventSource.MultiTestRunFinalizationStop(0); + return null; } } diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs new file mode 100644 index 0000000000..5a681f38c4 --- /dev/null +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs @@ -0,0 +1,478 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.TestPlatform.CrossPlatEngine.UnitTests.MultiTestRunFinalization +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading; + using System.Threading.Tasks; + + using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using Moq; + + [TestClass] + public class MultiTestRunFinalizationManagerTests + { + private const string uri1 = "datacollector://microsoft/some1/1.0"; + private const string uri2 = "datacollector://microsoft/some2/2.0"; + private const string uri3 = "datacollector://microsoft/some3/2.0"; + + private readonly Mock mockEventSource; + private readonly Mock mockAttachmentHandler1; + private readonly Mock mockAttachmentHandler2; + private readonly Mock mockEventsHandler; + private readonly MultiTestRunFinalizationManager manager; + private readonly CancellationTokenSource cancellationTokenSource; + + public MultiTestRunFinalizationManagerTests() + { + mockEventSource = new Mock(); + mockAttachmentHandler1 = new Mock(); + mockAttachmentHandler2 = new Mock(); + mockEventsHandler = new Mock(); + + mockAttachmentHandler1.Setup(h => h.GetExtensionUri()).Returns(new Uri(uri1)); + mockAttachmentHandler2.Setup(h => h.GetExtensionUri()).Returns(new Uri(uri2)); + + manager = new MultiTestRunFinalizationManager(mockEventSource.Object, mockAttachmentHandler1.Object, mockAttachmentHandler2.Object); + + cancellationTokenSource = new CancellationTokenSource(); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturnNoAttachmentsThroughEventsHandler_IfNoAttachmentsOnInput() + { + // arrange + List inputAttachments = new List(); + + // act + await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + + // assert + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>(c => c.Count == 0))); + mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(0)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturnNoAttachments_IfNoAttachmentsOnInput() + { + // arrange + List inputAttachments = new List(); + + // act + var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + + // assert + Assert.AreEqual(0, result.Count); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(0)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachmentThroughEventsHandler_If1NotRelatedAttachmentOnInput() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri3), "uri3_input") + }; + + // act + await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + + // assert + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])))); + mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(1)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachment_If1NotRelatedAttachmentOnInput() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri3), "uri3_input") + }; + + // act + var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + + // assert + Assert.AreEqual(1, result.Count); + Assert.IsTrue(result.Contains(inputAttachments[0])); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(1)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachmentThroughEventsHandler_IfRelatedAttachmentOnInput() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input") + }; + + List outputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_output") + }; + + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns(outputAttachments); + + // act + await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + + // assert + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>(c => c.Count == 1 && c.Contains(outputAttachments[0])))); + mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(1)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachment_IfRelatedAttachmentOnInput() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input") + }; + + List outputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_output") + }; + + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns(outputAttachments); + + // act + var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + + // assert + Assert.AreEqual(1, result.Count); + Assert.IsTrue(result.Contains(outputAttachments[0])); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(1)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturnNullThroughEventsHandler_IfRelatedAttachmentOnInputButHandlerThrowsException() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input") + }; + + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Throws(new Exception("exception message")); + + // act + await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + + // assert + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(null)); + mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "exception message"), Times.Once); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfRelatedAttachmentOnInputButHandlerThrowsException() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input") + }; + + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Throws(new Exception("exception message")); + + // act + var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + + // assert + Assert.IsNull(result); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturnNullThroughEventsHandler_IfOperationIsCancelled() + { + // arrange + cancellationTokenSource.Cancel(); + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input") + }; + + // act + await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + + // assert + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(null)); + mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "The operation was canceled."), Times.Once); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfOperationIsCancelled() + { + // arrange + cancellationTokenSource.Cancel(); + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input") + }; + + // act + var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + + // assert + Assert.IsNull(result); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachmentsThroughEventsHandler_IfRelatedAttachmentsOnInput() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input1"), + new AttachmentSet(new Uri(uri1), "uri1_input2"), + new AttachmentSet(new Uri(uri2), "uri2_input1"), + new AttachmentSet(new Uri(uri2), "uri2_input2"), + new AttachmentSet(new Uri(uri3), "uri3_input1"), + }; + + List outputAttachmentsForHandler1 = new List + { + new AttachmentSet(new Uri(uri1), "uri1_output") + }; + + List outputAttachmentsForHandler2 = new List + { + new AttachmentSet(new Uri(uri2), "uri2_output") + }; + + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler1); + mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler2); + + // act + await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + + // assert + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>( + c => c.Count == 3 && + c.Contains(inputAttachments[4]) && + c.Contains(outputAttachmentsForHandler1.First()) && + c.Contains(outputAttachmentsForHandler2.First())))); + mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(5)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(3)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), cancellationTokenSource.Token)); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachments_IfRelatedAttachmentsOnInput() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input1"), + new AttachmentSet(new Uri(uri1), "uri1_input2"), + new AttachmentSet(new Uri(uri2), "uri2_input1"), + new AttachmentSet(new Uri(uri2), "uri2_input2"), + new AttachmentSet(new Uri(uri3), "uri3_input1"), + }; + + List outputAttachmentsForHandler1 = new List + { + new AttachmentSet(new Uri(uri1), "uri1_output") + }; + + List outputAttachmentsForHandler2 = new List + { + new AttachmentSet(new Uri(uri2), "uri2_output") + }; + + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler1); + mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler2); + + // act + var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + + // assert + Assert.AreEqual(3, result.Count); + Assert.IsTrue(result.Contains(inputAttachments[4])); + Assert.IsTrue(result.Contains(outputAttachmentsForHandler1[0])); + Assert.IsTrue(result.Contains(outputAttachmentsForHandler2[0])); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(5)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(3)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), cancellationTokenSource.Token)); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturnNullThroughEventsHandler_IfOperationCancelled() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input") + }; + + List outputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_output") + }; + + var innerTaskCompletionSource = new TaskCompletionSource(); + + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns((ICollection i1, CancellationToken cancellation) => + { + for (int i = 0; i < 1000; ++i) + { + Task.Delay(100); + Console.WriteLine($"Iteration: {i}"); + + if (cancellation.IsCancellationRequested) break; + + if (i == 3) + { + cancellationTokenSource.Cancel(); + } + } + + innerTaskCompletionSource.TrySetResult(null); + return outputAttachments; + }); + + // act + await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + Console.WriteLine("Finalization done"); + await innerTaskCompletionSource.Task; + + // assert + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(null)); + mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Informational, "Finalization was cancelled.")); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + } + + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfOperationCancelled() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input") + }; + + List outputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_output") + }; + + var innerTaskCompletionSource = new TaskCompletionSource(); + + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns((ICollection i1, CancellationToken cancellation) => + { + for (int i = 0; i < 1000; ++i) + { + Task.Delay(100); + Console.WriteLine($"Iteration: {i}"); + + if (cancellation.IsCancellationRequested) break; + + if (i == 3) + { + cancellationTokenSource.Cancel(); + } + } + + innerTaskCompletionSource.TrySetResult(null); + return outputAttachments; + }); + + // act + var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + Console.WriteLine("Finalization done"); + await innerTaskCompletionSource.Task; + + // assert + Assert.IsNull(result); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + } + } +} From e16e3ada63166ee36ca19e230ef601143bf5e332 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Mon, 15 Jun 2020 12:12:39 +0200 Subject: [PATCH 25/58] More changes --- .../Interfaces/Engine/IMultiTestRunFinalizationManager.cs | 1 - .../Client/Parallel/ParallelProxyExecutionManager.cs | 7 +++++++ .../DataCollection/ParallelDataCollectionEventsHandler.cs | 6 +++--- .../DataCollector/IDataCollectorAttachments.cs | 7 ++++++- .../CodeCoverageDataAttachmentsHandler.cs | 5 +++++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs index b09c6f9339..e91b1da0d3 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs @@ -26,7 +26,6 @@ internal interface IMultiTestRunFinalizationManager /// Finalizes multi test /// /// Attachments - /// EventHandler for handling multi test run finalization events from Engine /// Cancellation token Task> FinalizeMultiTestRunAsync(ICollection attachments, CancellationToken cancellationToken); } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs index 922541e63c..86df14a387 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs @@ -14,11 +14,14 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.Utilities; /// /// ParallelProxyExecutionManager that manages parallel execution @@ -258,12 +261,16 @@ private ParallelRunEventsHandler GetEventsHandler(IProxyExecutionManager concurr { var concurrentManagerWithDataCollection = concurrentManager as ProxyExecutionManagerWithDataCollection; + // TODO : use TestPluginCache to iterate over all IDataCollectorAttachments + var finalizationManager = new MultiTestRunFinalizationManager(TestPlatformEventSource.Instance, new CodeCoverageDataAttachmentsHandler()); + return new ParallelDataCollectionEventsHandler( this.requestData, concurrentManagerWithDataCollection, this.currentRunEventsHandler, this, this.currentRunDataAggregator, + finalizationManager, concurrentManagerWithDataCollection.CancellationToken); } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs index ed9d614743..c743622f2c 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs @@ -27,11 +27,11 @@ public ParallelDataCollectionEventsHandler(IRequestData requestData, ITestRunEventsHandler actualRunEventsHandler, IParallelProxyExecutionManager parallelProxyExecutionManager, ParallelRunDataAggregator runDataAggregator, + IMultiTestRunFinalizationManager finalizationManager, CancellationToken cancellationToken) : this(requestData, proxyExecutionManager, actualRunEventsHandler, parallelProxyExecutionManager, runDataAggregator, JsonDataSerializer.Instance) { - // TODO : use TestPluginCache to iterate over all IDataCollectorAttachments - this.finalizationManager = new MultiTestRunFinalizationManager(TestPlatformEventSource.Instance, new CodeCoverageDataAttachmentsHandler()); + this.finalizationManager = finalizationManager; this.cancellationToken = cancellationToken; } @@ -65,7 +65,7 @@ public override void HandleTestRunComplete( this.runDataAggregator.IsCanceled, this.runDataAggregator.IsAborted, this.runDataAggregator.GetAggregatedException(), - attachments, + attachments ?? runDataAggregator.RunContextAttachments, this.runDataAggregator.ElapsedTime); // Add Metrics from Test Host diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs index eff8238976..84df144523 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs @@ -12,12 +12,17 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection /// public interface IDataCollectorAttachments { + /// + /// Gets the attachment set after Test Run Session + /// + /// Gets the attachment set after Test Run Session + ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments); + /// /// Gets the attachment set after Test Run Session /// /// Gets the attachment set after Test Run Session ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, CancellationToken cancellationToken); - // TODO: add new method /// /// Gets the attachment Uri, which is handled by current Collector diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index f2ceeac7f2..395b8b2451 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -31,6 +31,11 @@ public Uri GetExtensionUri() return CodeCoverageDataCollectorUri; } + public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments) + { + return HandleDataCollectionAttachmentSets(dataCollectionAttachments, CancellationToken.None); + } + public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, CancellationToken cancellationToken) { if (dataCollectionAttachments != null && dataCollectionAttachments.Any()) From cbca05ad0a42a4f3367a6052ea7c539cd1c110d5 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Jun 2020 10:13:12 +0200 Subject: [PATCH 26/58] More tests --- .../Parallel/ParallelRunDataAggregator.cs | 2 +- .../ParallelDataCollectionEventsHandler.cs | 7 +- .../CodeCoverageDataAttachmentsHandler.cs | 8 -- .../VsTestConsoleWrapper.cs | 6 -- .../ParallelProxyExecutionManagerTests.cs | 27 ++++++ ...arallelDataCollectionEventsHandlerTests.cs | 95 +++++++++++++++++++ ...CodeCoverageDataAttachmentsHandlerTests.cs | 42 ++++++-- 7 files changed, 161 insertions(+), 26 deletions(-) create mode 100644 test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunDataAggregator.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunDataAggregator.cs index 2cc3d3c26c..b2d7f238b8 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunDataAggregator.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunDataAggregator.cs @@ -49,7 +49,7 @@ public ParallelRunDataAggregator() public TimeSpan ElapsedTime { get; set; } - public Collection RunContextAttachments { get; } + public Collection RunContextAttachments { get; set; } public List RunCompleteArgsAttachments { get; } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs index c743622f2c..0ac7a10312 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs @@ -8,13 +8,10 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection using System.Threading; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; - using Microsoft.VisualStudio.TestPlatform.Utilities; internal class ParallelDataCollectionEventsHandler : ParallelRunEventsHandler { @@ -59,13 +56,13 @@ public override void HandleTestRunComplete( if (parallelRunComplete) { - Collection attachments = finalizationManager.FinalizeMultiTestRunAsync(runDataAggregator.RunContextAttachments, cancellationToken).Result; + runDataAggregator.RunContextAttachments = finalizationManager.FinalizeMultiTestRunAsync(runDataAggregator.RunContextAttachments, cancellationToken).Result ?? runDataAggregator.RunContextAttachments; var completedArgs = new TestRunCompleteEventArgs(this.runDataAggregator.GetAggregatedRunStats(), this.runDataAggregator.IsCanceled, this.runDataAggregator.IsAborted, this.runDataAggregator.GetAggregatedException(), - attachments ?? runDataAggregator.RunContextAttachments, + runDataAggregator.RunContextAttachments, this.runDataAggregator.ElapsedTime); // Add Metrics from Test Host diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index 395b8b2451..3181c51476 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -100,14 +100,6 @@ private string MergeCodeCoverageFiles(IList files, CancellationToken can } throw; } - catch (ObjectDisposedException) - { - if (EqtTrace.IsWarningEnabled) - { - EqtTrace.Warning("CodeCoverageDataCollectorAttachmentsHandler: object disposed."); - } - throw; - } catch (Exception ex) { if (EqtTrace.IsErrorEnabled) diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index d5145f5f65..550f72330a 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -283,12 +283,6 @@ public Task FinalizeMultiTestRunAsync(ICollection attachments, IM return requestSender.FinalizeMultiTestRunAsync(attachments, testSessionEventsHandler, cancellationToken); } - /// - public void CancelMultiTestRunFinalization() - { - throw new System.NotImplementedException(); - } - #endregion private void EnsureInitialized() diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/Parallel/ParallelProxyExecutionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/Parallel/ParallelProxyExecutionManagerTests.cs index 9a7a439a80..78b7376bcf 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/Parallel/ParallelProxyExecutionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/Parallel/ParallelProxyExecutionManagerTests.cs @@ -15,6 +15,7 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.Client using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; 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.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; @@ -171,6 +172,32 @@ public void HandlePartialRunCompleteShouldCreateNewProxyExecutionManagerIfDataCo Assert.IsTrue(this.proxyManagerFuncCalled); } + [TestMethod] + public void HandlePartialRunCompleteShouldCreateNewProxyExecutionManagerIfDataCollectionEnabledAndCreatorWithDataCollection() + { + var completeArgs = new TestRunCompleteEventArgs(null, true, true, null, null, TimeSpan.Zero); + this.mockTestHostManager = new Mock(); + this.mockRequestSender = new Mock(); + this.mockDataCollectionManager = new Mock(); + var proxyDataCollectionManager = new ProxyExecutionManagerWithDataCollection(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.mockDataCollectionManager.Object); + var managers = new List>(); + this.proxyManagerFunc = () => + { + this.proxyManagerFuncCalled = true; + var manager = new Mock(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.mockDataCollectionManager.Object); + managers.Add(manager); + return manager.Object; + }; + var parallelExecutionManager = this.SetupExecutionManager(this.proxyManagerFunc, 2, setupTestCases: true); + + this.proxyManagerFuncCalled = false; + parallelExecutionManager.HandlePartialRunComplete(proxyDataCollectionManager, completeArgs, null, null, null); + Assert.IsTrue(this.proxyManagerFuncCalled); + + var handler = parallelExecutionManager.GetHandlerForGivenManager(managers.Last().Object); + Assert.IsTrue(handler is ParallelDataCollectionEventsHandler); + } + [TestMethod] public void HandlePartialRunCompleteShouldCreateNewProxyExecutionManagerIfIsAbortedIsTrue() { diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs new file mode 100644 index 0000000000..81bd9a7fe0 --- /dev/null +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs @@ -0,0 +1,95 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.TestPlatform.CrossPlatEngine.UnitTests.DataCollection +{ + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using Moq; + using System; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Threading; + using System.Threading.Tasks; + + [TestClass] + public class ParallelDataCollectionEventsHandlerTests + { + private const string uri1 = "datacollector://microsoft/some1/1.0"; + private const string uri2 = "datacollector://microsoft/some2/2.0"; + private const string uri3 = "datacollector://microsoft/some3/2.0"; + + private readonly Mock mockRequestData; + private readonly Mock mockProxyExecutionManager; + private readonly Mock mockTestRunEventsHandler; + private readonly Mock mockParallelProxyExecutionManager; + private readonly Mock mockMultiTestRunFinalizationManager; + private readonly CancellationTokenSource cancellationTokenSource; + private readonly ParallelDataCollectionEventsHandler parallelDataCollectionEventsHandler; + + public ParallelDataCollectionEventsHandlerTests() + { + mockRequestData = new Mock(); + mockProxyExecutionManager = new Mock(); + mockTestRunEventsHandler = new Mock(); + mockParallelProxyExecutionManager = new Mock(); + mockMultiTestRunFinalizationManager = new Mock(); + cancellationTokenSource = new CancellationTokenSource(); + parallelDataCollectionEventsHandler = new ParallelDataCollectionEventsHandler(mockRequestData.Object, mockProxyExecutionManager.Object, mockTestRunEventsHandler.Object, + mockParallelProxyExecutionManager.Object, new ParallelRunDataAggregator(), mockMultiTestRunFinalizationManager.Object, cancellationTokenSource.Token); + + mockParallelProxyExecutionManager.Setup(m => m.HandlePartialRunComplete(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>())).Returns(true); + } + + [TestMethod] + public void HandleTestRunComplete_ShouldCallFinalizerWithAttachmentsAndUseResults() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input1"), + new AttachmentSet(new Uri(uri2), "uri2_input1"), + new AttachmentSet(new Uri(uri3), "uri3_input1") + }; + + Collection outputAttachments = new Collection + { + new AttachmentSet(new Uri(uri1), "uri1_input1") + }; + + mockMultiTestRunFinalizationManager.Setup(f => f.FinalizeMultiTestRunAsync(It.IsAny>(), It.IsAny())).Returns(Task.FromResult(outputAttachments)); + + // act + parallelDataCollectionEventsHandler.HandleTestRunComplete(new TestRunCompleteEventArgs(null, false, false, null, null, TimeSpan.FromSeconds(1)), null, inputAttachments, null); + + // assert + mockTestRunEventsHandler.Verify(h => h.HandleTestRunComplete(It.IsAny(), It.IsAny(), It.Is>(c => c.Count == 1 && c.Contains(outputAttachments[0])), It.IsAny>())); + mockMultiTestRunFinalizationManager.Verify(f => f.FinalizeMultiTestRunAsync(It.Is>(a => a.Count == 3), cancellationTokenSource.Token)); + } + + [TestMethod] + public void HandleTestRunComplete_ShouldCallFinalizerWithAttachmentsAndNotUserResults_IfFinalizerReturnsNull() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input1"), + new AttachmentSet(new Uri(uri2), "uri2_input1"), + new AttachmentSet(new Uri(uri3), "uri3_input1") + }; + + mockMultiTestRunFinalizationManager.Setup(f => f.FinalizeMultiTestRunAsync(It.IsAny>(), It.IsAny())).Returns(Task.FromResult((Collection)null)); + + // act + parallelDataCollectionEventsHandler.HandleTestRunComplete(new TestRunCompleteEventArgs(null, false, false, null, null, TimeSpan.FromSeconds(1)), null, inputAttachments, null); + + // assert + mockTestRunEventsHandler.Verify(h => h.HandleTestRunComplete(It.IsAny(), It.IsAny(), It.Is>(c => c.Count == 3), It.IsAny>())); + mockMultiTestRunFinalizationManager.Verify(f => f.FinalizeMultiTestRunAsync(It.Is>(a => a.Count == 3), cancellationTokenSource.Token)); + } + } +} diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs index 9e55591dcb..915ad152b5 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs @@ -5,6 +5,7 @@ namespace Microsoft.TestPlatform.Utilities.UnitTests using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.Utilities; using Microsoft.VisualStudio.TestTools.UnitTesting; + using Moq; using System; using System.Collections.ObjectModel; using System.Threading; @@ -36,16 +37,45 @@ public void HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoAttachme } [TestMethod] - public void HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoCodeCoverageAttachments() + public void HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested() { - Collection attachment = new Collection(); var attachmentSet = new AttachmentSet(new Uri("//badrui//"), string.Empty); + attachmentSet.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\aa"), "coverage")); + CancellationTokenSource cts = new CancellationTokenSource(); + cts.Cancel(); - ICollection resultAttachmentSets = - coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, CancellationToken.None); + Collection attachment = new Collection + { + attachmentSet + }; - Assert.IsNotNull(resultAttachmentSets); - Assert.IsTrue(resultAttachmentSets.Count == 0); + Assert.ThrowsException(() => coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, cts.Token)); + + Assert.AreEqual(1, attachment.Count); + } + + [TestMethod] + public void HandleDataCollectionAttachmentSetsShouldReturnExistingAttachmentsIfFailedToLoadLibrary() + { + var attachmentSet1 = new AttachmentSet(new Uri("//badrui//"), string.Empty); + attachmentSet1.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\aa"), "coverage")); + + var attachmentSet2 = new AttachmentSet(new Uri("//badruj//"), string.Empty); + attachmentSet2.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\ab"), "coverage")); + + CancellationTokenSource cts = new CancellationTokenSource(); + + Collection attachment = new Collection + { + attachmentSet1, + attachmentSet2 + }; + + var result = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, cts.Token); + + Assert.AreEqual(2, result.Count); + Assert.IsTrue(result.Contains(attachmentSet1)); + Assert.IsTrue(result.Contains(attachmentSet2)); } } } From 31761757492a6580512eced31ecedbbfbae798e2 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Jun 2020 11:50:24 +0200 Subject: [PATCH 27/58] tests for reqeust sender --- .../VsTestConsoleRequestSender.cs | 1 - .../VsTestConsoleRequestSenderTests.cs | 167 ++++++++++++++++++ 2 files changed, 167 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index 5516f33c0b..b263203063 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -782,7 +782,6 @@ private async Task SendMessageAndListenAndReportFinalizationResultAsync(ICollect // Also, connection termination might not kill the process which could result in files being locked by testhost. } - // TODO: do we need events? this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStop(); } diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs index 457856254d..d3d45ca6a7 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs @@ -1899,6 +1899,173 @@ public async Task StartTestRunAsyncShouldLogErrorOnProcessExited() #endregion + #region Finalization Tests + + [TestMethod] + public async Task FinalizeTestsShouldCompleteWithZeroAttachments() + { + await this.InitializeCommunicationAsync(); + + var mockHandler = new Mock(); + + var payload = new MultiTestRunFinalizationCompletePayload() { Attachments = new AttachmentSet[0] }; + var finalizationComplete = new Message() + { + MessageType = MessageType.MultiTestRunFinalizationComplete, + Payload = JToken.FromObject(payload) + }; + this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete)); + + await this.requestSenderAsync.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, mockHandler.Object, CancellationToken.None); + + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is>(a => a.Count == 0)), Times.Once, "Discovery Complete must be called"); + mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never, "TestMessage event must not be called"); + } + + [TestMethod] + public async Task FinalizeTestsShouldCompleteWithOneAttachment() + { + await this.InitializeCommunicationAsync(); + + var mockHandler = new Mock(); + + var payload = new MultiTestRunFinalizationCompletePayload() + { + Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } + }; + var finalizationComplete = new Message() + { + MessageType = MessageType.MultiTestRunFinalizationComplete, + Payload = JToken.FromObject(payload) + }; + this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete)); + + await this.requestSenderAsync.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, mockHandler.Object, CancellationToken.None); + + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is>(a => a.Count == 1)), Times.Once, "Discovery Complete must be called"); + mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never, "TestMessage event must not be called"); + } + + [TestMethod] + public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndTestMessage() + { + await this.InitializeCommunicationAsync(); + + var mockHandler = new Mock(); + + var payload = new MultiTestRunFinalizationCompletePayload() + { + Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } + }; + var finalizationComplete = new Message() + { + MessageType = MessageType.MultiTestRunFinalizationComplete, + Payload = JToken.FromObject(payload) + }; + + var mpayload = new TestMessagePayload() { MessageLevel = TestMessageLevel.Informational, Message = "Hello" }; + var message = CreateMessage(MessageType.TestMessage, mpayload); + + this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(message)); + mockHandler.Setup(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny())).Callback( + () => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete))); + + await this.requestSenderAsync.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, mockHandler.Object, CancellationToken.None); + + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is>(a => a.Count == 1)), Times.Once, "Discovery Complete must be called"); + mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Once, "TestMessage event must be called"); + } + + [TestMethod] + public async Task FinalizeTestsShouldSendCancelMessageIfCancellationTokenCancelled() + { + await this.InitializeCommunicationAsync(); + + var cts = new CancellationTokenSource(); + + var mockHandler = new Mock(); + + var payload = new MultiTestRunFinalizationCompletePayload() + { + Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } + }; + var finalizationComplete = new Message() + { + MessageType = MessageType.MultiTestRunFinalizationComplete, + Payload = JToken.FromObject(payload) + }; + + var mpayload = new TestMessagePayload() { MessageLevel = TestMessageLevel.Informational, Message = "Hello" }; + var message = CreateMessage(MessageType.TestMessage, mpayload); + + this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(message)); + mockHandler.Setup(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny())).Callback(() => + { + cts.Cancel(); + this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete)); + }); + + await this.requestSenderAsync.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, mockHandler.Object, cts.Token); + + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel)); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is>(a => a.Count == 1)), Times.Once, "Discovery Complete must be called"); + mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Once, "TestMessage event must be called"); + } + + [TestMethod] + public async Task FinalizeTestsShouldSendCancelMessageIfCancellationTokenCancelledAtTheBeginning() + { + await this.InitializeCommunicationAsync(); + + var cts = new CancellationTokenSource(); + cts.Cancel(); + + var mockHandler = new Mock(); + + var payload = new MultiTestRunFinalizationCompletePayload() + { + Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } + }; + var finalizationComplete = new Message() + { + MessageType = MessageType.MultiTestRunFinalizationComplete, + Payload = JToken.FromObject(payload) + }; + + this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete)); + + await this.requestSenderAsync.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, mockHandler.Object, cts.Token); + + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel)); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is>(a => a.Count == 1)), Times.Once, "Discovery Complete must be called"); + mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Never, "TestMessage event must be called"); + } + + [TestMethod] + public async Task FinalizeTestsShouldAbortOnExceptionInSendMessage() + { + var mockHandler = new Mock(); + this.mockCommunicationManager.Setup(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())).Throws(new IOException()); + + await this.requestSenderAsync.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, mockHandler.Object, CancellationToken.None); + + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(null), Times.Once, "Discovery Complete must be called"); + mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Error, It.IsAny()), Times.Once, "TestMessage event must be called"); + this.mockCommunicationManager.Verify(cm => cm.StopServer(), Times.Never); + } + + #endregion + + + #region Private Methods /// From 89f7eed44b07ee07995aca7901473840a9369448 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Jun 2020 12:09:17 +0200 Subject: [PATCH 28/58] more tests --- .../VsTestConsoleWrapperAsyncTests.cs | 16 ++++++++++++++++ .../VsTestConsoleWrapperTests.cs | 17 +++++++++++++++++ .../TestRequestManagerTests.cs | 4 ++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs index d272a5753b..634bb7e1a4 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs @@ -5,6 +5,8 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests { using System; using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Threading; using System.Threading.Tasks; using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; @@ -302,6 +304,20 @@ await this.consoleWrapper.RunTestsWithCustomTestHostAsync( this.mockRequestSender.Verify(rs => rs.StartTestRunWithCustomHostAsync(this.testCases, "RunSettings", options, It.IsAny(), It.IsAny()), Times.Once); } + [TestMethod] + public async Task FinalizeMultiTestRunAsyncShouldSucceed() + { + var attachments = new Collection(); + var cancellationToken = new CancellationToken(); + + await this.consoleWrapper.FinalizeMultiTestRunAsync( + attachments, + new Mock().Object, + cancellationToken); + + this.mockRequestSender.Verify(rs => rs.FinalizeMultiTestRunAsync(attachments, It.IsAny(), cancellationToken)); + } + [TestMethod] public void EndSessionShouldSucceed() { diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs index 2691bb43c7..8b6797b7f4 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs @@ -13,7 +13,10 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests using Moq; using System; using System.Collections.Generic; + using System.Collections.ObjectModel; using System.Diagnostics; + using System.Threading; + using System.Threading.Tasks; [TestClass] public class VsTestConsoleWrapperTests @@ -303,6 +306,20 @@ public void RunTestsWithSelectedTestsAndOptionsUsingACustomHostShouldPassOnOptio this.mockRequestSender.Verify(rs => rs.StartTestRunWithCustomHost(this.testCases, "RunSettings", options, It.IsAny(), It.IsAny()), Times.Once); } + [TestMethod] + public async Task FinalizeMultiTestRunAsyncShouldSucceed() + { + var attachments = new Collection(); + var cancellationToken = new CancellationToken(); + + await this.consoleWrapper.FinalizeMultiTestRunAsync( + attachments, + new Mock().Object, + cancellationToken); + + this.mockRequestSender.Verify(rs => rs.FinalizeMultiTestRunAsync(attachments, It.IsAny(), cancellationToken)); + } + [TestMethod] public void EndSessionShouldSucceed() { diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index 02a16c39cc..d25ff4e616 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -81,6 +81,7 @@ public TestRequestManagerTests() this.mockMetricsPublisher = new Mock(); this.mockMetricsPublisherTask = Task.FromResult(this.mockMetricsPublisher.Object); + this.mockFinalizationManager = new Mock(); this.testRequestManager = new TestRequestManager( this.commandLineOptions, this.mockTestPlatform.Object, @@ -102,8 +103,7 @@ public TestRequestManagerTests() this.mockAssemblyMetadataProvider.Setup(a => a.GetFrameWork(It.IsAny())) .Returns(new FrameworkName(Constants.DotNetFramework40)); this.mockProcessHelper.Setup(x => x.GetCurrentProcessId()).Returns(1234); - this.mockProcessHelper.Setup(x => x.GetProcessName(It.IsAny())).Returns("dotnet.exe"); - this.mockFinalizationManager = new Mock(); + this.mockProcessHelper.Setup(x => x.GetProcessName(It.IsAny())).Returns("dotnet.exe"); } [TestCleanup] From 3c3c63136dce9a27d65047eb9ca0fe52b0052f89 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Jun 2020 14:12:05 +0200 Subject: [PATCH 29/58] Tests for cancelling --- .../TestRequestManagerTests.cs | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index d25ff4e616..95e18855bb 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -1,9 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; - namespace vstest.console.UnitTests.TestPlatformHelpers { using System; @@ -25,6 +22,7 @@ namespace vstest.console.UnitTests.TestPlatformHelpers using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Runtime.Versioning; @@ -2184,6 +2182,65 @@ public void DiscoverTestsShouldOverrideOnlyAssemblyNameIfConsoleLoggerAlreadyPre Assert.IsNotNull(loggerSettingsList[1].CodeBase); } + [TestMethod] + public void FinalizeMultiTestRunShouldSucceed() + { + var mockEventsHandler = new Mock(); + mockFinalizationManager + .Setup(m => m.FinalizeMultiTestRunAsync(It.IsAny>(), It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); + + var payload = new MultiTestRunFinalizationPayload() + { + Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } + }; + + testRequestManager.FinalizeMultiTestRun(payload, mockEventsHandler.Object); + + mockFinalizationManager.Verify(m => m.FinalizeMultiTestRunAsync(payload.Attachments, mockEventsHandler.Object, It.IsAny())); + mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStart()); + mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStop()); + } + + [TestMethod] + public async Task CancelMultiTestRunFinalizationShouldSucceedIfRequestInProgress() + { + var mockEventsHandler = new Mock(); + mockFinalizationManager + .Setup(m => m.FinalizeMultiTestRunAsync(It.IsAny>(), It.IsAny(), It.IsAny())) + .Returns((ICollection a, IMultiTestRunFinalizationEventsHandler h, CancellationToken token) => Task.Run(() => + { + int i = 0; + while (!token.IsCancellationRequested) + { + i++; + Console.WriteLine($"Iteration {i}"); + Task.Delay(5).Wait(); + } + })); + + var payload = new MultiTestRunFinalizationPayload() + { + Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } + }; + + Task task = Task.Run(() => testRequestManager.FinalizeMultiTestRun(payload, mockEventsHandler.Object)); + await Task.Delay(50); + testRequestManager.CancelMultiTestRunFinalization(); + + await task; + + mockFinalizationManager.Verify(m => m.FinalizeMultiTestRunAsync(payload.Attachments, mockEventsHandler.Object, It.IsAny())); + mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStart()); + mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStop()); + } + + [TestMethod] + public void CancelMultiTestRunFinalizationShouldSucceedIfNoRequest() + { + testRequestManager.CancelMultiTestRunFinalization(); + } + private static DiscoveryRequestPayload CreateDiscoveryPayload(string runsettings) { var discoveryPayload = new DiscoveryRequestPayload From eeb7963c4a64bfe2372b3b03213c9f1706ad45a7 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Jun 2020 18:07:29 +0200 Subject: [PATCH 30/58] Acceptance tests done --- .../CodeCoverageDataAttachmentsHandler.cs | 3 - .../CodeCoverageTests.cs | 313 ++++++++++++++++++ .../FinalizeMultiTestRunTests.cs | 249 -------------- 3 files changed, 313 insertions(+), 252 deletions(-) create mode 100644 test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs delete mode 100644 test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunTests.cs diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index 3181c51476..1ca310ceda 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -82,9 +82,6 @@ private string MergeCodeCoverageFiles(IList files, CancellationToken can cancellationToken.ThrowIfCancellationRequested(); File.Copy(fileName, outputfileName, true); - - cancellationToken.ThrowIfCancellationRequested(); - File.Delete(files[i]); } File.Delete(fileName); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs new file mode 100644 index 0000000000..b40538fc71 --- /dev/null +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -0,0 +1,313 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests +{ + using Microsoft.TestPlatform.TestUtilities; + using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using Moq; + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.IO; + using System.Linq; + using System.Net.Mail; + using System.Threading; + using System.Threading.Tasks; + using System.Xml; + using VisualStudio.TestPlatform.ObjectModel.Logging; + + /// + /// The Multi test run finalization tests using VsTestConsoleWrapper API's + /// + [TestClass] + public class CodeCoverageTests : AcceptanceTestBase + { + /* + * Below value is just safe coverage result for which all tests are passing. + * Inspecting this value gives us confidence that there is no big drop in overall coverage. + */ + private const double ExpectedMinimalModuleCoverage = 30.0; + + private IVsTestConsoleWrapper vstestConsoleWrapper; + private RunEventHandler runEventHandler; + private MultiTestRunFinalizationEventHandler multiTestRunFinalizationEventHandler; + + private void Setup() + { + this.vstestConsoleWrapper = this.GetVsTestConsoleWrapper(); + this.runEventHandler = new RunEventHandler(); + this.multiTestRunFinalizationEventHandler = new MultiTestRunFinalizationEventHandler(); + } + + [TestCleanup] + public void Cleanup() + { + this.vstestConsoleWrapper?.EndSession(); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void TestRunWithCodeCoverage(RunnerInfo runnerInfo) + { + // arrange + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + // act + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies(), this.GetCodeCoverageRunSettings(1), this.runEventHandler); + + // assert + Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + + int expectedNumberOfAttachments = testEnvironment.RunnerFramework.Equals(IntegrationTestBase.CoreRunnerFramework) && + testEnvironment.TargetFramework.Equals(IntegrationTestBase.CoreRunnerFramework) ? 2 : 1; + Assert.AreEqual(expectedNumberOfAttachments, this.runEventHandler.Attachments.Count); + + AssertCoverageResults(this.runEventHandler.Attachments); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void TestRunWithCodeCoverageParallel(RunnerInfo runnerInfo) + { + // arrange + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + // act + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies(), this.GetCodeCoverageRunSettings(4), this.runEventHandler); + + // assert + Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.runEventHandler.Attachments.Count); + + AssertCoverageResults(this.runEventHandler.Attachments); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) + { + // arrange + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(1), this.runEventHandler); + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(1), this.runEventHandler); + + Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + Assert.AreEqual(2, this.runEventHandler.Attachments.Count); + + // act + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, multiTestRunFinalizationEventHandler, CancellationToken.None); + + // Assert + multiTestRunFinalizationEventHandler.EnsureSuccess(); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.multiTestRunFinalizationEventHandler.Attachments.Count); + + AssertCoverageResults(this.multiTestRunFinalizationEventHandler.Attachments); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerInfo runnerInfo) + { + // arrange + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(1), this.runEventHandler); + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(1), this.runEventHandler); + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(1), this.runEventHandler); + + Assert.AreEqual(9, this.runEventHandler.TestResults.Count); + Assert.AreEqual(3, this.runEventHandler.Attachments.Count); + + // act + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, multiTestRunFinalizationEventHandler, CancellationToken.None); + + // Assert + multiTestRunFinalizationEventHandler.EnsureSuccess(); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 3, this.multiTestRunFinalizationEventHandler.Attachments.Count); + + AssertCoverageResults(this.multiTestRunFinalizationEventHandler.Attachments); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo runnerInfo) + { + // arrange + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(1), this.runEventHandler); + Assert.AreEqual(3, this.runEventHandler.TestResults.Count); + Assert.AreEqual(1, this.runEventHandler.Attachments.Count); + + List attachments = Enumerable.Range(0, 1000).Select(i => this.runEventHandler.Attachments.First()).ToList(); + + CancellationTokenSource cts = new CancellationTokenSource(); + + Task finalization = this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(attachments, multiTestRunFinalizationEventHandler, cts.Token); + await Task.Delay(TimeSpan.FromSeconds(1)); + + // act + cts.Cancel(); + + // Assert + await finalization; + multiTestRunFinalizationEventHandler.EnsureSuccess(); + + if(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework)) + { + Assert.AreEqual(0, this.multiTestRunFinalizationEventHandler.Attachments.Count); + } + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public async Task EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runnerInfo) + { + var numOfProcesses = Process.GetProcessesByName("vstest.console").Length; + + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(1), this.runEventHandler); + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(1), this.runEventHandler); + + Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + Assert.AreEqual(2, this.runEventHandler.Attachments.Count); + + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, multiTestRunFinalizationEventHandler, CancellationToken.None); + + // act + this.vstestConsoleWrapper?.EndSession(); + + // Assert + Assert.AreEqual(numOfProcesses, Process.GetProcessesByName("vstest.console").Length); + + this.vstestConsoleWrapper = null; + } + + private IList GetTestAssemblies() + { + return GetProjects().Select(p => this.GetAssetFullPath(p)).ToList(); + } + + private IList GetProjects() + { + return new List { "SimpleTestProject.dll", "SimpleTestProject2.dll" }; + } + + /// + /// Default RunSettings + /// + /// + public string GetCodeCoverageRunSettings(int cpuCount) + { + string runSettingsXml = $@" + + + {FrameworkArgValue} + {GetCodeCoveragePath()} + {cpuCount} + + + + + + + + + .*CPPUnitTestFramework.* + + + + + True + True + True + False + + + + + + "; + return runSettingsXml; + } + + private void AssertCoverageResults(IList attachments) + { + if (attachments.Count == 1) + { + var xmlCoverage = GetXmlCoverage(attachments.First()); + + foreach (var project in GetProjects()) + { + var moduleNode = GetModuleNode(xmlCoverage.DocumentElement, project.ToLower()); + AssertCoverage(moduleNode, ExpectedMinimalModuleCoverage); + } + } + } + + private XmlDocument GetXmlCoverage(AttachmentSet attachment) + { + string output = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); + + var analyze = Process.Start(new ProcessStartInfo + { + FileName = GetCodeCoverageExePath(), + Arguments = $"analyze /include_skipped_functions /include_skipped_modules /output:\"{output}\" \"{attachment.Attachments.First().Uri.LocalPath}\"", + RedirectStandardOutput = true + }); + + string analysisOutput = analyze.StandardOutput.ReadToEnd(); + + analyze.WaitForExit(); + Assert.IsTrue(0 == analyze.ExitCode, $"Code Coverage analyze failed: {analysisOutput}"); + + XmlDocument coverage = new XmlDocument(); + coverage.Load(output); + return coverage; + } + + private string GetCodeCoveragePath() + { + return Path.Combine(IntegrationTestEnvironment.TestPlatformRootDirectory, "artifacts", IntegrationTestEnvironment.BuildConfiguration, "Microsoft.CodeCoverage"); + } + + private string GetCodeCoverageExePath() + { + return Path.Combine(GetCodeCoveragePath(), "CodeCoverage", "CodeCoverage.exe"); + } + + private XmlNode GetModuleNode(XmlNode node, string name) + { + return GetNode(node, "module", name); + } + + private XmlNode GetNode(XmlNode node, string type, string name) + { + return node.SelectSingleNode($"//{type}[@name='{name}']"); + } + + private void AssertCoverage(XmlNode node, double expectedCoverage) + { + var coverage = double.Parse(node.Attributes["block_coverage"].Value); + Console.WriteLine($"Checking coverage for {node.Name} {node.Attributes["name"].Value}. Expected at least: {expectedCoverage}. Result: {coverage}"); + Assert.IsTrue(coverage > expectedCoverage, $"Coverage check failed for {node.Name} {node.Attributes["name"].Value}. Expected at least: {expectedCoverage}. Found: {coverage}"); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunTests.cs deleted file mode 100644 index 546d93efdc..0000000000 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunTests.cs +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests -{ - using Microsoft.TestPlatform.TestUtilities; - using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; - using Microsoft.VisualStudio.TestPlatform.Common.Telemetry; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.IO; - using System.Linq; - using System.Threading; - using System.Threading.Tasks; - using VisualStudio.TestPlatform.ObjectModel.Logging; - - /// - /// The Run Tests using VsTestConsoleWrapper API's - /// - [TestClass] - public class FinalizeMultiTestRunTests : AcceptanceTestBase - { - private IVsTestConsoleWrapper vstestConsoleWrapper; - private RunEventHandler runEventHandler; - private MultiTestRunFinalizationEventHandler multiTestRunFinalizationEventHandler; - - private void Setup() - { - this.vstestConsoleWrapper = this.GetVsTestConsoleWrapper(); - this.runEventHandler = new RunEventHandler(); - this.multiTestRunFinalizationEventHandler = new MultiTestRunFinalizationEventHandler(); - } - - [TestCleanup] - public void Cleanup() - { - this.vstestConsoleWrapper?.EndSession(); - } - - [TestMethod] - [NetFullTargetFrameworkDataSource] - [NetCoreTargetFrameworkDataSource] - public async Task FinalizeMultiTestRun(RunnerInfo runnerInfo) - { - AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); - this.Setup(); - - this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); - this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); - - Assert.AreEqual(6, this.runEventHandler.TestResults.Count); - Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, multiTestRunFinalizationEventHandler, CancellationToken.None); - - // Assert - multiTestRunFinalizationEventHandler.EnsureSuccess(); - Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.multiTestRunFinalizationEventHandler.Attachments.Count); - } - - [TestMethod] - [NetFullTargetFrameworkDataSource] - [NetCoreTargetFrameworkDataSource] - public async Task EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runnerInfo) - { - var numOfProcesses = Process.GetProcessesByName("vstest.console").Length; - - AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); - this.Setup(); - - this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); - this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); - - Assert.AreEqual(6, this.runEventHandler.TestResults.Count); - Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, multiTestRunFinalizationEventHandler, CancellationToken.None); - this.vstestConsoleWrapper?.EndSession(); - - // Assert - Assert.AreEqual(numOfProcesses, Process.GetProcessesByName("vstest.console").Length); - - this.vstestConsoleWrapper = null; - } - - [TestMethod] - [NetFullTargetFrameworkDataSource] - [NetCoreTargetFrameworkDataSource] - public void RunTestsWithTelemetryOptedIn(RunnerInfo runnerInfo) - { - AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); - this.Setup(); - - this.vstestConsoleWrapper.RunTests( - this.GetTestAssemblies(), - this.GetDefaultRunSettings(), - new TestPlatformOptions() { CollectMetrics = true }, - this.runEventHandler); - - // Assert - Assert.AreEqual(6, this.runEventHandler.TestResults.Count); - Assert.IsTrue(this.runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TargetDevice)); - Assert.IsTrue(this.runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TargetFramework)); - Assert.IsTrue(this.runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TargetOS)); - Assert.IsTrue(this.runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForRun)); - Assert.IsTrue(this.runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.NumberOfAdapterDiscoveredDuringExecution)); - Assert.IsTrue(this.runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.RunState)); - } - - [TestMethod] - [NetFullTargetFrameworkDataSource] - [NetCoreTargetFrameworkDataSource] - public void RunTestsWithTelemetryOptedOut(RunnerInfo runnerInfo) - { - AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); - this.Setup(); - - this.vstestConsoleWrapper.RunTests( - this.GetTestAssemblies(), - this.GetDefaultRunSettings(), - new TestPlatformOptions() { CollectMetrics = false }, - this.runEventHandler); - - // Assert - Assert.AreEqual(6, this.runEventHandler.TestResults.Count); - Assert.AreEqual(0, this.runEventHandler.Metrics.Count); - } - - [TestMethod] - [NetFullTargetFrameworkDataSource] - [NetCoreTargetFrameworkDataSource] - public void RunTestsShouldThrowOnStackOverflowException(RunnerInfo runnerInfo) - { - AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); - this.Setup(); - - if (IntegrationTestEnvironment.BuildConfiguration.Equals("release", StringComparison.OrdinalIgnoreCase)) - { - // On release, x64 builds, recursive calls may be replaced with loops (tail call optimization) - Assert.Inconclusive("On StackOverflowException testhost not exited in release configuration."); - return; - } - - var source = new[] { this.GetAssetFullPath("SimpleTestProject3.dll") }; - - this.vstestConsoleWrapper.RunTests( - source, - this.GetDefaultRunSettings(), - new TestPlatformOptions() { TestCaseFilter = "ExitWithStackoverFlow" }, - this.runEventHandler); - - var errorMessage = runnerInfo.TargetFramework == "net451" - ? "The active test run was aborted. Reason: Test host process crashed : Process is terminated due to StackOverflowException.\r\n" - : "The active test run was aborted. Reason: Test host process crashed : Process is terminating due to StackOverflowException.\r\n"; - - Assert.AreEqual(errorMessage, this.runEventHandler.LogMessage); - } - - [TestMethod] - [NetFullTargetFrameworkDataSource(useCoreRunner: false)] - [NetCoreTargetFrameworkDataSource(useCoreRunner: false)] - public void RunTestsShouldShowProperWarningOnNoTestsForTestCaseFilter(RunnerInfo runnerInfo) - { - AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); - this.Setup(); - - var testAssemblyName = "SimpleTestProject2.dll"; - var source = new List() { this.GetAssetFullPath(testAssemblyName) }; - - var veryLongTestCaseFilter = - "FullyQualifiedName=VeryLongTestCaseNameeeeeeeeeeeeee" + - "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + - "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + - "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + - "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; - - this.vstestConsoleWrapper.RunTests( - source, - this.GetDefaultRunSettings(), - new TestPlatformOptions() { TestCaseFilter = veryLongTestCaseFilter }, - this.runEventHandler); - - var expectedFilter = veryLongTestCaseFilter.Substring(0, 256) + "..."; - - // Assert - StringAssert.StartsWith(this.runEventHandler.LogMessage, $"No test matches the given testcase filter `{expectedFilter}` in"); - StringAssert.EndsWith(this.runEventHandler.LogMessage, testAssemblyName); - - Assert.AreEqual(TestMessageLevel.Warning, this.runEventHandler.TestMessageLevel); - } - - private IList GetTestAssemblies() - { - var testAssemblies = new List - { - this.GetAssetFullPath("SimpleTestProject.dll"), - this.GetAssetFullPath("SimpleTestProject2.dll") - }; - - return testAssemblies; - } - - /// - /// Default RunSettings - /// - /// - public string GetCodeCoverageRunSettings() - { - string traceDataCollectorDir = Path.Combine(IntegrationTestEnvironment.TestPlatformRootDirectory, $@"src\DataCollectors\TraceDataCollector\bin\{IntegrationTestEnvironment.BuildConfiguration}\netstandard2.0"); - if (this.testEnvironment.TargetFramework.Equals(IntegrationTestBase.DesktopRunnerFramework)) - { - traceDataCollectorDir = Path.Combine(IntegrationTestEnvironment.TestPlatformRootDirectory, $@"artifacts\{IntegrationTestEnvironment.BuildConfiguration}\Microsoft.CodeCoverage"); - } - - string runSettingsXml = $@" - - - {FrameworkArgValue} - {traceDataCollectorDir} - - - - - - - - - .*CPPUnitTestFramework.* - - - - - True - True - True - False - - - - - - "; - return runSettingsXml; - } - } -} \ No newline at end of file From bbb22441330de1b71d309fb104afe288a2f691de Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Jun 2020 18:08:15 +0200 Subject: [PATCH 31/58] Remove not used stuff --- .../TranslationLayerTests/CodeCoverageTests.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs index b40538fc71..21059e755c 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -7,17 +7,14 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; - using Moq; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; - using System.Net.Mail; using System.Threading; using System.Threading.Tasks; using System.Xml; - using VisualStudio.TestPlatform.ObjectModel.Logging; /// /// The Multi test run finalization tests using VsTestConsoleWrapper API's From 4d61a921cc3f58df8d1bd07600a5cc5d9d4aca91 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Jun 2020 18:30:23 +0200 Subject: [PATCH 32/58] Fix comments --- .../MultiTestRunFinalizationEventsHandler.cs | 12 +++++------- .../Engine/IMultiTestRunFinalizationManager.cs | 9 +++++---- .../Tracing/Interfaces/ITestPlatformEventSource.cs | 12 ++++++------ .../Tracing/TestPlatformEventSource.cs | 8 ++++---- .../MultiTestRunFinalizationManager.cs | 10 +++++----- .../Payloads/MultiTestRunFinalizationPayload.cs | 2 +- .../Interfaces/ITranslationLayerRequestSender.cs | 4 ++-- .../ITranslationLayerRequestSenderAsync.cs | 4 ++-- .../Interfaces/IVsTestConsoleWrapper.cs | 4 ++-- .../Interfaces/IVsTestConsoleWrapperAsync.cs | 4 ++-- .../VsTestConsoleRequestSender.cs | 2 +- .../TestPlatformHelpers/TestRequestManager.cs | 12 ++---------- .../Utility/ConverterTests.cs | 2 +- 13 files changed, 38 insertions(+), 47 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs index 78cc89e1be..cc9c7cbcab 100644 --- a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs @@ -11,7 +11,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization using System.Collections.Generic; /// - /// The multi test finalization event handler. + /// The multi test finalization events handler. /// public class MultiTestRunFinalizationEventsHandler : IMultiTestRunFinalizationEventsHandler { @@ -20,23 +20,20 @@ public class MultiTestRunFinalizationEventsHandler : IMultiTestRunFinalizationEv /// /// Initializes a new instance of the class. /// - /// The Request Handler. + /// The communication manager. public MultiTestRunFinalizationEventsHandler(ICommunicationManager communicationManager) { this.communicationManager = communicationManager; } - /// - /// The handle discovery message. - /// - /// Logging level. - /// Logging message. + /// public void HandleLogMessage(TestMessageLevel level, string message) { var testMessagePayload = new TestMessagePayload { MessageLevel = level, Message = message }; this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); } + /// public void HandleMultiTestRunFinalizationComplete(ICollection attachments) { if (EqtTrace.IsInfoEnabled) @@ -53,6 +50,7 @@ public void HandleMultiTestRunFinalizationComplete(ICollection at this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationComplete, payload); } + /// public void HandleRawMessage(string rawMessage) { // No-Op diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs index e91b1da0d3..078bc1349f 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs @@ -17,16 +17,17 @@ internal interface IMultiTestRunFinalizationManager /// /// Finalizes multi test run and provides results through handler /// - /// Attachments - /// EventHandler for handling multi test run finalization events from Engine + /// Collection of attachments + /// EventHandler for handling multi test run finalization event /// Cancellation token Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken); /// - /// Finalizes multi test + /// Finalizes multi test run /// - /// Attachments + /// Collection of attachments /// Cancellation token + /// Collection of attachments. Task> FinalizeMultiTestRunAsync(ICollection attachments, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs index a287b0cf6d..262803cf48 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs @@ -196,18 +196,18 @@ public interface ITestPlatformEventSource /// /// The multi test run finalization start. /// - /// - /// The number of attachements. + /// + /// The number of attachments. /// - void MultiTestRunFinalizationStart(long numberOfAttachements); + void MultiTestRunFinalizationStart(long numberOfAttachments); /// /// The multi test run finalization stop. /// - /// - /// The number of attachements. + /// + /// The number of attachments. /// - void MultiTestRunFinalizationStop(long numberOfAttachements); + void MultiTestRunFinalizationStop(long numberOfAttachments); /// /// Mark the start of translation layer multi test run finalization request. diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs index 7cda495578..cf7a4f5845 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs @@ -254,16 +254,16 @@ public void MultiTestRunFinalizationRequestStop() /// [Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId)] - public void MultiTestRunFinalizationStart(long numberOfAttachements) + public void MultiTestRunFinalizationStart(long numberOfAttachments) { - this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId, numberOfAttachements); + this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId, numberOfAttachments); } /// [Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStopEventId)] - public void MultiTestRunFinalizationStop(long numberOfAttachements) + public void MultiTestRunFinalizationStop(long numberOfAttachments) { - this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStopEventId, numberOfAttachements); + this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStopEventId, numberOfAttachments); } /// diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index 2eb388eeeb..23bb2d463b 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -16,7 +16,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization { /// - /// Orchestrates multi test run finalization operations for the engine communicating with the test host process. + /// Orchestrates multi test run finalization operations. /// public class MultiTestRunFinalizationManager : IMultiTestRunFinalizationManager { @@ -60,7 +60,7 @@ private async Task> InternalFinalizeMultiTestRunAsync( Task task = Task.Run(() => { - HandleAttachements(attachments, cancellationToken); + HandleAttachments(attachments, cancellationToken); }); var completedTask = await Task.WhenAny(task, taskCompletionSource.Task); @@ -92,7 +92,7 @@ private async Task> InternalFinalizeMultiTestRunAsync( } } - private void HandleAttachements(ICollection attachments, CancellationToken cancellationToken) + private void HandleAttachments(ICollection attachments, CancellationToken cancellationToken) { foreach (var dataCollectorAttachmentsHandler in dataCollectorAttachmentsHandlers) { @@ -107,8 +107,8 @@ private void HandleAttachements(ICollection attachments, Cancella attachments.Remove(attachment); } - ICollection processedAttachements = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), cancellationToken); - foreach (var attachment in processedAttachements) + ICollection processedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), cancellationToken); + foreach (var attachment in processedAttachments) { attachments.Add(attachment); } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs index 5066f0e3a9..13f7cfc229 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs @@ -12,7 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client public class MultiTestRunFinalizationPayload { /// - /// Settings used for the discovery request. + /// Collection of attachments. /// [DataMember] public ICollection Attachments { get; set; } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs index 224edbe0aa..45519affa7 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs @@ -113,9 +113,9 @@ internal interface ITranslationLayerRequestSender : IDisposable void CancelDiscovery(); /// - /// Provides back all attachements to TestPlatform for additional processing (for example merging) + /// Provides back all attachments to TestPlatform for additional processing (for example merging) /// - /// List of attachements + /// Collection of attachments /// Events handler /// Cancellation token Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs index babfee4518..0bf4ce0a82 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs @@ -79,9 +79,9 @@ internal interface ITranslationLayerRequestSenderAsync : IDisposable void OnProcessExited(); /// - /// Provides back all attachements to TestPlatform for additional processing (for example merging) + /// Provides back all attachments to TestPlatform for additional processing (for example merging) /// - /// List of attachements + /// Collection of attachments /// Events handler /// Cancellation token Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs index acc2ab836b..d9b86dac3a 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs @@ -121,9 +121,9 @@ public interface IVsTestConsoleWrapper void RunTestsWithCustomTestHost(IEnumerable testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); /// - /// Provides back all attachements to TestPlatform for additional processing (for example merging) + /// Provides back all attachments to TestPlatform for additional processing (for example merging) /// - /// List of attachements + /// Collection of attachments /// EventHandler to receive session complete event /// Cancellation token Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs index d3b705150b..3e6cabe3b8 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs @@ -83,9 +83,9 @@ public interface IVsTestConsoleWrapperAsync Task RunTestsWithCustomTestHostAsync(IEnumerable testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); /// - /// Provides back all attachements to TestPlatform for additional processing (for example merging) + /// Provides back all attachments to TestPlatform for additional processing (for example merging) /// - /// List of attachements + /// Collection of attachments /// EventHandler to receive session complete event /// Cancellation token Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index b263203063..c32e28bfa5 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -755,7 +755,7 @@ private async Task SendMessageAndListenAndReportFinalizationResultAsync(ICollect { if (EqtTrace.IsInfoEnabled) { - EqtTrace.Info("VsTestConsoleRequestSender.SendMessageAndListenAndReportAttachements: Process complete."); + EqtTrace.Info("VsTestConsoleRequestSender.SendMessageAndListenAndReportAttachments: Process complete."); } var multiTestRunFinalizationCompletePayload = this.dataSerializer.DeserializePayload(message); diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 5ef58e6190..d38cc6cd0e 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -312,13 +312,7 @@ public void RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc } } - /// - /// Discover Tests given a list of sources, run settings. - /// - /// Discovery payload - /// EventHandler for discovered tests - /// Protocol related information - /// True, if successful + /// public void FinalizeMultiTestRun(MultiTestRunFinalizationPayload finalizationPayload, IMultiTestRunFinalizationEventsHandler finalizationEventsHandler) { EqtTrace.Info("TestRequestManager.FinalizeMultiTestRun: Multi test run finalization started."); @@ -392,9 +386,7 @@ public void AbortTestRun() this.currentTestRunRequest?.Abort(); } - /// - /// Cancel the multi test run finalization. - /// + /// public void CancelMultiTestRunFinalization() { EqtTrace.Info("TestRequestManager.CancelMultiTestRunFinalization: Sending cancel request."); diff --git a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs index 8d1e341c9e..1734b9c15d 100644 --- a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs +++ b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs @@ -145,7 +145,7 @@ public void ToTestElementShouldContainExpectedTestMethodPropertiesIfFqnDoesNotEn } [TestMethod] - public void ToResultFilesShouldAddAttachementsWithRelativeURI() + public void ToResultFilesShouldAddAttachmentsWithRelativeURI() { UriDataAttachment uriDataAttachment1 = new UriDataAttachment(new Uri($"/mnt/c/abc.txt", UriKind.Relative), "Description 1"); From 11908955ca7a09035dd3a6ddc7ab3e2273edc904 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Jun 2020 19:23:06 +0200 Subject: [PATCH 33/58] Fix race condition in test --- .../DesignMode/DesignModeClientTests.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs index e34ec2335c..4c8c962e92 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs @@ -460,8 +460,16 @@ public void DesignModeClientConnectShouldCallRequestManagerForFinalizationStart( this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startFinalization); + this.mockTestRequestManager + .Setup( + rm => rm.FinalizeMultiTestRun( + It.IsAny(), + It.IsAny())) + .Callback(() => complateEvent.Set()); + this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); + Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "Finalization not completed."); this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Never); this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny()), Times.Never); this.mockTestRequestManager.Verify(rm => rm.FinalizeMultiTestRun(It.IsAny(), It.IsAny())); From 82bb3dec8fb1eff8cc0c9c06557674eaf5b5c4a1 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Jun 2020 21:15:56 +0200 Subject: [PATCH 34/58] Fix another race condition --- .../MultiTestRunFinalizationManagerTests.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs index 5a681f38c4..094d26fa05 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs @@ -392,20 +392,27 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNullThroughEventsHandler mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns((ICollection i1, CancellationToken cancellation) => { - for (int i = 0; i < 1000; ++i) - { - Task.Delay(100); - Console.WriteLine($"Iteration: {i}"); + try + { + for (int i = 0; i < 1000; ++i) + { + Task.Delay(100).Wait(); + Console.WriteLine($"Iteration: {i}"); - if (cancellation.IsCancellationRequested) break; + cancellation.ThrowIfCancellationRequested(); - if (i == 3) - { - cancellationTokenSource.Cancel(); + if (i == 3) + { + cancellationTokenSource.Cancel(); + Task.Delay(500).Wait(); + } } } - - innerTaskCompletionSource.TrySetResult(null); + finally + { + innerTaskCompletionSource.TrySetResult(null); + } + return outputAttachments; }); From 9376adbe5aff4c169fd3ac5497746d96dd5f1d46 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Jun 2020 22:25:05 +0200 Subject: [PATCH 35/58] Fix converting to xml --- .../TranslationLayerTests/CodeCoverageTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs index 21059e755c..aab70e6843 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -267,7 +267,8 @@ private XmlDocument GetXmlCoverage(AttachmentSet attachment) { FileName = GetCodeCoverageExePath(), Arguments = $"analyze /include_skipped_functions /include_skipped_modules /output:\"{output}\" \"{attachment.Attachments.First().Uri.LocalPath}\"", - RedirectStandardOutput = true + RedirectStandardOutput = true, + UseShellExecute = false }); string analysisOutput = analyze.StandardOutput.ReadToEnd(); From be9537ba5109bfe993ac913717f700725555f0fe Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Jun 2020 23:04:08 +0200 Subject: [PATCH 36/58] fix next test --- .../MultiTestRunFinalizationManagerTests.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs index 094d26fa05..ae911a6feb 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs @@ -452,14 +452,15 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfOperationCancelle { for (int i = 0; i < 1000; ++i) { - Task.Delay(100); + Task.Delay(100).Wait(); Console.WriteLine($"Iteration: {i}"); - if (cancellation.IsCancellationRequested) break; + cancellation.ThrowIfCancellationRequested(); if (i == 3) - { + { cancellationTokenSource.Cancel(); + Task.Delay(500).Wait(); } } From f157e24022375ce2fdb8d2ac8eca827694d9f941 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Jun 2020 23:45:42 +0200 Subject: [PATCH 37/58] fix test --- .../MultiTestRunFinalizationManagerTests.cs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs index ae911a6feb..e3d0f106f9 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs @@ -450,21 +450,27 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfOperationCancelle mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns((ICollection i1, CancellationToken cancellation) => { - for (int i = 0; i < 1000; ++i) + try { - Task.Delay(100).Wait(); - Console.WriteLine($"Iteration: {i}"); + for (int i = 0; i < 1000; ++i) + { + Task.Delay(100).Wait(); + Console.WriteLine($"Iteration: {i}"); - cancellation.ThrowIfCancellationRequested(); + cancellation.ThrowIfCancellationRequested(); - if (i == 3) - { - cancellationTokenSource.Cancel(); - Task.Delay(500).Wait(); + if (i == 3) + { + cancellationTokenSource.Cancel(); + Task.Delay(500).Wait(); + } } } + finally + { + innerTaskCompletionSource.TrySetResult(null); + } - innerTaskCompletionSource.TrySetResult(null); return outputAttachments; }); From b25a64ee20daec2e9724f0acacd88a99e98d76b8 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Wed, 17 Jun 2020 09:33:22 +0200 Subject: [PATCH 38/58] Next changes --- .../MultiTestRunFinalizationManager.cs | 42 +++++++++---------- .../VsTestConsoleRequestSender.cs | 41 +++++++++--------- .../VsTestConsoleWrapperAsync.cs | 4 +- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index 23bb2d463b..f3a0188771 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -35,7 +35,7 @@ public MultiTestRunFinalizationManager(ITestPlatformEventSource testPlatformEven /// public async Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) { - await InternalFinalizeMultiTestRunAsync(new Collection(attachments.ToList()), eventHandler, cancellationToken); + await InternalFinalizeMultiTestRunAsync(new Collection(attachments.ToList()), eventHandler, cancellationToken).ConfigureAwait(false); } /// @@ -53,30 +53,28 @@ private async Task> InternalFinalizeMultiTestRunAsync( cancellationToken.ThrowIfCancellationRequested(); var taskCompletionSource = new TaskCompletionSource(); - cancellationToken.Register(() => + using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled())) { - taskCompletionSource.TrySetCanceled(); - }); - - Task task = Task.Run(() => - { - HandleAttachments(attachments, cancellationToken); - }); + Task task = Task.Run(() => + { + HandleAttachments(attachments, cancellationToken); + }); - var completedTask = await Task.WhenAny(task, taskCompletionSource.Task); + var completedTask = await Task.WhenAny(task, taskCompletionSource.Task).ConfigureAwait(false); - if (completedTask == task) - { - await task; - eventHandler?.HandleMultiTestRunFinalizationComplete(attachments); - testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); - return attachments; - } - else - { - eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Informational, "Finalization was cancelled."); - eventHandler?.HandleMultiTestRunFinalizationComplete(null); - testPlatformEventSource.MultiTestRunFinalizationStop(0); + if (completedTask == task) + { + await task; + eventHandler?.HandleMultiTestRunFinalizationComplete(attachments); + testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); + return attachments; + } + else + { + eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Informational, "Finalization was cancelled."); + eventHandler?.HandleMultiTestRunFinalizationComplete(null); + testPlatformEventSource.MultiTestRunFinalizationStop(0); + } } return null; diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index c32e28bfa5..69589fe187 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -742,31 +742,32 @@ private async Task SendMessageAndListenAndReportFinalizationResultAsync(ICollect this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationStart, payload); var isMultiTestRunFinalizationComplete = false; - cancellationToken.Register(() => this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationCancel)); - - // Cycle through the messages that the vstest.console sends. - // Currently each of the operations are not separate tasks since they should not each take much time. - // This is just a notification. - while (!isMultiTestRunFinalizationComplete) + using (cancellationToken.Register(() => this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationCancel))) { - var message = await this.TryReceiveMessageAsync(); - - if (string.Equals(MessageType.MultiTestRunFinalizationComplete, message.MessageType)) + // Cycle through the messages that the vstest.console sends. + // Currently each of the operations are not separate tasks since they should not each take much time. + // This is just a notification. + while (!isMultiTestRunFinalizationComplete) { - if (EqtTrace.IsInfoEnabled) + var message = await this.TryReceiveMessageAsync().ConfigureAwait(false); + + if (string.Equals(MessageType.MultiTestRunFinalizationComplete, message.MessageType)) { - EqtTrace.Info("VsTestConsoleRequestSender.SendMessageAndListenAndReportAttachments: Process complete."); - } + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("VsTestConsoleRequestSender.SendMessageAndListenAndReportAttachments: Process complete."); + } - var multiTestRunFinalizationCompletePayload = this.dataSerializer.DeserializePayload(message); + var multiTestRunFinalizationCompletePayload = this.dataSerializer.DeserializePayload(message); - eventHandler.HandleMultiTestRunFinalizationComplete(multiTestRunFinalizationCompletePayload.Attachments); - isMultiTestRunFinalizationComplete = true; - } - else if (string.Equals(MessageType.TestMessage, message.MessageType)) - { - var testMessagePayload = this.dataSerializer.DeserializePayload(message); - eventHandler.HandleLogMessage(testMessagePayload.MessageLevel, testMessagePayload.Message); + eventHandler.HandleMultiTestRunFinalizationComplete(multiTestRunFinalizationCompletePayload.Attachments); + isMultiTestRunFinalizationComplete = true; + } + else if (string.Equals(MessageType.TestMessage, message.MessageType)) + { + var testMessagePayload = this.dataSerializer.DeserializePayload(message); + eventHandler.HandleLogMessage(testMessagePayload.MessageLevel, testMessagePayload.Message); + } } } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs index fc0f9a40fe..0a0aaf829f 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs @@ -228,8 +228,8 @@ public async Task FinalizeMultiTestRunAsync(ICollection attachmen { this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStart(); - await this.EnsureInitializedAsync(); - await requestSender.FinalizeMultiTestRunAsync(attachments, testSessionEventsHandler, cancellationToken); + await this.EnsureInitializedAsync().ConfigureAwait(false); + await requestSender.FinalizeMultiTestRunAsync(attachments, testSessionEventsHandler, cancellationToken).ConfigureAwait(false); } /// From fc7a1c0bd3278100a7174bf0858ea96a42971430 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Fri, 19 Jun 2020 12:20:11 +0200 Subject: [PATCH 39/58] Review changes #1 --- .../DesignMode/DesignModeClient.cs | 2 +- .../RequestHelper/ITestRequestManager.cs | 2 +- .../IMultiTestRunFinalizationManager.cs | 4 +- .../Telemetry/TelemetryDataConstants.cs | 10 + .../Parallel/ParallelRunEventsHandler.cs | 2 +- .../ParallelDataCollectionEventsHandler.cs | 2 +- .../MultiTestRunFinalizationManager.cs | 97 +++++-- .../MultiTestRunFinalizationPayload.cs | 8 +- .../IDataCollectorAttachments.cs | 5 +- .../CodeCoverageDataAttachmentsHandler.cs | 12 +- .../ITranslationLayerRequestSender.cs | 10 +- .../ITranslationLayerRequestSenderAsync.cs | 33 +-- .../Interfaces/IVsTestConsoleWrapper.cs | 12 +- .../Interfaces/IVsTestConsoleWrapperAsync.cs | 25 +- .../VsTestConsoleRequestSender.cs | 18 +- .../VsTestConsoleWrapper.cs | 161 ++++++++++- .../VsTestConsoleWrapperAsync.cs | 269 ------------------ .../TestPlatformHelpers/TestRequestManager.cs | 10 +- .../CodeCoverageTests.cs | 8 +- .../DesignMode/DesignModeClientTests.cs | 11 +- ...arallelDataCollectionEventsHandlerTests.cs | 8 +- ...CodeCoverageDataAttachmentsHandlerTests.cs | 23 +- .../VsTestConsoleRequestSenderTests.cs | 78 +++-- .../VsTestConsoleWrapperAsyncTests.cs | 18 +- .../VsTestConsoleWrapperTests.cs | 3 +- .../TestRequestManagerTests.cs | 43 ++- 26 files changed, 403 insertions(+), 471 deletions(-) delete mode 100644 src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index f83ff7d0bc..d49af32336 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -479,7 +479,7 @@ private void StartMultiTestRunFinalization(MultiTestRunFinalizationPayload final { try { - testRequestManager.FinalizeMultiTestRun(finalizationPayload, new MultiTestRunFinalizationEventsHandler(this.communicationManager)); + testRequestManager.FinalizeMultiTestRun(finalizationPayload, new MultiTestRunFinalizationEventsHandler(this.communicationManager), this.protocolConfig); } catch (Exception ex) { diff --git a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs index 380484ab7f..eb18c4fa0b 100644 --- a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs +++ b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs @@ -49,7 +49,7 @@ public interface ITestRequestManager : IDisposable /// /// Multi test run finalization payload /// Multi test run finalization events handler - void FinalizeMultiTestRun(MultiTestRunFinalizationPayload multiTestRunFinalizationPayload, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationEventsHandler); + void FinalizeMultiTestRun(MultiTestRunFinalizationPayload multiTestRunFinalizationPayload, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationEventsHandler, ProtocolConfig protocolConfig); /// /// Cancel the current TestRun request diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs index 078bc1349f..d13ea35f71 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs @@ -20,7 +20,7 @@ internal interface IMultiTestRunFinalizationManager /// Collection of attachments /// EventHandler for handling multi test run finalization event /// Cancellation token - Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken); + Task FinalizeMultiTestRunAsync(IRequestData requestData, IEnumerable attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken); /// /// Finalizes multi test run @@ -28,6 +28,6 @@ internal interface IMultiTestRunFinalizationManager /// Collection of attachments /// Cancellation token /// Collection of attachments. - Task> FinalizeMultiTestRunAsync(ICollection attachments, CancellationToken cancellationToken); + Task> FinalizeMultiTestRunAsync(IRequestData requestData, IEnumerable attachments, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.Common/Telemetry/TelemetryDataConstants.cs b/src/Microsoft.TestPlatform.Common/Telemetry/TelemetryDataConstants.cs index b7a277e1e1..671350a63e 100644 --- a/src/Microsoft.TestPlatform.Common/Telemetry/TelemetryDataConstants.cs +++ b/src/Microsoft.TestPlatform.Common/Telemetry/TelemetryDataConstants.cs @@ -90,9 +90,19 @@ public static class TelemetryDataConstants public static string NumberOfAdapterUsedToDiscoverTests = "VS.TestDiscovery.AdaptersUsedCount"; + // *********************Finalization**************************** + public static string NumberOfAttachmentsSentForFinalization = "VS.TestFinalization.InitialAttachmentsCount"; + + public static string NumberOfAttachmentsAfterFinalization = "VS.TestFinalization.FinalAttachmentsCount"; + + public static string TimeTakenInSecForFinalization = "VS.TestFinalization.TotalTimeTakenInSec"; + public static string FinalizationState = "VS.TestFinalization.FinalizationState"; + // **************Events Name ********************************** public static string TestDiscoveryCompleteEvent = "vs/testplatform/testdiscoverysession"; public static string TestExecutionCompleteEvent = "vs/testplatform/testrunsession"; + + public static string TestFinalizationCompleteEvent = "vs/testplatform/testfinalizationsession"; } } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunEventsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunEventsHandler.cs index bacf1da410..5a66d9528e 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunEventsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunEventsHandler.cs @@ -31,7 +31,7 @@ internal class ParallelRunEventsHandler : ITestRunEventsHandler2 private IDataSerializer dataSerializer; - private IRequestData requestData; + protected IRequestData requestData; public ParallelRunEventsHandler(IRequestData requestData, IProxyExecutionManager proxyExecutionManager, diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs index 0ac7a10312..f6c2ea0829 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs @@ -56,7 +56,7 @@ public override void HandleTestRunComplete( if (parallelRunComplete) { - runDataAggregator.RunContextAttachments = finalizationManager.FinalizeMultiTestRunAsync(runDataAggregator.RunContextAttachments, cancellationToken).Result ?? runDataAggregator.RunContextAttachments; + runDataAggregator.RunContextAttachments = finalizationManager.FinalizeMultiTestRunAsync(requestData, runDataAggregator.RunContextAttachments, cancellationToken).Result ?? runDataAggregator.RunContextAttachments; var completedArgs = new TestRunCompleteEventArgs(this.runDataAggregator.GetAggregatedRunStats(), this.runDataAggregator.IsCanceled, diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index f3a0188771..4bb4818ee9 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -4,9 +4,11 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestPlatform.Common.Telemetry; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; @@ -20,6 +22,10 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinali /// public class MultiTestRunFinalizationManager : IMultiTestRunFinalizationManager { + private static string FinalizationCompleted = "Completed"; + private static string FinalizationCanceled = "Canceled"; + private static string FinalizationFailed = "Failed"; + private readonly ITestPlatformEventSource testPlatformEventSource; private readonly IDataCollectorAttachments[] dataCollectorAttachmentsHandlers; @@ -33,65 +39,74 @@ public MultiTestRunFinalizationManager(ITestPlatformEventSource testPlatformEven } /// - public async Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) + public async Task FinalizeMultiTestRunAsync(IRequestData requestData, IEnumerable attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) { - await InternalFinalizeMultiTestRunAsync(new Collection(attachments.ToList()), eventHandler, cancellationToken).ConfigureAwait(false); + await InternalFinalizeMultiTestRunAsync(requestData, new Collection(attachments.ToList()), eventHandler, cancellationToken).ConfigureAwait(false); } - /// - public Task> FinalizeMultiTestRunAsync(ICollection attachments, CancellationToken cancellationToken) + public Task> FinalizeMultiTestRunAsync(IRequestData requestData, IEnumerable attachments, CancellationToken cancellationToken) { - return InternalFinalizeMultiTestRunAsync(new Collection(attachments.ToList()), null, cancellationToken); + return InternalFinalizeMultiTestRunAsync(requestData, new Collection(attachments.ToList()), null, cancellationToken); } - private async Task> InternalFinalizeMultiTestRunAsync(Collection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) + private async Task> InternalFinalizeMultiTestRunAsync(IRequestData requestData, Collection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) { + Stopwatch stopwatch = Stopwatch.StartNew(); + try { testPlatformEventSource.MultiTestRunFinalizationStart(attachments?.Count ?? 0); - + requestData.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsSentForFinalization, attachments?.Count ?? 0); + cancellationToken.ThrowIfCancellationRequested(); - var taskCompletionSource = new TaskCompletionSource(); + var taskCompletionSource = new TaskCompletionSource>(); using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled())) { - Task task = Task.Run(() => + Task> task = Task.Run(() => { - HandleAttachments(attachments, cancellationToken); + return ProcessAttachments(new Collection(attachments.ToList()), new ProgressReporter(eventHandler, dataCollectorAttachmentsHandlers.Length), cancellationToken); }); var completedTask = await Task.WhenAny(task, taskCompletionSource.Task).ConfigureAwait(false); if (completedTask == task) { - await task; - eventHandler?.HandleMultiTestRunFinalizationComplete(attachments); - testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); - return attachments; + return FinalizeOperation(requestData, await task, eventHandler, FinalizationCompleted); } else { eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Informational, "Finalization was cancelled."); - eventHandler?.HandleMultiTestRunFinalizationComplete(null); - testPlatformEventSource.MultiTestRunFinalizationStop(0); + return FinalizeOperation(requestData, attachments, eventHandler, FinalizationCanceled); } } - - return null; + } + catch (OperationCanceledException) + { + if (EqtTrace.IsWarningEnabled) + { + EqtTrace.Warning("MultiTestRunFinalizationManager: operation was cancelled."); + } + return FinalizeOperation(requestData, attachments, eventHandler, FinalizationCanceled); } catch (Exception e) { EqtTrace.Error("MultiTestRunFinalizationManager: Exception in FinalizeMultiTestRunAsync: " + e); eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); - eventHandler?.HandleMultiTestRunFinalizationComplete(null); - testPlatformEventSource.MultiTestRunFinalizationStop(0); - return null; + return FinalizeOperation(requestData, attachments, eventHandler, FinalizationFailed); + } + finally + { + stopwatch.Stop(); + requestData.MetricsCollection.Metrics.Add(TelemetryDataConstants.TimeTakenInSecForFinalization, stopwatch.Elapsed.TotalSeconds); } } - private void HandleAttachments(ICollection attachments, CancellationToken cancellationToken) + private Collection ProcessAttachments(Collection attachments, ProgressReporter progressReporter, CancellationToken cancellationToken) { + if (attachments == null || !attachments.Any()) return attachments; + foreach (var dataCollectorAttachmentsHandler in dataCollectorAttachmentsHandlers) { Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); @@ -105,7 +120,7 @@ private void HandleAttachments(ICollection attachments, Cancellat attachments.Remove(attachment); } - ICollection processedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), cancellationToken); + ICollection processedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), progressReporter, cancellationToken); foreach (var attachment in processedAttachments) { attachments.Add(attachment); @@ -113,6 +128,42 @@ private void HandleAttachments(ICollection attachments, Cancellat } } } + + return attachments; + } + + private Collection FinalizeOperation(IRequestData requestData, Collection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, string finalizationState) + { + eventHandler?.HandleMultiTestRunFinalizationComplete(attachments); + testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); + requestData.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsAfterFinalization, attachments.Count); + requestData.MetricsCollection.Add(TelemetryDataConstants.FinalizationState, attachments.Count); + + return attachments; + } + + private class ProgressReporter : IProgress + { + private readonly IMultiTestRunFinalizationEventsHandler eventsHandler; + private readonly int totalNumberOfHandlers; + private int currentHandlerIndex; + + public ProgressReporter(IMultiTestRunFinalizationEventsHandler eventsHandler, int totalNumberOfHandlers) + { + this.eventsHandler = eventsHandler; + this.currentHandlerIndex = 0; + this.totalNumberOfHandlers = totalNumberOfHandlers; + } + + public void IncremenetHandlerIndex() + { + currentHandlerIndex++; + } + + public void Report(int value) + { + //eventsHandler.report( current, total, value) + } } } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs index 13f7cfc229..844b86e8dc 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs @@ -15,6 +15,12 @@ public class MultiTestRunFinalizationPayload /// Collection of attachments. /// [DataMember] - public ICollection Attachments { get; set; } + public IEnumerable Attachments { get; set; } + + /// + /// Gets or sets whether Metrics should be collected or not. + /// + [DataMember] + public bool CollectMetrics { get; set; } } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs index 84df144523..4c1d2bdabf 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs @@ -21,8 +21,11 @@ public interface IDataCollectorAttachments /// /// Gets the attachment set after Test Run Session /// + /// Attachments to be processed + /// Progress reporter. Accepts integers from 0 to 100 + /// Cancellation token /// Gets the attachment set after Test Run Session - ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, CancellationToken cancellationToken); + ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, IProgress progressReporter, CancellationToken cancellationToken); /// /// Gets the attachment Uri, which is handled by current Collector diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index 1ca310ceda..90ab94fd56 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -9,6 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities using System.IO; using System.Linq; using System.Reflection; + using System.Resources; using System.Threading; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; @@ -33,15 +34,15 @@ public Uri GetExtensionUri() public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments) { - return HandleDataCollectionAttachmentSets(dataCollectionAttachments, CancellationToken.None); + return HandleDataCollectionAttachmentSets(dataCollectionAttachments, null, CancellationToken.None); } - public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, CancellationToken cancellationToken) + public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, IProgress progressReporter, CancellationToken cancellationToken) { if (dataCollectionAttachments != null && dataCollectionAttachments.Any()) { var codeCoverageFiles = dataCollectionAttachments.Select(coverageAttachment => coverageAttachment.Attachments[0].Uri.LocalPath).ToArray(); - var outputFile = MergeCodeCoverageFiles(codeCoverageFiles, cancellationToken); + var outputFile = MergeCodeCoverageFiles(codeCoverageFiles, progressReporter, cancellationToken); var attachmentSet = new AttachmentSet(CodeCoverageDataCollectorUri, CoverageFriendlyName); if (!string.IsNullOrEmpty(outputFile)) @@ -57,7 +58,7 @@ public ICollection HandleDataCollectionAttachmentSets(ICollection return new Collection(); } - private string MergeCodeCoverageFiles(IList files, CancellationToken cancellationToken) + private string MergeCodeCoverageFiles(IList files, IProgress progressReporter, CancellationToken cancellationToken) { string fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + CoverageFileExtension); string outputfileName = files[0]; @@ -82,11 +83,14 @@ private string MergeCodeCoverageFiles(IList files, CancellationToken can cancellationToken.ThrowIfCancellationRequested(); File.Copy(fileName, outputfileName, true); + + progressReporter?.Report(100 * i / files.Count); } File.Delete(fileName); } + progressReporter?.Report(100); return outputfileName; } catch (OperationCanceledException) diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs index 45519affa7..35e50a9b10 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs @@ -14,7 +14,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces /// /// Defines contract to send test platform requests to test host /// - internal interface ITranslationLayerRequestSender : IDisposable + internal interface ITranslationLayerRequestSender : IDisposable, ITranslationLayerRequestSenderAsync { /// /// Initializes the communication for sending requests @@ -111,13 +111,5 @@ internal interface ITranslationLayerRequestSender : IDisposable /// Cancels the discovery of tests /// void CancelDiscovery(); - - /// - /// Provides back all attachments to TestPlatform for additional processing (for example merging) - /// - /// Collection of attachments - /// Events handler - /// Cancellation token - Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs index 0bf4ce0a82..19ef32c915 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs @@ -23,16 +23,6 @@ internal interface ITranslationLayerRequestSenderAsync : IDisposable /// Task InitializeCommunicationAsync(int clientConnectionTimeout); - /// - /// See - /// - void Close(); - - /// - /// See - /// - void InitializeExtensions(IEnumerable pathToAdditionalExtensions); - /// /// Asynchronous equivalent of ITranslationLayerRequestSender.DiscoverTests/>. /// @@ -58,32 +48,13 @@ internal interface ITranslationLayerRequestSenderAsync : IDisposable /// Task StartTestRunWithCustomHostAsync(IEnumerable testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler runEventsHandler, ITestHostLauncher customTestHostLauncher); - /// - /// See . - /// - void EndSession(); - - /// - /// See . - /// - void CancelTestRun(); - - /// - /// See . - /// - void AbortTestRun(); - - /// - /// See . - /// - void OnProcessExited(); - /// /// Provides back all attachments to TestPlatform for additional processing (for example merging) /// /// Collection of attachments + /// Enables metrics collection /// Events handler /// Cancellation token - Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); + Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool collectMetrics, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs index d9b86dac3a..9cd3c6b5b9 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs @@ -4,8 +4,6 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces { using System.Collections.Generic; - using System.Threading; - using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; @@ -13,7 +11,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces /// /// Controller for various test operations on the test runner. /// - public interface IVsTestConsoleWrapper + public interface IVsTestConsoleWrapper : IVsTestConsoleWrapperAsync { /// /// Starts the test runner process and readies for requests. @@ -120,14 +118,6 @@ public interface IVsTestConsoleWrapper /// Custom test host launcher for the run. void RunTestsWithCustomTestHost(IEnumerable testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); - /// - /// Provides back all attachments to TestPlatform for additional processing (for example merging) - /// - /// Collection of attachments - /// EventHandler to receive session complete event - /// Cancellation token - Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); - /// /// Cancel the last test run. /// diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs index 3e6cabe3b8..56e322d711 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs @@ -37,11 +37,6 @@ public interface IVsTestConsoleWrapperAsync /// Task DiscoverTestsAsync(IEnumerable sources, string discoverySettings, TestPlatformOptions options, ITestDiscoveryEventsHandler2 discoveryEventsHandler); - /// - /// See . - /// - void CancelDiscovery(); - /// /// Asynchronous equivalent of . /// @@ -86,23 +81,9 @@ public interface IVsTestConsoleWrapperAsync /// Provides back all attachments to TestPlatform for additional processing (for example merging) /// /// Collection of attachments + /// Enables metrics collection /// EventHandler to receive session complete event - /// Cancellation token - Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); - - /// - /// See . - /// - void CancelTestRun(); - - /// - /// See . - /// - void AbortTestRun(); - - /// - /// See . - /// - void EndSession(); + /// Cancellation token + Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool collectMetrics, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index 69589fe187..6d0e187be5 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -26,7 +26,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer /// /// VstestConsoleRequestSender for sending requests to Vstest.console.exe /// - internal class VsTestConsoleRequestSender : ITranslationLayerRequestSender, ITranslationLayerRequestSenderAsync + internal class VsTestConsoleRequestSender : ITranslationLayerRequestSender { private readonly ICommunicationManager communicationManager; @@ -384,9 +384,9 @@ public void EndSession() } /// - public Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) + public Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool collectMetrics, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) { - return this.SendMessageAndListenAndReportFinalizationResultAsync(attachments, testSessionEventsHandler, cancellationToken); + return this.SendMessageAndListenAndReportFinalizationResultAsync(attachments, collectMetrics, testSessionEventsHandler, cancellationToken); } /// @@ -731,14 +731,16 @@ private async Task SendMessageAndListenAndReportTestResultsAsync(string messageT this.testPlatformEventSource.TranslationLayerExecutionStop(); } - private async Task SendMessageAndListenAndReportFinalizationResultAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) + private async Task SendMessageAndListenAndReportFinalizationResultAsync(IEnumerable attachments, bool collectMetrics, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) { try { var payload = new MultiTestRunFinalizationPayload { - Attachments = attachments + Attachments = attachments, + CollectMetrics = collectMetrics }; + this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationStart, payload); var isMultiTestRunFinalizationComplete = false; @@ -782,8 +784,10 @@ private async Task SendMessageAndListenAndReportFinalizationResultAsync(ICollect // know of the error, so that the TL can wait for the next instruction from the client itself. // Also, connection termination might not kill the process which could result in files being locked by testhost. } - - this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStop(); + finally + { + this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStop(); + } } private Message TryReceiveMessage() diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index 550f72330a..e59cf1c0cc 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -274,17 +274,150 @@ public void EndSession() this.sessionStarted = false; } + #endregion + + #region IVsTestConsoleWrapper + + /// + public async Task StartSessionAsync() + { + EqtTrace.Info("VsTestConsoleWrapperAsync.StartSessionAsync: Starting VsTestConsoleWrapper session"); + + this.testPlatformEventSource.TranslationLayerInitializeStart(); + + var timeout = EnvironmentHelper.GetConnectionTimeout(); + // Start communication + var port = await this.requestSender.InitializeCommunicationAsync(timeout * 1000); + + if (port > 0) + { + // Fill the parameters + this.consoleParameters.ParentProcessId = Process.GetCurrentProcess().Id; + this.consoleParameters.PortNumber = port; + + // Start vstest.console.exe process + this.vstestConsoleProcessManager.StartProcess(this.consoleParameters); + } + else + { + // Close the sender as it failed to host server + this.requestSender.Close(); + throw new TransationLayerException("Error hosting communication channel and connecting to console"); + } + } + + /// + public async Task InitializeExtensionsAsync(IEnumerable pathToAdditionalExtensions) + { + await this.EnsureInitializedAsync(); + this.pathToAdditionalExtensions = pathToAdditionalExtensions.ToList(); + this.requestSender.InitializeExtensions(this.pathToAdditionalExtensions); + } + + /// + public async Task DiscoverTestsAsync(IEnumerable sources, string discoverySettings, ITestDiscoveryEventsHandler discoveryEventsHandler) + { + this.testPlatformEventSource.TranslationLayerDiscoveryStart(); + await this.EnsureInitializedAsync(); + + // Converts ITestDiscoveryEventsHandler to ITestDiscoveryEventsHandler2 + var discoveryCompleteEventsHandler2 = new DiscoveryEventsHandleConverter(discoveryEventsHandler); + await this.requestSender.DiscoverTestsAsync(sources, discoverySettings, options: null, discoveryEventsHandler: discoveryCompleteEventsHandler2); + } + + + /// + public async Task DiscoverTestsAsync(IEnumerable sources, string discoverySettings, TestPlatformOptions options, ITestDiscoveryEventsHandler2 discoveryEventsHandler) + { + this.testPlatformEventSource.TranslationLayerDiscoveryStart(); + await this.EnsureInitializedAsync(); + await this.requestSender.DiscoverTestsAsync(sources, discoverySettings, options, discoveryEventsHandler); + } + + /// + public async Task RunTestsAsync(IEnumerable sources, string runSettings, ITestRunEventsHandler testRunEventsHandler) + { + await RunTestsAsync(sources, runSettings, null, testRunEventsHandler); + } + + /// + public async Task RunTestsAsync(IEnumerable sources, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler) + { + var sourceList = sources.ToList(); + this.testPlatformEventSource.TranslationLayerExecutionStart(0, sourceList.Count, 0, runSettings ?? string.Empty); + + await this.EnsureInitializedAsync(); + await this.requestSender.StartTestRunAsync(sourceList, runSettings, options, testRunEventsHandler); + } + /// - public Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) + public async Task RunTestsAsync(IEnumerable testCases, string runSettings, ITestRunEventsHandler testRunEventsHandler) + { + var testCaseList = testCases.ToList(); + this.testPlatformEventSource.TranslationLayerExecutionStart(0, 0, testCaseList.Count, runSettings ?? string.Empty); + + await this.EnsureInitializedAsync(); + await this.requestSender.StartTestRunAsync(testCaseList, runSettings, options: null, runEventsHandler: testRunEventsHandler); + } + + /// + public async Task RunTestsAsync(IEnumerable testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler) + { + var testCaseList = testCases.ToList(); + this.testPlatformEventSource.TranslationLayerExecutionStart(0, 0, testCaseList.Count, runSettings ?? string.Empty); + + await this.EnsureInitializedAsync(); + await this.requestSender.StartTestRunAsync(testCaseList, runSettings, options, testRunEventsHandler); + } + + /// + public async Task RunTestsWithCustomTestHostAsync(IEnumerable sources, string runSettings, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) + { + await RunTestsWithCustomTestHostAsync(sources, runSettings, null, testRunEventsHandler, customTestHostLauncher); + } + + /// + public async Task RunTestsWithCustomTestHostAsync(IEnumerable sources, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) + { + var sourceList = sources.ToList(); + this.testPlatformEventSource.TranslationLayerExecutionStart(1, sourceList.Count, 0, runSettings ?? string.Empty); + + await this.EnsureInitializedAsync(); + await this.requestSender.StartTestRunWithCustomHostAsync(sourceList, runSettings, options, testRunEventsHandler, customTestHostLauncher); + } + + /// + public async Task RunTestsWithCustomTestHostAsync(IEnumerable testCases, string runSettings, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) + { + var testCaseList = testCases.ToList(); + this.testPlatformEventSource.TranslationLayerExecutionStart(1, 0, testCaseList.Count, runSettings ?? string.Empty); + + await this.EnsureInitializedAsync(); + await this.requestSender.StartTestRunWithCustomHostAsync(testCaseList, runSettings, options: null, runEventsHandler: testRunEventsHandler, customTestHostLauncher: customTestHostLauncher); + } + + /// + public async Task RunTestsWithCustomTestHostAsync(IEnumerable testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) + { + var testCaseList = testCases.ToList(); + this.testPlatformEventSource.TranslationLayerExecutionStart(1, 0, testCaseList.Count, runSettings ?? string.Empty); + + await this.EnsureInitializedAsync(); + await this.requestSender.StartTestRunWithCustomHostAsync(testCaseList, runSettings, options, testRunEventsHandler, customTestHostLauncher); + } + + /// + public async Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool collectMetrics, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) { this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStart(); - this.EnsureInitialized(); - return requestSender.FinalizeMultiTestRunAsync(attachments, testSessionEventsHandler, cancellationToken); + await this.EnsureInitializedAsync().ConfigureAwait(false); + await requestSender.FinalizeMultiTestRunAsync(attachments, collectMetrics, testSessionEventsHandler, cancellationToken).ConfigureAwait(false); } #endregion + private void EnsureInitialized() { if (!this.vstestConsoleProcessManager.IsProcessInitialized()) @@ -307,6 +440,28 @@ private void EnsureInitialized() } } + private async Task EnsureInitializedAsync() + { + if (!this.vstestConsoleProcessManager.IsProcessInitialized()) + { + EqtTrace.Info("VsTestConsoleWrapper.EnsureInitializedAsync: Process is not started."); + await this.StartSessionAsync(); + this.sessionStarted = this.WaitForConnection(); + + if (this.sessionStarted) + { + EqtTrace.Info("VsTestConsoleWrapper.EnsureInitializedAsync: Send a request to initialize extensions."); + this.requestSender.InitializeExtensions(this.pathToAdditionalExtensions); + } + } + + if (!this.sessionStarted && this.requestSender != null) + { + EqtTrace.Info("VsTestConsoleWrapper.EnsureInitializedAsync: Process Started."); + this.sessionStarted = this.WaitForConnection(); + } + } + private bool WaitForConnection() { EqtTrace.Info("VsTestConsoleWrapper.WaitForConnection: Waiting for connection to command line runner."); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs deleted file mode 100644 index 0a0aaf829f..0000000000 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs +++ /dev/null @@ -1,269 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer -{ - using System.Collections.Generic; - using System.Diagnostics; - using System.Linq; - using System.Threading; - using System.Threading.Tasks; - - using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers; - using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing; - using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; - - /// - /// An implementation of to invoke test operations - /// via the vstest.console test runner. - /// - public class VsTestConsoleWrapperAsync : IVsTestConsoleWrapperAsync - { - #region Private Members - - private readonly IProcessManager vstestConsoleProcessManager; - - private readonly ITranslationLayerRequestSenderAsync requestSender; - - /// - /// Path to additional extensions to reinitialize vstest.console - /// - private IEnumerable pathToAdditionalExtensions; - - /// - /// Additional parameters for vstest.console.exe - /// - private readonly ConsoleParameters consoleParameters; - - private readonly ITestPlatformEventSource testPlatformEventSource; - - #endregion - - #region Constructor - - /// - /// Initializes a new instance of the class. - /// - /// - /// Path to the test runner vstest.console.exe. - /// - public VsTestConsoleWrapperAsync(string vstestConsolePath) : - this(vstestConsolePath, ConsoleParameters.Default) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Path to the test runner vstest.console.exe. - /// The parameters to be passed onto the runner process - public VsTestConsoleWrapperAsync(string vstestConsolePath, ConsoleParameters consoleParameters) : - this(new VsTestConsoleRequestSender(), new VsTestConsoleProcessManager(vstestConsolePath), consoleParameters, TestPlatformEventSource.Instance) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Sender for test messages. - /// Process manager. - /// The parameters to be passed onto the runner process - /// Performance event source - internal VsTestConsoleWrapperAsync(ITranslationLayerRequestSenderAsync requestSender, IProcessManager processManager, ConsoleParameters consoleParameters, ITestPlatformEventSource testPlatformEventSource) - { - this.requestSender = requestSender; - this.vstestConsoleProcessManager = processManager; - this.consoleParameters = consoleParameters; - this.testPlatformEventSource = testPlatformEventSource; - this.pathToAdditionalExtensions = new List(); - - this.vstestConsoleProcessManager.ProcessExited += (sender, args) => this.requestSender.OnProcessExited(); - } - - #endregion - - #region IVsTestConsoleWrapper - - /// - public async Task StartSessionAsync() - { - EqtTrace.Info("VsTestConsoleWrapperAsync.StartSessionAsync: Starting VsTestConsoleWrapper session"); - - this.testPlatformEventSource.TranslationLayerInitializeStart(); - - var timeout = EnvironmentHelper.GetConnectionTimeout(); - // Start communication - var port = await this.requestSender.InitializeCommunicationAsync(timeout * 1000); - - if (port > 0) - { - // Fill the parameters - this.consoleParameters.ParentProcessId = Process.GetCurrentProcess().Id; - this.consoleParameters.PortNumber = port; - - // Start vstest.console.exe process - this.vstestConsoleProcessManager.StartProcess(this.consoleParameters); - } - else - { - // Close the sender as it failed to host server - this.requestSender.Close(); - throw new TransationLayerException("Error hosting communication channel and connecting to console"); - } - } - - /// - public async Task InitializeExtensionsAsync(IEnumerable pathToAdditionalExtensions) - { - await this.EnsureInitializedAsync(); - this.pathToAdditionalExtensions = pathToAdditionalExtensions.ToList(); - this.requestSender.InitializeExtensions(this.pathToAdditionalExtensions); - } - - /// - public async Task DiscoverTestsAsync(IEnumerable sources, string discoverySettings, ITestDiscoveryEventsHandler discoveryEventsHandler) - { - this.testPlatformEventSource.TranslationLayerDiscoveryStart(); - await this.EnsureInitializedAsync(); - - // Converts ITestDiscoveryEventsHandler to ITestDiscoveryEventsHandler2 - var discoveryCompleteEventsHandler2 = new DiscoveryEventsHandleConverter(discoveryEventsHandler); - await this.requestSender.DiscoverTestsAsync(sources, discoverySettings, options: null, discoveryEventsHandler: discoveryCompleteEventsHandler2); - } - - - /// - public async Task DiscoverTestsAsync(IEnumerable sources, string discoverySettings, TestPlatformOptions options, ITestDiscoveryEventsHandler2 discoveryEventsHandler) - { - this.testPlatformEventSource.TranslationLayerDiscoveryStart(); - await this.EnsureInitializedAsync(); - await this.requestSender.DiscoverTestsAsync(sources, discoverySettings, options, discoveryEventsHandler); - } - - /// - public void CancelDiscovery() - { - // TODO: Cancel Discovery - // this.requestSender.CancelDiscovery(); - } - - /// - public async Task RunTestsAsync(IEnumerable sources, string runSettings, ITestRunEventsHandler testRunEventsHandler) - { - await RunTestsAsync(sources, runSettings, null, testRunEventsHandler); - } - - /// - public async Task RunTestsAsync(IEnumerable sources, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler) - { - var sourceList = sources.ToList(); - this.testPlatformEventSource.TranslationLayerExecutionStart(0, sourceList.Count, 0, runSettings ?? string.Empty); - - await this.EnsureInitializedAsync(); - await this.requestSender.StartTestRunAsync(sourceList, runSettings, options, testRunEventsHandler); - } - - /// - public async Task RunTestsAsync(IEnumerable testCases, string runSettings, ITestRunEventsHandler testRunEventsHandler) - { - var testCaseList = testCases.ToList(); - this.testPlatformEventSource.TranslationLayerExecutionStart(0, 0, testCaseList.Count, runSettings ?? string.Empty); - - await this.EnsureInitializedAsync(); - await this.requestSender.StartTestRunAsync(testCaseList, runSettings, options: null, runEventsHandler: testRunEventsHandler); - } - - /// - public async Task RunTestsAsync(IEnumerable testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler) - { - var testCaseList = testCases.ToList(); - this.testPlatformEventSource.TranslationLayerExecutionStart(0, 0, testCaseList.Count, runSettings ?? string.Empty); - - await this.EnsureInitializedAsync(); - await this.requestSender.StartTestRunAsync(testCaseList, runSettings, options, testRunEventsHandler); - } - - /// - public async Task RunTestsWithCustomTestHostAsync(IEnumerable sources, string runSettings, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) - { - await RunTestsWithCustomTestHostAsync(sources, runSettings, null, testRunEventsHandler, customTestHostLauncher); - } - - /// - public async Task RunTestsWithCustomTestHostAsync(IEnumerable sources, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) - { - var sourceList = sources.ToList(); - this.testPlatformEventSource.TranslationLayerExecutionStart(1, sourceList.Count, 0, runSettings ?? string.Empty); - - await this.EnsureInitializedAsync(); - await this.requestSender.StartTestRunWithCustomHostAsync(sourceList, runSettings, options, testRunEventsHandler, customTestHostLauncher); - } - - /// - public async Task RunTestsWithCustomTestHostAsync(IEnumerable testCases, string runSettings, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) - { - var testCaseList = testCases.ToList(); - this.testPlatformEventSource.TranslationLayerExecutionStart(1, 0, testCaseList.Count, runSettings ?? string.Empty); - - await this.EnsureInitializedAsync(); - await this.requestSender.StartTestRunWithCustomHostAsync(testCaseList, runSettings, options: null, runEventsHandler: testRunEventsHandler, customTestHostLauncher: customTestHostLauncher); - } - - /// - public async Task RunTestsWithCustomTestHostAsync(IEnumerable testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) - { - var testCaseList = testCases.ToList(); - this.testPlatformEventSource.TranslationLayerExecutionStart(1, 0, testCaseList.Count, runSettings ?? string.Empty); - - await this.EnsureInitializedAsync(); - await this.requestSender.StartTestRunWithCustomHostAsync(testCaseList, runSettings, options, testRunEventsHandler, customTestHostLauncher); - } - - /// - public async Task FinalizeMultiTestRunAsync(ICollection attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) - { - this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStart(); - - await this.EnsureInitializedAsync().ConfigureAwait(false); - await requestSender.FinalizeMultiTestRunAsync(attachments, testSessionEventsHandler, cancellationToken).ConfigureAwait(false); - } - - /// - public void CancelTestRun() - { - this.requestSender.CancelTestRun(); - } - - /// - public void AbortTestRun() - { - this.requestSender.AbortTestRun(); - } - - /// - public void EndSession() - { - this.requestSender.EndSession(); - this.requestSender.Close(); - } - - #endregion - - private async Task EnsureInitializedAsync() - { - if (!this.vstestConsoleProcessManager.IsProcessInitialized()) - { - EqtTrace.Info("VsTestConsoleWrapper.EnsureInitializedAsync: Process is not started."); - await this.StartSessionAsync(); - - EqtTrace.Info("VsTestConsoleWrapper.EnsureInitializedAsync: Send a request to initialize extensions."); - this.requestSender.InitializeExtensions(this.pathToAdditionalExtensions); - } - } - - } -} diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index d38cc6cd0e..ac53184926 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -313,10 +313,13 @@ public void RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc } /// - public void FinalizeMultiTestRun(MultiTestRunFinalizationPayload finalizationPayload, IMultiTestRunFinalizationEventsHandler finalizationEventsHandler) + public void FinalizeMultiTestRun(MultiTestRunFinalizationPayload finalizationPayload, IMultiTestRunFinalizationEventsHandler finalizationEventsHandler, ProtocolConfig protocolConfig) { EqtTrace.Info("TestRequestManager.FinalizeMultiTestRun: Multi test run finalization started."); + this.telemetryOptedIn = finalizationPayload.CollectMetrics; + var requestData = this.GetRequestData(protocolConfig); + // Make sure to run the run request inside a lock as the below section is not thread-safe // There can be only one discovery, execution or finalization request at a given point in time lock (this.syncObject) @@ -328,7 +331,7 @@ public void FinalizeMultiTestRun(MultiTestRunFinalizationPayload finalizationPay this.currentFinalizationCancellationTokenSource = new CancellationTokenSource(); - Task task = this.finalizationManager.FinalizeMultiTestRunAsync(finalizationPayload.Attachments, finalizationEventsHandler, this.currentFinalizationCancellationTokenSource.Token); + Task task = this.finalizationManager.FinalizeMultiTestRunAsync(requestData, finalizationPayload.Attachments, finalizationEventsHandler, this.currentFinalizationCancellationTokenSource.Token); task.Wait(); } finally @@ -341,6 +344,9 @@ public void FinalizeMultiTestRun(MultiTestRunFinalizationPayload finalizationPay EqtTrace.Info("TestRequestManager.FinalizeMultiTestRun: Multi test run finalization completed."); this.testPlatformEventSource.MultiTestRunFinalizationRequestStop(); + + // Post the finalization complete event + this.metricsPublisher.Result.PublishMetrics(TelemetryDataConstants.TestFinalizationCompleteEvent, requestData.MetricsCollection.Metrics); } } } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs index aab70e6843..54cf57f5cb 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -102,7 +102,7 @@ public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) Assert.AreEqual(2, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, multiTestRunFinalizationEventHandler, CancellationToken.None); // Assert multiTestRunFinalizationEventHandler.EnsureSuccess(); @@ -128,7 +128,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerI Assert.AreEqual(3, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, multiTestRunFinalizationEventHandler, CancellationToken.None); // Assert multiTestRunFinalizationEventHandler.EnsureSuccess(); @@ -154,7 +154,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run CancellationTokenSource cts = new CancellationTokenSource(); - Task finalization = this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(attachments, multiTestRunFinalizationEventHandler, cts.Token); + Task finalization = this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(attachments, true, multiTestRunFinalizationEventHandler, cts.Token); await Task.Delay(TimeSpan.FromSeconds(1)); // act @@ -186,7 +186,7 @@ public async Task EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runn Assert.AreEqual(6, this.runEventHandler.TestResults.Count); Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, multiTestRunFinalizationEventHandler, CancellationToken.None); // act this.vstestConsoleWrapper?.EndSession(); diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs index 4c8c962e92..28818876d9 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs @@ -419,7 +419,8 @@ public void DesignModeClientConnectShouldSendTestMessageAndFinalizationCompleteO this.mockTestRequestManager.Setup( rm => rm.FinalizeMultiTestRun( It.IsAny(), - It.IsAny())) + It.IsAny(), + It.IsAny())) .Throws(new Exception()); this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); @@ -442,7 +443,8 @@ public void DesignModeClientConnectShouldSendTestMessageAndDiscoverCompleteOnTes this.mockTestRequestManager.Setup( rm => rm.FinalizeMultiTestRun( It.IsAny(), - It.IsAny())) + It.IsAny(), + It.IsAny())) .Throws(new TestPlatformException("Hello world")); this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); @@ -464,7 +466,8 @@ public void DesignModeClientConnectShouldCallRequestManagerForFinalizationStart( .Setup( rm => rm.FinalizeMultiTestRun( It.IsAny(), - It.IsAny())) + It.IsAny(), + It.IsAny())) .Callback(() => complateEvent.Set()); this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); @@ -472,7 +475,7 @@ public void DesignModeClientConnectShouldCallRequestManagerForFinalizationStart( Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "Finalization not completed."); this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Never); this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny()), Times.Never); - this.mockTestRequestManager.Verify(rm => rm.FinalizeMultiTestRun(It.IsAny(), It.IsAny())); + this.mockTestRequestManager.Verify(rm => rm.FinalizeMultiTestRun(It.IsAny(), It.IsAny(), It.IsAny())); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs index 81bd9a7fe0..e341bb5c74 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs @@ -61,14 +61,14 @@ public void HandleTestRunComplete_ShouldCallFinalizerWithAttachmentsAndUseResult new AttachmentSet(new Uri(uri1), "uri1_input1") }; - mockMultiTestRunFinalizationManager.Setup(f => f.FinalizeMultiTestRunAsync(It.IsAny>(), It.IsAny())).Returns(Task.FromResult(outputAttachments)); + mockMultiTestRunFinalizationManager.Setup(f => f.FinalizeMultiTestRunAsync(mockRequestData.Object, It.IsAny>(), It.IsAny())).Returns(Task.FromResult(outputAttachments)); // act parallelDataCollectionEventsHandler.HandleTestRunComplete(new TestRunCompleteEventArgs(null, false, false, null, null, TimeSpan.FromSeconds(1)), null, inputAttachments, null); // assert mockTestRunEventsHandler.Verify(h => h.HandleTestRunComplete(It.IsAny(), It.IsAny(), It.Is>(c => c.Count == 1 && c.Contains(outputAttachments[0])), It.IsAny>())); - mockMultiTestRunFinalizationManager.Verify(f => f.FinalizeMultiTestRunAsync(It.Is>(a => a.Count == 3), cancellationTokenSource.Token)); + mockMultiTestRunFinalizationManager.Verify(f => f.FinalizeMultiTestRunAsync(mockRequestData.Object, It.Is>(a => a.Count == 3), cancellationTokenSource.Token)); } [TestMethod] @@ -82,14 +82,14 @@ public void HandleTestRunComplete_ShouldCallFinalizerWithAttachmentsAndNotUserRe new AttachmentSet(new Uri(uri3), "uri3_input1") }; - mockMultiTestRunFinalizationManager.Setup(f => f.FinalizeMultiTestRunAsync(It.IsAny>(), It.IsAny())).Returns(Task.FromResult((Collection)null)); + mockMultiTestRunFinalizationManager.Setup(f => f.FinalizeMultiTestRunAsync(mockRequestData.Object, It.IsAny>(), It.IsAny())).Returns(Task.FromResult((Collection)null)); // act parallelDataCollectionEventsHandler.HandleTestRunComplete(new TestRunCompleteEventArgs(null, false, false, null, null, TimeSpan.FromSeconds(1)), null, inputAttachments, null); // assert mockTestRunEventsHandler.Verify(h => h.HandleTestRunComplete(It.IsAny(), It.IsAny(), It.Is>(c => c.Count == 3), It.IsAny>())); - mockMultiTestRunFinalizationManager.Verify(f => f.FinalizeMultiTestRunAsync(It.Is>(a => a.Count == 3), cancellationTokenSource.Token)); + mockMultiTestRunFinalizationManager.Verify(f => f.FinalizeMultiTestRunAsync(mockRequestData.Object, It.Is>(a => a.Count == 3), cancellationTokenSource.Token)); } } } diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs index 915ad152b5..145c86993a 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs @@ -1,22 +1,23 @@ -using System.Collections.Generic; - -namespace Microsoft.TestPlatform.Utilities.UnitTests +namespace Microsoft.TestPlatform.Utilities.UnitTests { using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.Utilities; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; + using System.Collections.Generic; using System.Collections.ObjectModel; using System.Threading; [TestClass] public class CodeCoverageDataAttachmentsHandlerTests { - private CodeCoverageDataAttachmentsHandler coverageDataAttachmentsHandler; + private readonly Mock> mockProgressReporter; + private readonly CodeCoverageDataAttachmentsHandler coverageDataAttachmentsHandler; public CodeCoverageDataAttachmentsHandlerTests() { + mockProgressReporter = new Mock>(); coverageDataAttachmentsHandler = new CodeCoverageDataAttachmentsHandler(); } @@ -25,15 +26,17 @@ public void HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoAttachme { Collection attachment = new Collection(); ICollection resultAttachmentSets = - coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, CancellationToken.None); + coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 0); - resultAttachmentSets = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(null, CancellationToken.None); + resultAttachmentSets = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(null, mockProgressReporter.Object, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 0); + + mockProgressReporter.Verify(p => p.Report(It.IsAny()), Times.Never); } [TestMethod] @@ -49,9 +52,11 @@ public void HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested attachmentSet }; - Assert.ThrowsException(() => coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, cts.Token)); + Assert.ThrowsException(() => coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, cts.Token)); Assert.AreEqual(1, attachment.Count); + + mockProgressReporter.Verify(p => p.Report(It.IsAny()), Times.Never); } [TestMethod] @@ -71,11 +76,13 @@ public void HandleDataCollectionAttachmentSetsShouldReturnExistingAttachmentsIfF attachmentSet2 }; - var result = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, cts.Token); + var result = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, cts.Token); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Contains(attachmentSet1)); Assert.IsTrue(result.Contains(attachmentSet2)); + + mockProgressReporter.Verify(p => p.Report(It.IsAny()), Times.Never); } } } diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs index d3d45ca6a7..c1f999f6d8 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs @@ -33,8 +33,6 @@ public class VsTestConsoleRequestSenderTests { private readonly ITranslationLayerRequestSender requestSender; - private readonly ITranslationLayerRequestSenderAsync requestSenderAsync; - private readonly Mock mockCommunicationManager; private readonly int WaitTimeout = 2000; @@ -49,10 +47,6 @@ public VsTestConsoleRequestSenderTests() this.mockCommunicationManager.Object, JsonDataSerializer.Instance, new Mock().Object); - this.requestSenderAsync = new VsTestConsoleRequestSender( - this.mockCommunicationManager.Object, - JsonDataSerializer.Instance, - new Mock().Object); } #region Communication Tests @@ -104,7 +98,7 @@ public async Task InitializeCommunicationAsyncShouldReturnInvalidPortNumberIfHos this.mockCommunicationManager.Setup(cm => cm.HostServer(new IPEndPoint(IPAddress.Loopback, 0))).Throws(new Exception("Fail")); this.mockCommunicationManager.Setup(cm => cm.AcceptClientAsync()).Returns(Task.FromResult(false)); - var portOutput = await this.requestSenderAsync.InitializeCommunicationAsync(this.WaitTimeout); + var portOutput = await this.requestSender.InitializeCommunicationAsync(this.WaitTimeout); Assert.IsTrue(portOutput < 0, "Negative port number must be returned if Hosting Server fails."); this.mockCommunicationManager.Verify(cm => cm.HostServer(new IPEndPoint(IPAddress.Loopback, 0)), Times.Once); @@ -143,7 +137,7 @@ public async Task InitializeCommunicationAsyncShouldFailConnectionIfMessageRecei this.mockCommunicationManager.Setup(cm => cm.AcceptClientAsync()).Returns(Task.FromResult(false)).Callback(() => { }); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).ThrowsAsync(new Exception("Fail")); - var portOutput = await this.requestSenderAsync.InitializeCommunicationAsync(this.WaitTimeout); + var portOutput = await this.requestSender.InitializeCommunicationAsync(this.WaitTimeout); // Connection must not succeed as handshake failed Assert.AreEqual(-1, portOutput, "Connection must fail if handshake failed."); @@ -189,7 +183,7 @@ public async Task InitializeCommunicationAsyncShouldFailConnectionIfSessionConne this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(discoveryMessage)); - var portOutput = await this.requestSenderAsync.InitializeCommunicationAsync(this.WaitTimeout); + var portOutput = await this.requestSender.InitializeCommunicationAsync(this.WaitTimeout); Assert.AreEqual(-1, portOutput, "Connection must fail if version check failed."); this.mockCommunicationManager.Verify(cm => cm.HostServer(new IPEndPoint(IPAddress.Loopback, 0)), Times.Once); @@ -239,7 +233,7 @@ public async Task InitializeCommunicationAsyncShouldFailConnectionIfSendMessageF this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(sessionConnected)); this.mockCommunicationManager.Setup(cm => cm.SendMessage(MessageType.VersionCheck, this.protocolVersion)).Throws(new Exception("Fail")); - var portOutput = await this.requestSenderAsync.InitializeCommunicationAsync(this.WaitTimeout); + var portOutput = await this.requestSender.InitializeCommunicationAsync(this.WaitTimeout); Assert.AreEqual(-1, portOutput, "Connection must fail if version check failed."); this.mockCommunicationManager.Verify(cm => cm.HostServer(new IPEndPoint(IPAddress.Loopback, 0)), Times.Once); @@ -310,7 +304,7 @@ public async Task InitializeCommunicationAsyncShouldFailConnectionIfProtocolIsNo this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(sessionConnected)); this.mockCommunicationManager.Setup(cm => cm.SendMessage(MessageType.VersionCheck)).Callback(changedMessage); - var portOutput = await this.requestSenderAsync.InitializeCommunicationAsync(this.WaitTimeout); + var portOutput = await this.requestSender.InitializeCommunicationAsync(this.WaitTimeout); Assert.AreEqual(-1, portOutput, "Connection must fail if version check failed."); this.mockCommunicationManager.Verify(cm => cm.HostServer(new IPEndPoint(IPAddress.Loopback, 0)), Times.Once); @@ -361,7 +355,7 @@ public async Task DiscoverTestsAsyncShouldCompleteWithZeroTests() }; this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(discoveryComplete)); - await this.requestSenderAsync.DiscoverTestsAsync(new List() { "1.dll" }, null, null, mockHandler.Object); + await this.requestSender.DiscoverTestsAsync(new List() { "1.dll" }, null, null, mockHandler.Object); mockHandler.Verify(mh => mh.HandleDiscoveryComplete(It.IsAny(), null), Times.Once, "Discovery Complete must be called"); mockHandler.Verify(mh => mh.HandleDiscoveredTests(It.IsAny>()), Times.Never, "DiscoveredTests must not be called"); @@ -427,7 +421,7 @@ public async Task DiscoverTestsAsyncShouldCompleteWithSingleTest() mockHandler.Setup(mh => mh.HandleDiscoveredTests(It.IsAny>())).Callback( () => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(discoveryComplete))); - await this.requestSenderAsync.DiscoverTestsAsync(new List() { "1.dll" }, null, new TestPlatformOptions(), mockHandler.Object); + await this.requestSender.DiscoverTestsAsync(new List() { "1.dll" }, null, new TestPlatformOptions(), mockHandler.Object); mockHandler.Verify(mh => mh.HandleDiscoveryComplete(It.IsAny(), null), Times.Once, "Discovery Complete must be called"); mockHandler.Verify(mh => mh.HandleDiscoveredTests(It.IsAny>()), Times.Once, "DiscoveredTests must be called"); @@ -498,7 +492,7 @@ public async Task DiscoverTestsAsyncShouldReportBackTestsWithTraitsInTestsFoundM this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult((discoveryComplete))); }); - await this.requestSenderAsync.DiscoverTestsAsync(new List() { "1.dll" }, null, new TestPlatformOptions(), mockHandler.Object); + await this.requestSender.DiscoverTestsAsync(new List() { "1.dll" }, null, new TestPlatformOptions(), mockHandler.Object); Assert.IsNotNull(receivedTestCases); Assert.AreEqual(1, receivedTestCases.Count); @@ -570,7 +564,7 @@ public async Task DiscoverTestsAsyncShouldReportBackTestsWithTraitsInDiscoveryCo receivedTestCases = tests?.ToList(); }); - await this.requestSenderAsync.DiscoverTestsAsync(new List() { "1.dll" }, null, new TestPlatformOptions(), mockHandler.Object); + await this.requestSender.DiscoverTestsAsync(new List() { "1.dll" }, null, new TestPlatformOptions(), mockHandler.Object); Assert.IsNotNull(receivedTestCases); Assert.AreEqual(1, receivedTestCases.Count); @@ -635,7 +629,7 @@ public async Task DiscoverTestsAsyncShouldCompleteWithTestMessage() mockHandler.Setup(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny())).Callback( () => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(discoveryComplete))); - await this.requestSenderAsync.DiscoverTestsAsync(new List() { "1.dll" }, null, new TestPlatformOptions(), mockHandler.Object); + await this.requestSender.DiscoverTestsAsync(new List() { "1.dll" }, null, new TestPlatformOptions(), mockHandler.Object); mockHandler.Verify(mh => mh.HandleDiscoveryComplete(It.IsAny(), null), Times.Once, "Discovery Complete must be called"); mockHandler.Verify(mh => mh.HandleDiscoveredTests(It.IsAny>()), Times.Once, "DiscoveredTests must be called"); @@ -665,7 +659,7 @@ public async Task DiscoverTestsAsyncShouldAbortOnExceptionInSendMessage() var payload = new DiscoveryRequestPayload { Sources = sources, RunSettings = null }; this.mockCommunicationManager.Setup(cm => cm.SendMessage(MessageType.StartDiscovery, payload)).Throws(new IOException()); - await this.requestSenderAsync.DiscoverTestsAsync(sources, null, new TestPlatformOptions(), mockHandler.Object); + await this.requestSender.DiscoverTestsAsync(sources, null, new TestPlatformOptions(), mockHandler.Object); mockHandler.Verify(mh => mh.HandleDiscoveryComplete(It.IsAny(), null), Times.Once, "Discovery Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Error, It.IsAny()), Times.Once, "TestMessage event must be called"); @@ -710,16 +704,16 @@ public async Task DiscoverTestsAsyncShouldLogErrorWhenProcessExited() var testCase = new TestCase("hello", new Uri("world://how"), "1.dll"); var testCaseList = new List() { testCase }; var testsFound = CreateMessage(MessageType.TestCasesFound, testCaseList); - await this.requestSenderAsync.InitializeCommunicationAsync(this.WaitTimeout); + await this.requestSender.InitializeCommunicationAsync(this.WaitTimeout); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Callback( (CancellationToken c) => { - Task.Run(() => this.requestSenderAsync.OnProcessExited()).Wait(); + Task.Run(() => this.requestSender.OnProcessExited()).Wait(); Assert.IsTrue(c.IsCancellationRequested); }).Returns(Task.FromResult((Message)null)); - await this.requestSenderAsync.DiscoverTestsAsync(sources, null, new TestPlatformOptions(), mockHandler.Object); + await this.requestSender.DiscoverTestsAsync(sources, null, new TestPlatformOptions(), mockHandler.Object); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Error, It.IsAny()), Times.Once); } @@ -778,7 +772,7 @@ public async Task StartTestRunAsyncShouldCompleteWithZeroTests() var runComplete = CreateMessage(MessageType.ExecutionComplete, payload); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runComplete)); - await this.requestSenderAsync.StartTestRunAsync(new List() { "1.dll" }, null, null, mockHandler.Object); + await this.requestSender.StartTestRunAsync(new List() { "1.dll" }, null, null, mockHandler.Object); mockHandler.Verify(mh => mh.HandleTestRunComplete(It.IsAny(), It.IsAny(), null, null), Times.Once, "Run Complete must be called"); @@ -888,7 +882,7 @@ public async Task StartTestRunAsyncShouldCompleteWithSingleTestAndMessage() this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runComplete)); }); - await this.requestSenderAsync.StartTestRunAsync(new List() { "1.dll" }, null, null, mockHandler.Object); + await this.requestSender.StartTestRunAsync(new List() { "1.dll" }, null, null, mockHandler.Object); mockHandler.Verify(mh => mh.HandleTestRunComplete(It.IsAny(), It.IsAny(), null, null), Times.Once, "Run Complete must be called"); @@ -1060,7 +1054,7 @@ public async Task StartTestRunAsyncWithCustomHostShouldComplete() this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); - await this.requestSenderAsync.StartTestRunWithCustomHostAsync(new List() { "1.dll" }, null, null, mockHandler.Object, mockLauncher.Object); + await this.requestSender.StartTestRunWithCustomHostAsync(new List() { "1.dll" }, null, null, mockHandler.Object, mockLauncher.Object); mockHandler.Verify(mh => mh.HandleTestRunComplete(It.IsAny(), It.IsAny(), null, null), Times.Once, "Run Complete must be called"); @@ -1161,7 +1155,7 @@ public async Task StartTestRunAsyncWithCustomHostShouldNotAbortAndSendErrorToVst this.mockCommunicationManager.Setup(cm => cm.SendMessage(It.IsAny(), It.IsAny(), this.protocolVersion)). Callback(() => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runComplete))); - await this.requestSenderAsync.StartTestRunWithCustomHostAsync(new List() { "1.dll" }, null, null, mockHandler.Object, mockLauncher.Object); + await this.requestSender.StartTestRunWithCustomHostAsync(new List() { "1.dll" }, null, null, mockHandler.Object, mockLauncher.Object); mockHandler.Verify(mh => mh.HandleTestRunComplete(It.IsAny(), It.IsAny(), null, null), Times.Once, "Run Complete must be called"); @@ -1258,7 +1252,7 @@ public async Task StartTestRunAsyncWithSelectedTestsShouldCompleteWithZeroTests( var runComplete = CreateMessage(MessageType.ExecutionComplete, payload); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runComplete)); - await this.requestSenderAsync.StartTestRunAsync(new List(), null, new TestPlatformOptions(), mockHandler.Object); + await this.requestSender.StartTestRunAsync(new List(), null, new TestPlatformOptions(), mockHandler.Object); mockHandler.Verify(mh => mh.HandleTestRunComplete(It.IsAny(), It.IsAny(), null, null), Times.Once, "Run Complete must be called"); @@ -1366,7 +1360,7 @@ public async Task StartTestRunAsyncWithSelectedTestsShouldCompleteWithSingleTest this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runComplete)); }); - await this.requestSenderAsync.StartTestRunAsync(testCaseList, null, new TestPlatformOptions(), mockHandler.Object); + await this.requestSender.StartTestRunAsync(testCaseList, null, new TestPlatformOptions(), mockHandler.Object); mockHandler.Verify(mh => mh.HandleTestRunComplete(It.IsAny(), It.IsAny(), null, null), Times.Once, "Run Complete must be called"); @@ -1474,7 +1468,7 @@ public async Task StartTestRunAsyncWithSelectedTestsHavingTraitsShouldReturnTest receivedChangeEventArgs = stats; }); - await this.requestSenderAsync.StartTestRunAsync(testCaseList, null, new TestPlatformOptions(), mockHandler.Object); + await this.requestSender.StartTestRunAsync(testCaseList, null, new TestPlatformOptions(), mockHandler.Object); Assert.IsNotNull(receivedChangeEventArgs); Assert.IsTrue(receivedChangeEventArgs.NewTestResults.Count() > 0); @@ -1588,7 +1582,7 @@ public async Task StartTestRunAsyncWithSelectedTestsHavingTraitsShouldReturnTest this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runComplete)); }); - await this.requestSenderAsync.StartTestRunAsync(testCaseList, null, new TestPlatformOptions(), mockHandler.Object); + await this.requestSender.StartTestRunAsync(testCaseList, null, new TestPlatformOptions(), mockHandler.Object); Assert.IsNotNull(receivedChangeEventArgs); Assert.IsTrue(receivedChangeEventArgs.NewTestResults.Any()); @@ -1715,7 +1709,7 @@ public async Task StartTestRunWithCustomHostAsyncWithSelectedTestsShouldComplete this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); - await this.requestSenderAsync.StartTestRunWithCustomHostAsync(testCaseList, null, new TestPlatformOptions(), mockHandler.Object, mockLauncher.Object); + await this.requestSender.StartTestRunWithCustomHostAsync(testCaseList, null, new TestPlatformOptions(), mockHandler.Object, mockLauncher.Object); mockHandler.Verify(mh => mh.HandleTestRunComplete(It.IsAny(), It.IsAny(), null, null), Times.Once, "Run Complete must be called"); @@ -1797,8 +1791,8 @@ public async Task StartTestRunWithCustomHostAsyncInParallelShouldCallCustomHostM } }); - await this.requestSenderAsync.InitializeCommunicationAsync(this.WaitTimeout); - await this.requestSenderAsync.StartTestRunWithCustomHostAsync(sources, null, null, mockHandler.Object, mockLauncher.Object); + await this.requestSender.InitializeCommunicationAsync(this.WaitTimeout); + await this.requestSender.StartTestRunWithCustomHostAsync(sources, null, null, mockHandler.Object, mockLauncher.Object); mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Exactly(2)); } @@ -1830,7 +1824,7 @@ public async Task StartTestRunAsyncShouldAbortOnExceptionInSendMessage() this.mockCommunicationManager.Setup(cm => cm.SendMessage(MessageType.TestRunAllSourcesWithDefaultHost, payload, this.protocolVersion)).Throws(exception); - await this.requestSenderAsync.StartTestRunAsync(sources, null, null, mockHandler.Object); + await this.requestSender.StartTestRunAsync(sources, null, null, mockHandler.Object); mockHandler.Verify(mh => mh.HandleTestRunComplete(It.IsAny(), null, null, null), Times.Once, "Test Run Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Error, It.IsAny()), Times.Once, "TestMessage event must be called"); @@ -1883,16 +1877,16 @@ public async Task StartTestRunAsyncShouldLogErrorOnProcessExited() RunAttachments = null, TestRunCompleteArgs = dummyCompleteArgs }; - await this.requestSenderAsync.InitializeCommunicationAsync(this.WaitTimeout); + await this.requestSender.InitializeCommunicationAsync(this.WaitTimeout); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())) .Callback((CancellationToken c) => { - Task.Run(() => this.requestSenderAsync.OnProcessExited()).Wait(); + Task.Run(() => this.requestSender.OnProcessExited()).Wait(); Assert.IsTrue(c.IsCancellationRequested); }).Returns(Task.FromResult((Message)null)); - await this.requestSenderAsync.StartTestRunAsync(sources, null, null, mockHandler.Object); + await this.requestSender.StartTestRunAsync(sources, null, null, mockHandler.Object); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Error, It.IsAny()), Times.Once); } @@ -1916,7 +1910,7 @@ public async Task FinalizeTestsShouldCompleteWithZeroAttachments() }; this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete)); - await this.requestSenderAsync.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, mockHandler.Object, CancellationToken.None); + await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, true, mockHandler.Object, CancellationToken.None); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); @@ -1942,7 +1936,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachment() }; this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete)); - await this.requestSenderAsync.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, mockHandler.Object, CancellationToken.None); + await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, true, mockHandler.Object, CancellationToken.None); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); @@ -1974,7 +1968,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndTestMessage() mockHandler.Setup(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny())).Callback( () => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete))); - await this.requestSenderAsync.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, mockHandler.Object, CancellationToken.None); + await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, false, mockHandler.Object, CancellationToken.None); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); @@ -2011,7 +2005,7 @@ public async Task FinalizeTestsShouldSendCancelMessageIfCancellationTokenCancell this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete)); }); - await this.requestSenderAsync.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, mockHandler.Object, cts.Token); + await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, false, mockHandler.Object, cts.Token); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel)); @@ -2041,7 +2035,7 @@ public async Task FinalizeTestsShouldSendCancelMessageIfCancellationTokenCancell this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete)); - await this.requestSenderAsync.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, mockHandler.Object, cts.Token); + await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, true, mockHandler.Object, cts.Token); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel)); @@ -2055,7 +2049,7 @@ public async Task FinalizeTestsShouldAbortOnExceptionInSendMessage() var mockHandler = new Mock(); this.mockCommunicationManager.Setup(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())).Throws(new IOException()); - await this.requestSenderAsync.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, mockHandler.Object, CancellationToken.None); + await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, false, mockHandler.Object, CancellationToken.None); mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(null), Times.Once, "Discovery Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Error, It.IsAny()), Times.Once, "TestMessage event must be called"); @@ -2147,7 +2141,7 @@ private async Task InitializeCommunicationAsync() this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(sessionConnected)); this.mockCommunicationManager.Setup(cm => cm.SendMessage(MessageType.VersionCheck, this.protocolVersion)).Callback(changedMessage); - var portOutput = await this.requestSenderAsync.InitializeCommunicationAsync(this.WaitTimeout); + var portOutput = await this.requestSender.InitializeCommunicationAsync(this.WaitTimeout); Assert.AreEqual(dummyPortInput, portOutput, "Connection must succeed."); } diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs index 634bb7e1a4..67b2010580 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs @@ -14,6 +14,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -21,11 +22,13 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests [TestClass] public class VsTestConsoleWrapperAsyncTests { - private IVsTestConsoleWrapperAsync consoleWrapper; + private IVsTestConsoleWrapper consoleWrapper; private Mock mockProcessManager; - private Mock mockRequestSender; + private Mock mockRequestSender; + + private Mock mockProcessHelper; private readonly List testSources = new List { "Hello", "World" }; @@ -42,13 +45,15 @@ public void TestInitialize() { this.consoleParameters = new ConsoleParameters(); - this.mockRequestSender = new Mock(); + this.mockRequestSender = new Mock(); this.mockProcessManager = new Mock(); - this.consoleWrapper = new VsTestConsoleWrapperAsync( + this.mockProcessHelper = new Mock(); + this.consoleWrapper = new VsTestConsoleWrapper( this.mockRequestSender.Object, this.mockProcessManager.Object, this.consoleParameters, - new Mock().Object); + new Mock().Object, + this.mockProcessHelper.Object); this.mockRequestSender.Setup(rs => rs.InitializeCommunicationAsync(It.IsAny())).Returns(Task.FromResult(100)); } @@ -312,10 +317,11 @@ public async Task FinalizeMultiTestRunAsyncShouldSucceed() await this.consoleWrapper.FinalizeMultiTestRunAsync( attachments, + true, new Mock().Object, cancellationToken); - this.mockRequestSender.Verify(rs => rs.FinalizeMultiTestRunAsync(attachments, It.IsAny(), cancellationToken)); + this.mockRequestSender.Verify(rs => rs.FinalizeMultiTestRunAsync(attachments, true, It.IsAny(), cancellationToken)); } [TestMethod] diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs index 8b6797b7f4..fd48f7b979 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs @@ -314,10 +314,11 @@ public async Task FinalizeMultiTestRunAsyncShouldSucceed() await this.consoleWrapper.FinalizeMultiTestRunAsync( attachments, + true, new Mock().Object, cancellationToken); - this.mockRequestSender.Verify(rs => rs.FinalizeMultiTestRunAsync(attachments, It.IsAny(), cancellationToken)); + this.mockRequestSender.Verify(rs => rs.FinalizeMultiTestRunAsync(attachments, true, It.IsAny(), cancellationToken)); } [TestMethod] diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index 95e18855bb..fcb2619e0a 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -48,8 +48,6 @@ public class TestRequestManagerTests private InferHelper inferHelper; private ITestRequestManager testRequestManager; private Mock mockTestPlatformEventSource; - private Mock mockRequestData; - private Mock mockMetricsCollection; private ProtocolConfig protocolConfig; private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; @@ -89,9 +87,6 @@ public TestRequestManagerTests() this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); - this.mockMetricsCollection = new Mock(); - this.mockRequestData = new Mock(); - this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(this.mockMetricsCollection.Object); this.mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(this.mockDiscoveryRequest.Object); this.mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())) @@ -2183,21 +2178,43 @@ public void DiscoverTestsShouldOverrideOnlyAssemblyNameIfConsoleLoggerAlreadyPre } [TestMethod] - public void FinalizeMultiTestRunShouldSucceed() + public void FinalizeMultiTestRunShouldSucceedWithTelemetryEnabled() { var mockEventsHandler = new Mock(); mockFinalizationManager - .Setup(m => m.FinalizeMultiTestRunAsync(It.IsAny>(), It.IsAny(), It.IsAny())) + .Setup(m => m.FinalizeMultiTestRunAsync(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())) .Returns(Task.FromResult(true)); var payload = new MultiTestRunFinalizationPayload() { - Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } + Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, + CollectMetrics = true + }; + + testRequestManager.FinalizeMultiTestRun(payload, mockEventsHandler.Object, this.protocolConfig); + + mockFinalizationManager.Verify(m => m.FinalizeMultiTestRunAsync(It.Is(r => r.IsTelemetryOptedIn), payload.Attachments, mockEventsHandler.Object, It.IsAny())); + mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStart()); + mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStop()); + } + + [TestMethod] + public void FinalizeMultiTestRunShouldSucceedWithTelemetryDisabled() + { + var mockEventsHandler = new Mock(); + mockFinalizationManager + .Setup(m => m.FinalizeMultiTestRunAsync(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(true)); + + var payload = new MultiTestRunFinalizationPayload() + { + Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, + CollectMetrics = false }; - testRequestManager.FinalizeMultiTestRun(payload, mockEventsHandler.Object); + testRequestManager.FinalizeMultiTestRun(payload, mockEventsHandler.Object, this.protocolConfig); - mockFinalizationManager.Verify(m => m.FinalizeMultiTestRunAsync(payload.Attachments, mockEventsHandler.Object, It.IsAny())); + mockFinalizationManager.Verify(m => m.FinalizeMultiTestRunAsync(It.Is(r => !r.IsTelemetryOptedIn), payload.Attachments, mockEventsHandler.Object, It.IsAny())); mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStart()); mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStop()); } @@ -2207,7 +2224,7 @@ public async Task CancelMultiTestRunFinalizationShouldSucceedIfRequestInProgress { var mockEventsHandler = new Mock(); mockFinalizationManager - .Setup(m => m.FinalizeMultiTestRunAsync(It.IsAny>(), It.IsAny(), It.IsAny())) + .Setup(m => m.FinalizeMultiTestRunAsync(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())) .Returns((ICollection a, IMultiTestRunFinalizationEventsHandler h, CancellationToken token) => Task.Run(() => { int i = 0; @@ -2224,13 +2241,13 @@ public async Task CancelMultiTestRunFinalizationShouldSucceedIfRequestInProgress Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } }; - Task task = Task.Run(() => testRequestManager.FinalizeMultiTestRun(payload, mockEventsHandler.Object)); + Task task = Task.Run(() => testRequestManager.FinalizeMultiTestRun(payload, mockEventsHandler.Object, this.protocolConfig)); await Task.Delay(50); testRequestManager.CancelMultiTestRunFinalization(); await task; - mockFinalizationManager.Verify(m => m.FinalizeMultiTestRunAsync(payload.Attachments, mockEventsHandler.Object, It.IsAny())); + mockFinalizationManager.Verify(m => m.FinalizeMultiTestRunAsync(It.IsAny(), payload.Attachments, mockEventsHandler.Object, It.IsAny())); mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStart()); mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStop()); } From bcd06731f0d067ace1d3454a75b44a8a3bcff67d Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Fri, 19 Jun 2020 14:17:50 +0200 Subject: [PATCH 40/58] Fixing multi test finalization manager tests --- .../MultiTestRunFinalizationManager.cs | 4 +- .../MultiTestRunFinalizationManagerTests.cs | 224 ++++++++++-------- .../TestRequestManagerTests.cs | 21 +- 3 files changed, 147 insertions(+), 102 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index 4bb4818ee9..2e0a197bd5 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -99,7 +99,7 @@ private async Task> InternalFinalizeMultiTestRunAsync( finally { stopwatch.Stop(); - requestData.MetricsCollection.Metrics.Add(TelemetryDataConstants.TimeTakenInSecForFinalization, stopwatch.Elapsed.TotalSeconds); + requestData.MetricsCollection.Add(TelemetryDataConstants.TimeTakenInSecForFinalization, stopwatch.Elapsed.TotalSeconds); } } @@ -137,7 +137,7 @@ private Collection FinalizeOperation(IRequestData requestData, Co eventHandler?.HandleMultiTestRunFinalizationComplete(attachments); testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); requestData.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsAfterFinalization, attachments.Count); - requestData.MetricsCollection.Add(TelemetryDataConstants.FinalizationState, attachments.Count); + requestData.MetricsCollection.Add(TelemetryDataConstants.FinalizationState, finalizationState); return attachments; } diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs index e3d0f106f9..ba4f983854 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs @@ -8,7 +8,7 @@ namespace Microsoft.TestPlatform.CrossPlatEngine.UnitTests.MultiTestRunFinalizat using System.Linq; using System.Threading; using System.Threading.Tasks; - + using Microsoft.VisualStudio.TestPlatform.Common.Telemetry; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -16,7 +16,7 @@ namespace Microsoft.TestPlatform.CrossPlatEngine.UnitTests.MultiTestRunFinalizat using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; - using Moq; + using Moq; [TestClass] public class MultiTestRunFinalizationManagerTests @@ -25,6 +25,8 @@ public class MultiTestRunFinalizationManagerTests private const string uri2 = "datacollector://microsoft/some2/2.0"; private const string uri3 = "datacollector://microsoft/some3/2.0"; + private readonly Mock mockRequestData; + private readonly Mock mockMetricsCollection; private readonly Mock mockEventSource; private readonly Mock mockAttachmentHandler1; private readonly Mock mockAttachmentHandler2; @@ -34,6 +36,10 @@ public class MultiTestRunFinalizationManagerTests public MultiTestRunFinalizationManagerTests() { + mockRequestData = new Mock(); + mockMetricsCollection = new Mock(); + mockRequestData.Setup(r => r.MetricsCollection).Returns(mockMetricsCollection.Object); + mockEventSource = new Mock(); mockAttachmentHandler1 = new Mock(); mockAttachmentHandler2 = new Mock(); @@ -48,23 +54,25 @@ public MultiTestRunFinalizationManagerTests() } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnNoAttachmentsThroughEventsHandler_IfNoAttachmentsOnInput() + public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroughEventsHandler_IfNoAttachmentsOnInput() { // arrange List inputAttachments = new List(); // act - await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>(c => c.Count == 0))); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(0)); mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + + VerifyMetrics(0, 0); } [TestMethod] @@ -74,16 +82,16 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNoAttachments_IfNoAttach List inputAttachments = new List(); // act - var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); // assert Assert.AreEqual(0, result.Count); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(0)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + + VerifyMetrics(0, 0); } [TestMethod] @@ -96,17 +104,17 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachmentT }; // act - await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])))); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(1)); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + + VerifyMetrics(1, 1); } [TestMethod] @@ -119,17 +127,17 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachment_ }; // act - var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); // assert Assert.AreEqual(1, result.Count); Assert.IsTrue(result.Contains(inputAttachments[0])); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(1)); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + + VerifyMetrics(1, 1); } [TestMethod] @@ -146,20 +154,20 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachmentThro new AttachmentSet(new Uri(uri1), "uri1_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns(outputAttachments); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns(outputAttachments); // act - await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>(c => c.Count == 1 && c.Contains(outputAttachments[0])))); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(1)); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + + VerifyMetrics(1, 1); } [TestMethod] @@ -176,10 +184,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachment_IfR new AttachmentSet(new Uri(uri1), "uri1_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns(outputAttachments); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns(outputAttachments); // act - var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); // assert Assert.AreEqual(1, result.Count); @@ -188,12 +196,14 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachment_IfR mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(1)); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + + VerifyMetrics(1, 1); } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnNullThroughEventsHandler_IfRelatedAttachmentOnInputButHandlerThrowsException() + public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroughEventsHandler_IfRelatedAttachmentOnInputButHandlerThrowsException() { // arrange List inputAttachments = new List @@ -201,24 +211,26 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNullThroughEventsHandler new AttachmentSet(new Uri(uri1), "uri1_input") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Throws(new Exception("exception message")); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Throws(new Exception("exception message")); // act - await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(null)); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>( + c => c.Count == 1 && + c.Contains(inputAttachments[0])))); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "exception message"), Times.Once); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + + VerifyMetrics(1, 1, "Failed"); } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfRelatedAttachmentOnInputButHandlerThrowsException() + public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfRelatedAttachmentOnInputButHandlerThrowsException() { // arrange List inputAttachments = new List @@ -226,23 +238,24 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfRelatedAttachment new AttachmentSet(new Uri(uri1), "uri1_input") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Throws(new Exception("exception message")); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Throws(new Exception("exception message")); // act - var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); // assert - Assert.IsNull(result); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + Assert.AreEqual(1, result.Count); + Assert.IsTrue(result.Contains(inputAttachments[0])); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + + VerifyMetrics(1, 1, "Failed"); } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnNullThroughEventsHandler_IfOperationIsCancelled() + public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroughEventsHandler_IfOperationIsCancelled() { // arrange cancellationTokenSource.Cancel(); @@ -252,21 +265,22 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNullThroughEventsHandler }; // act - await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(null)); - mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "The operation was canceled."), Times.Once); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>( + c => c.Count == 1 && + c.Contains(inputAttachments[0])))); mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + + VerifyMetrics(1, 1, "Canceled"); } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfOperationIsCancelled() + public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOperationIsCancelled() { // arrange cancellationTokenSource.Cancel(); @@ -276,16 +290,17 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfOperationIsCancel }; // act - var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); // assert - Assert.IsNull(result); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + Assert.AreEqual(1, result.Count); + Assert.IsTrue(result.Contains(inputAttachments[0])); mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + + VerifyMetrics(1, 1, "Canceled"); } [TestMethod] @@ -311,11 +326,11 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachmentsThro new AttachmentSet(new Uri(uri2), "uri2_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler1); - mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler2); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler1); + mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler2); // act - await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>( @@ -324,12 +339,12 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachmentsThro c.Contains(outputAttachmentsForHandler1.First()) && c.Contains(outputAttachmentsForHandler2.First())))); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(5)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(3)); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), cancellationTokenSource.Token)); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), cancellationTokenSource.Token)); + + VerifyMetrics(5, 3); } [TestMethod] @@ -355,27 +370,27 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachments_IfR new AttachmentSet(new Uri(uri2), "uri2_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler1); - mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler2); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler1); + mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler2); // act - var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); // assert Assert.AreEqual(3, result.Count); Assert.IsTrue(result.Contains(inputAttachments[4])); Assert.IsTrue(result.Contains(outputAttachmentsForHandler1[0])); Assert.IsTrue(result.Contains(outputAttachmentsForHandler2[0])); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(5)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(3)); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), cancellationTokenSource.Token)); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), cancellationTokenSource.Token)); + + VerifyMetrics(5, 3); } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnNullThroughEventsHandler_IfOperationCancelled() + public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroughEventsHandler_IfOperationCancelled() { // arrange List inputAttachments = new List @@ -390,7 +405,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNullThroughEventsHandler var innerTaskCompletionSource = new TaskCompletionSource(); - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns((ICollection i1, CancellationToken cancellation) => + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns((ICollection i1, IProgress progress, CancellationToken cancellation) => { try { @@ -412,28 +427,30 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNullThroughEventsHandler { innerTaskCompletionSource.TrySetResult(null); } - + return outputAttachments; }); // act - await manager.FinalizeMultiTestRunAsync(inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); Console.WriteLine("Finalization done"); await innerTaskCompletionSource.Task; // assert - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(null)); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>( + c => c.Count == 1 && + c.Contains(inputAttachments[0])))); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Informational, "Finalization was cancelled.")); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + + VerifyMetrics(1, 1, "Canceled"); } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfOperationCancelled() + public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOperationCancelled() { // arrange List inputAttachments = new List @@ -448,7 +465,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfOperationCancelle var innerTaskCompletionSource = new TaskCompletionSource(); - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns((ICollection i1, CancellationToken cancellation) => + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns((ICollection i1, IProgress p, CancellationToken cancellation) => { try { @@ -475,18 +492,31 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfOperationCancelle }); // act - var result = await manager.FinalizeMultiTestRunAsync(inputAttachments, cancellationTokenSource.Token); + var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); Console.WriteLine("Finalization done"); await innerTaskCompletionSource.Task; // assert - Assert.IsNull(result); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + Assert.IsNotNull(result); + Assert.AreEqual(1, result.Count); + Assert.IsTrue(result.Contains(inputAttachments[0])); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + + VerifyMetrics(1, 1, "Canceled"); + } + + private void VerifyMetrics(int inputCount, int outputCount, string status = "Completed") + { + mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(inputCount)); + mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(outputCount)); + + mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.NumberOfAttachmentsSentForFinalization, inputCount)); + mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.NumberOfAttachmentsAfterFinalization, outputCount)); + mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.FinalizationState, status)); + mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.TimeTakenInSecForFinalization, It.IsAny())); } } } diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index fcb2619e0a..768263b8a1 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -2183,7 +2183,11 @@ public void FinalizeMultiTestRunShouldSucceedWithTelemetryEnabled() var mockEventsHandler = new Mock(); mockFinalizationManager .Setup(m => m.FinalizeMultiTestRunAsync(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(true)); + .Returns((IRequestData r, ICollection a, IMultiTestRunFinalizationEventsHandler h, CancellationToken token) => Task.Run(() => + { + r.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsSentForFinalization, 5); + r.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsAfterFinalization, 1); + })); var payload = new MultiTestRunFinalizationPayload() { @@ -2196,6 +2200,11 @@ public void FinalizeMultiTestRunShouldSucceedWithTelemetryEnabled() mockFinalizationManager.Verify(m => m.FinalizeMultiTestRunAsync(It.Is(r => r.IsTelemetryOptedIn), payload.Attachments, mockEventsHandler.Object, It.IsAny())); mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStart()); mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStop()); + + mockMetricsPublisher.Verify(p => p.PublishMetrics(TelemetryDataConstants.TestFinalizationCompleteEvent, + It.Is>(m => m.Count == 2 && + m.ContainsKey(TelemetryDataConstants.NumberOfAttachmentsSentForFinalization) && (int)m[TelemetryDataConstants.NumberOfAttachmentsSentForFinalization] == 5 && + m.ContainsKey(TelemetryDataConstants.NumberOfAttachmentsAfterFinalization) && (int)m[TelemetryDataConstants.NumberOfAttachmentsAfterFinalization] == 1))); } [TestMethod] @@ -2225,7 +2234,7 @@ public async Task CancelMultiTestRunFinalizationShouldSucceedIfRequestInProgress var mockEventsHandler = new Mock(); mockFinalizationManager .Setup(m => m.FinalizeMultiTestRunAsync(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())) - .Returns((ICollection a, IMultiTestRunFinalizationEventsHandler h, CancellationToken token) => Task.Run(() => + .Returns((IRequestData r, ICollection a, IMultiTestRunFinalizationEventsHandler h, CancellationToken token) => Task.Run(() => { int i = 0; while (!token.IsCancellationRequested) @@ -2234,11 +2243,14 @@ public async Task CancelMultiTestRunFinalizationShouldSucceedIfRequestInProgress Console.WriteLine($"Iteration {i}"); Task.Delay(5).Wait(); } + + r.MetricsCollection.Add(TelemetryDataConstants.FinalizationState, "Canceled"); })); var payload = new MultiTestRunFinalizationPayload() { - Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } + Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, + CollectMetrics = true }; Task task = Task.Run(() => testRequestManager.FinalizeMultiTestRun(payload, mockEventsHandler.Object, this.protocolConfig)); @@ -2250,6 +2262,9 @@ public async Task CancelMultiTestRunFinalizationShouldSucceedIfRequestInProgress mockFinalizationManager.Verify(m => m.FinalizeMultiTestRunAsync(It.IsAny(), payload.Attachments, mockEventsHandler.Object, It.IsAny())); mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStart()); mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStop()); + + mockMetricsPublisher.Verify(p => p.PublishMetrics(TelemetryDataConstants.TestFinalizationCompleteEvent, + It.Is>(m => m.Count == 1 && m.ContainsKey(TelemetryDataConstants.FinalizationState) && (string)m[TelemetryDataConstants.FinalizationState] == "Canceled"))); } [TestMethod] From 147f23ece6e80454911ea71a3a87f8ecb27f5c3f Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Fri, 19 Jun 2020 14:49:44 +0200 Subject: [PATCH 41/58] Fixes --- .../VsTestConsoleWrapper.cs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index e59cf1c0cc..116a9d3240 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -446,19 +446,9 @@ private async Task EnsureInitializedAsync() { EqtTrace.Info("VsTestConsoleWrapper.EnsureInitializedAsync: Process is not started."); await this.StartSessionAsync(); - this.sessionStarted = this.WaitForConnection(); - - if (this.sessionStarted) - { - EqtTrace.Info("VsTestConsoleWrapper.EnsureInitializedAsync: Send a request to initialize extensions."); - this.requestSender.InitializeExtensions(this.pathToAdditionalExtensions); - } - } - if (!this.sessionStarted && this.requestSender != null) - { - EqtTrace.Info("VsTestConsoleWrapper.EnsureInitializedAsync: Process Started."); - this.sessionStarted = this.WaitForConnection(); + EqtTrace.Info("VsTestConsoleWrapper.EnsureInitializedAsync: Send a request to initialize extensions."); + this.requestSender.InitializeExtensions(this.pathToAdditionalExtensions); } } From 5d185667e56f35724964efe3e2f039b90c3f079b Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Fri, 19 Jun 2020 14:56:09 +0200 Subject: [PATCH 42/58] Fix last unit test --- test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs index fd48f7b979..b27f781ba1 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs @@ -56,6 +56,7 @@ public void TestInitialize() this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); this.mockRequestSender.Setup(rs => rs.InitializeCommunication()).Returns(100); + this.mockRequestSender.Setup(rs => rs.InitializeCommunicationAsync(It.IsAny())).Returns(Task.FromResult(100)); } [TestMethod] From f4c121ab223d700ee8eed24c137f37ebad7dce37 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Fri, 19 Jun 2020 21:40:14 +0200 Subject: [PATCH 43/58] Fix acceptance tests --- .../TranslationLayerTests/CodeCoverageTests.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs index 54cf57f5cb..6818593723 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -164,10 +164,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run await finalization; multiTestRunFinalizationEventHandler.EnsureSuccess(); - if(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework)) - { - Assert.AreEqual(0, this.multiTestRunFinalizationEventHandler.Attachments.Count); - } + Assert.AreEqual(1000, this.multiTestRunFinalizationEventHandler.Attachments.Count); } [TestMethod] From 1b56b78fe0c60a23d8684eac54edce0d424721ca Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Mon, 22 Jun 2020 12:19:58 +0200 Subject: [PATCH 44/58] Progress feature, compiling + unit tests --- .../MultiTestRunFinalizationEventsHandler.cs | 37 +++++++--- .../Messages/MessageType.cs | 5 ++ ...MultiTestRunFinalizationCompletePayload.cs | 8 ++- ...MultiTestRunFinalizationProgressPayload.cs | 18 +++++ .../MultiTestRunFinalizationManager.cs | 56 ++++++---------- ...ltiTestRunFinalizationCompleteEventArgs.cs | 50 ++++++++++++++ ...ltiTestRunFinalizationProgressEventArgs.cs | 51 ++++++++++++++ .../IMultiTestRunFinalizationEventsHandler.cs | 17 ++++- .../VsTestConsoleRequestSender.cs | 9 ++- .../MultiTestRunFinalizationEventHandler.cs | 23 +++++++ ...tiTestRunFinalizationEventsHandlerTests.cs | 15 ++++- .../MultiTestRunFinalizationManagerTests.cs | 54 ++++++++++----- .../VsTestConsoleRequestSenderTests.cs | 67 ++++++++++++++++--- 13 files changed, 331 insertions(+), 79 deletions(-) create mode 100644 src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationProgressPayload.cs create mode 100644 src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs create mode 100644 src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs diff --git a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs index cc9c7cbcab..b31d7463a9 100644 --- a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs @@ -27,14 +27,7 @@ public MultiTestRunFinalizationEventsHandler(ICommunicationManager communication } /// - public void HandleLogMessage(TestMessageLevel level, string message) - { - var testMessagePayload = new TestMessagePayload { MessageLevel = level, Message = message }; - this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); - } - - /// - public void HandleMultiTestRunFinalizationComplete(ICollection attachments) + public void HandleMultiTestRunFinalizationComplete(MultiTestRunFinalizationCompleteEventArgs finalizationCompleteEventArgs, IEnumerable lastChunk) { if (EqtTrace.IsInfoEnabled) { @@ -43,13 +36,37 @@ public void HandleMultiTestRunFinalizationComplete(ICollection at var payload = new MultiTestRunFinalizationCompletePayload() { - Attachments = attachments + FinalizationCompleteEventArgs = finalizationCompleteEventArgs, + Attachments = lastChunk }; - // Send run complete to translation layer this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationComplete, payload); } + /// + public void HandleMultiTestRunFinalizationProgress(MultiTestRunFinalizationProgressEventArgs finalizationProgressEventArgs) + { + var payload = new MultiTestRunFinalizationProgressPayload() + { + FinalizationProgressEventArgs = finalizationProgressEventArgs, + }; + + this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationProgress, payload); + } + + /// + public void HandleFinalisedAttachments(IEnumerable attachments) + { + throw new System.NotImplementedException(); + } + + /// + public void HandleLogMessage(TestMessageLevel level, string message) + { + var testMessagePayload = new TestMessagePayload { MessageLevel = level, Message = message }; + this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); + } + /// public void HandleRawMessage(string rawMessage) { diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs index bb23393f03..802c8e5c87 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs @@ -133,6 +133,11 @@ public static class MessageType /// public const string MultiTestRunFinalizationComplete = "MultiTestRunFinalization.Complete"; + /// + /// Multi test run finalization progress + /// + public const string MultiTestRunFinalizationProgress = "MultiTestRunFinalization.Progress"; + /// /// Cancel multi test run finalization /// diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationCompletePayload.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationCompletePayload.cs index d20d55e61a..4d9ef24169 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationCompletePayload.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationCompletePayload.cs @@ -6,15 +6,21 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel using System.Collections.Generic; using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; /// /// Multi test run finalization complete payload. /// public class MultiTestRunFinalizationCompletePayload { + /// + /// Gets or sets the multi test run finalization complete args. + /// + public MultiTestRunFinalizationCompleteEventArgs FinalizationCompleteEventArgs { get; set; } + /// /// Gets or sets the attachments. /// - public ICollection Attachments { get; set; } + public IEnumerable Attachments { get; set; } } } diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationProgressPayload.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationProgressPayload.cs new file mode 100644 index 0000000000..6190ada03c --- /dev/null +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationProgressPayload.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel +{ + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + + /// + /// Multi test run finalization complete payload. + /// + public class MultiTestRunFinalizationProgressPayload + { + /// + /// Gets or sets the multi test run finalization complete args. + /// + public MultiTestRunFinalizationProgressEventArgs FinalizationProgressEventArgs { get; set; } + } +} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index 2e0a197bd5..5e7d14b69d 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -65,19 +65,19 @@ private async Task> InternalFinalizeMultiTestRunAsync( { Task> task = Task.Run(() => { - return ProcessAttachments(new Collection(attachments.ToList()), new ProgressReporter(eventHandler, dataCollectorAttachmentsHandlers.Length), cancellationToken); + return ProcessAttachments(new Collection(attachments.ToList()), eventHandler, cancellationToken); }); var completedTask = await Task.WhenAny(task, taskCompletionSource.Task).ConfigureAwait(false); if (completedTask == task) { - return FinalizeOperation(requestData, await task, eventHandler, FinalizationCompleted); + return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, false, null), await task, eventHandler); } else { eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Informational, "Finalization was cancelled."); - return FinalizeOperation(requestData, attachments, eventHandler, FinalizationCanceled); + return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, false, null), attachments, eventHandler); } } } @@ -87,14 +87,14 @@ private async Task> InternalFinalizeMultiTestRunAsync( { EqtTrace.Warning("MultiTestRunFinalizationManager: operation was cancelled."); } - return FinalizeOperation(requestData, attachments, eventHandler, FinalizationCanceled); + return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, false, null), attachments, eventHandler); } catch (Exception e) { EqtTrace.Error("MultiTestRunFinalizationManager: Exception in FinalizeMultiTestRunAsync: " + e); eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); - return FinalizeOperation(requestData, attachments, eventHandler, FinalizationFailed); + return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, true, e), attachments, eventHandler); } finally { @@ -103,12 +103,15 @@ private async Task> InternalFinalizeMultiTestRunAsync( } } - private Collection ProcessAttachments(Collection attachments, ProgressReporter progressReporter, CancellationToken cancellationToken) + private Collection ProcessAttachments(Collection attachments, IMultiTestRunFinalizationEventsHandler eventsHandler, CancellationToken cancellationToken) { - if (attachments == null || !attachments.Any()) return attachments; + if (attachments == null || !attachments.Any()) return attachments; - foreach (var dataCollectorAttachmentsHandler in dataCollectorAttachmentsHandlers) + for (int i = 0; i < dataCollectorAttachmentsHandlers.Length; i++) { + IDataCollectorAttachments dataCollectorAttachmentsHandler = dataCollectorAttachmentsHandlers[i]; + string attachmentsHandlerName = dataCollectorAttachmentsHandler.GetType().FullName; + Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); if (attachementUri != null) { @@ -120,6 +123,9 @@ private Collection ProcessAttachments(Collection a attachments.Remove(attachment); } + IProgress progressReporter = new Progress((int progress) => + eventsHandler?.HandleMultiTestRunFinalizationProgress( + new MultiTestRunFinalizationProgressEventArgs(i + 1, attachmentsHandlerName, progress, dataCollectorAttachmentsHandlers.Length))); ICollection processedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), progressReporter, cancellationToken); foreach (var attachment in processedAttachments) { @@ -132,38 +138,16 @@ private Collection ProcessAttachments(Collection a return attachments; } - private Collection FinalizeOperation(IRequestData requestData, Collection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, string finalizationState) - { - eventHandler?.HandleMultiTestRunFinalizationComplete(attachments); + private Collection FinalizeOperation(IRequestData requestData, MultiTestRunFinalizationCompleteEventArgs completeArgs, Collection attachments, IMultiTestRunFinalizationEventsHandler eventHandler) + { testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); requestData.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsAfterFinalization, attachments.Count); - requestData.MetricsCollection.Add(TelemetryDataConstants.FinalizationState, finalizationState); - - return attachments; - } + requestData.MetricsCollection.Add(TelemetryDataConstants.FinalizationState, completeArgs.IsAborted ? FinalizationFailed : completeArgs.IsCanceled ? FinalizationCanceled : FinalizationCompleted); - private class ProgressReporter : IProgress - { - private readonly IMultiTestRunFinalizationEventsHandler eventsHandler; - private readonly int totalNumberOfHandlers; - private int currentHandlerIndex; + completeArgs.Metrics = requestData.MetricsCollection.Metrics; + eventHandler?.HandleMultiTestRunFinalizationComplete(completeArgs, attachments); - public ProgressReporter(IMultiTestRunFinalizationEventsHandler eventsHandler, int totalNumberOfHandlers) - { - this.eventsHandler = eventsHandler; - this.currentHandlerIndex = 0; - this.totalNumberOfHandlers = totalNumberOfHandlers; - } - - public void IncremenetHandlerIndex() - { - currentHandlerIndex++; - } - - public void Report(int value) - { - //eventsHandler.report( current, total, value) - } + return attachments; } } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs new file mode 100644 index 0000000000..db61554c9d --- /dev/null +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client +{ + using System; + using System.Collections.Generic; + using System.Runtime.Serialization; + + [DataContract] + public class MultiTestRunFinalizationCompleteEventArgs : EventArgs + { + /// + /// Default constructor. + /// + /// Specifies whether the finalization is canceled. + /// Specifies whether the finalization is aborted. + /// Specifies the error encountered during the execution of the finalization. + public MultiTestRunFinalizationCompleteEventArgs(bool isCanceled, bool isAborted, Exception error) + { + this.IsCanceled = isCanceled; + this.IsAborted = isAborted; + this.Error = error; + } + + /// + /// Gets a value indicating whether the finalization is aborted or not. + /// + [DataMember] + public bool IsAborted { get; private set; } + + /// + /// Gets a value indicating whether the finalization is canceled or not. + /// + [DataMember] + public bool IsCanceled { get; private set; } + + /// + /// Gets the error encountered during the finalization of the test runs. Null if there is no error. + /// + [DataMember] + public Exception Error { get; private set; } + + /// + /// Get or Sets the Metrics + /// + [DataMember] + public IDictionary Metrics { get; set; } + } +} diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs new file mode 100644 index 0000000000..760987ec4a --- /dev/null +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client +{ + using System; + using System.Runtime.Serialization; + + [DataContract] + public class MultiTestRunFinalizationProgressEventArgs : EventArgs + { + /// + /// Default constructor. + /// + /// Specifies current handler index. + /// Specifies current handler name. + /// Specifies current handler progress. + /// Specifies the overall number of handlers. + public MultiTestRunFinalizationProgressEventArgs(long currentHandlerIndex, string currentHandlerName, long currentHandlerProgress, long handlersCount) + { + CurrentHandlerIndex = currentHandlerIndex; + CurrentHandlerName = currentHandlerName; + CurrentHandlerProgress = currentHandlerProgress; + HandlersCount = handlersCount; + } + + /// + /// Gets a current handler index. + /// + [DataMember] + public long CurrentHandlerIndex { get; private set; } + + /// + /// Gets a current handler name. + /// + [DataMember] + public string CurrentHandlerName { get; private set; } + + /// + /// Gets a current handler progress. + /// + [DataMember] + public long CurrentHandlerProgress { get; private set; } + + /// + /// Gets the overall number of handlers. + /// + [DataMember] + public long HandlersCount { get; private set; } + } +} diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs index 93484152da..8c00b00c60 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs @@ -13,7 +13,20 @@ public interface IMultiTestRunFinalizationEventsHandler : ITestMessageEventHandl /// /// Dispatch MultiTestRunFinalizationComplete event to listeners. /// - /// Attachments reprocessed. - void HandleMultiTestRunFinalizationComplete(ICollection attachments); + /// Finalization Complete event args. + /// Last set of processed attachment sets. + void HandleMultiTestRunFinalizationComplete(MultiTestRunFinalizationCompleteEventArgs finalizationCompleteEventArgs, IEnumerable lastChunk); + + /// + /// Dispatch FinalisedAttachments event to listeners. + /// + /// Finalised attachment sets. + void HandleFinalisedAttachments(IEnumerable attachments); + + /// + /// Dispatch MultiTestRunFinalizationProgress event to listeners. + /// + /// Finalization Progress event args. + void HandleMultiTestRunFinalizationProgress(MultiTestRunFinalizationProgressEventArgs finalizationProgressEventArgs); } } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index 6d0e187be5..783c254c95 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -762,9 +762,14 @@ private async Task SendMessageAndListenAndReportFinalizationResultAsync(IEnumera var multiTestRunFinalizationCompletePayload = this.dataSerializer.DeserializePayload(message); - eventHandler.HandleMultiTestRunFinalizationComplete(multiTestRunFinalizationCompletePayload.Attachments); + eventHandler.HandleMultiTestRunFinalizationComplete(multiTestRunFinalizationCompletePayload.FinalizationCompleteEventArgs, multiTestRunFinalizationCompletePayload.Attachments); isMultiTestRunFinalizationComplete = true; } + else if (string.Equals(MessageType.MultiTestRunFinalizationProgress, message.MessageType)) + { + var multiTestRunFinalizationProgressPayload = this.dataSerializer.DeserializePayload(message); + eventHandler.HandleMultiTestRunFinalizationProgress(multiTestRunFinalizationProgressPayload.FinalizationProgressEventArgs); + } else if (string.Equals(MessageType.TestMessage, message.MessageType)) { var testMessagePayload = this.dataSerializer.DeserializePayload(message); @@ -777,7 +782,7 @@ private async Task SendMessageAndListenAndReportFinalizationResultAsync(IEnumera { EqtTrace.Error("Aborting Test Session End Operation: {0}", exception); eventHandler.HandleLogMessage(TestMessageLevel.Error, TranslationLayerResources.AbortedMultiTestRunFinalization); - eventHandler.HandleMultiTestRunFinalizationComplete(null); + eventHandler.HandleMultiTestRunFinalizationComplete(new MultiTestRunFinalizationCompleteEventArgs(false, true, exception), null); // Earlier we were closing the connection with vstest.console in case of exceptions // Removing that code because vstest.console might be in a healthy state and letting the client diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs index 0a1b77a832..baa457c62a 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs @@ -82,5 +82,28 @@ public void HandleMultiTestRunFinalizationComplete(ICollection at this.Attachments.AddRange(attachments); } } + + public void HandleMultiTestRunFinalizationComplete(MultiTestRunFinalizationCompleteEventArgs finalizationCompleteEventArgs, IEnumerable lastChunk) + { + if (lastChunk != null) + { + this.Attachments.AddRange(lastChunk); + } + + if (finalizationCompleteEventArgs.Error != null) + { + Errors.Add(finalizationCompleteEventArgs.Error.Message); + } + } + + public void HandleFinalisedAttachments(IEnumerable attachments) + { + throw new NotImplementedException(); + } + + public void HandleMultiTestRunFinalizationProgress(MultiTestRunFinalizationProgressEventArgs finalizationProgressEventArgs) + { + throw new NotImplementedException(); + } } } diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs index 26d50e6edc..be9a766e63 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs @@ -38,10 +38,21 @@ public void EventsHandlerHandleLogMessageShouldSendTestMessage() public void EventsHandlerHandleMultiTestRunFinalizationCompleteShouldSendFinalizationCompleteMessage() { var attachments = new[] { new AttachmentSet(new System.Uri("http://www.bing.com/"), "code coverage") }; + var args = new MultiTestRunFinalizationCompleteEventArgs(false, false, null); - handler.HandleMultiTestRunFinalizationComplete(attachments); + handler.HandleMultiTestRunFinalizationComplete(args, attachments); - mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.Is(p => p.Attachments == attachments))); + mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.Is(p => p.Attachments == attachments && p.FinalizationCompleteEventArgs == args))); + } + + [TestMethod] + public void EventsHandlerHandleMultiTestRunFinalizationProgressShouldSendFinalizationProgressMessage() + { + var args = new MultiTestRunFinalizationProgressEventArgs(1, "CC", 90, 2); + + handler.HandleMultiTestRunFinalizationProgress(args); + + mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationProgress, It.Is(p => p.FinalizationProgressEventArgs == args))); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs index ba4f983854..e5b8d4d44a 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs @@ -63,8 +63,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>(c => c.Count == 0))); + VerifyCompleteEvent(false, false, false); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is(a => !a.IsAborted && !a.IsCanceled), It.Is>(c => c.Count == 0))); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(0)); mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); @@ -107,7 +109,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachmentT await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])))); + VerifyCompleteEvent(false, false, false, inputAttachments[0]); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); @@ -160,7 +163,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachmentThro await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>(c => c.Count == 1 && c.Contains(outputAttachments[0])))); + VerifyCompleteEvent(false, false, false, outputAttachments[0]); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); @@ -217,9 +221,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>( - c => c.Count == 1 && - c.Contains(inputAttachments[0])))); + VerifyCompleteEvent(true, false, true, inputAttachments[0]); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "exception message"), Times.Once); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); @@ -268,9 +271,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>( - c => c.Count == 1 && - c.Contains(inputAttachments[0])))); + VerifyCompleteEvent(false, true, false, inputAttachments[0]); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); @@ -333,11 +335,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachmentsThro await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>( - c => c.Count == 3 && - c.Contains(inputAttachments[4]) && - c.Contains(outputAttachmentsForHandler1.First()) && - c.Contains(outputAttachmentsForHandler2.First())))); + VerifyCompleteEvent(false, false, false, inputAttachments[4], outputAttachmentsForHandler1.First(), outputAttachmentsForHandler2.First()); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); @@ -409,12 +408,13 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug { try { - for (int i = 0; i < 1000; ++i) + for (int i = 0; i < 100; ++i) { Task.Delay(100).Wait(); Console.WriteLine($"Iteration: {i}"); cancellation.ThrowIfCancellationRequested(); + progress.Report(i + 1); if (i == 3) { @@ -437,9 +437,12 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug await innerTaskCompletionSource.Task; // assert - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is>( - c => c.Count == 1 && - c.Contains(inputAttachments[0])))); + VerifyCompleteEvent(false, true, false, inputAttachments[0]); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Exactly(4)); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 1)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 2)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 3)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 4)))); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Informational, "Finalization was cancelled.")); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); @@ -518,5 +521,20 @@ private void VerifyMetrics(int inputCount, int outputCount, string status = "Com mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.FinalizationState, status)); mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.TimeTakenInSecForFinalization, It.IsAny())); } + + private void VerifyCompleteEvent(bool isAborted, bool isCanceled, bool containsError, params AttachmentSet[] expectedSets) + { + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete( + It.Is(a => a.IsAborted == isAborted && a.IsCanceled == isCanceled && (a.Error != null) == containsError), + It.Is>(c => c.Count == expectedSets.Length && expectedSets.All(e => c.Contains(e))))); + } + + private bool VerifyProgressArgs(MultiTestRunFinalizationProgressEventArgs args, int progress) + { + Assert.AreEqual(1, args.CurrentHandlerIndex); + Assert.AreEqual(2, args.HandlersCount); + Assert.IsTrue(args.CurrentHandlerName.StartsWith("Castle.Proxies.ObjectProxy")); + return progress == args.CurrentHandlerProgress; + } } } diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs index c1f999f6d8..3658178a24 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs @@ -1902,7 +1902,12 @@ public async Task FinalizeTestsShouldCompleteWithZeroAttachments() var mockHandler = new Mock(); - var payload = new MultiTestRunFinalizationCompletePayload() { Attachments = new AttachmentSet[0] }; + var payload = new MultiTestRunFinalizationCompletePayload() + { + FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(false, false, null), + Attachments = new AttachmentSet[0] + }; + var finalizationComplete = new Message() { MessageType = MessageType.MultiTestRunFinalizationComplete, @@ -1914,7 +1919,7 @@ public async Task FinalizeTestsShouldCompleteWithZeroAttachments() mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is>(a => a.Count == 0)), Times.Once, "Discovery Complete must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is(a => !a.IsAborted && !a.IsCanceled && a.Error == null), It.Is>(a => a.Count == 0)), Times.Once, "Finalization Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never, "TestMessage event must not be called"); } @@ -1926,7 +1931,8 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachment() var mockHandler = new Mock(); var payload = new MultiTestRunFinalizationCompletePayload() - { + { + FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(true, true, new Exception("msg")), Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } }; var finalizationComplete = new Message() @@ -1940,7 +1946,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachment() mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is>(a => a.Count == 1)), Times.Once, "Discovery Complete must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is(a => a.IsAborted && a.IsCanceled && a.Error != null), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never, "TestMessage event must not be called"); } @@ -1953,8 +1959,10 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndTestMessage() var payload = new MultiTestRunFinalizationCompletePayload() { + FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(false, false, null), Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } }; + var finalizationComplete = new Message() { MessageType = MessageType.MultiTestRunFinalizationComplete, @@ -1972,10 +1980,53 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndTestMessage() mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is>(a => a.Count == 1)), Times.Once, "Discovery Complete must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Once, "TestMessage event must be called"); } + [TestMethod] + public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndProgressMessage() + { + await this.InitializeCommunicationAsync(); + + var mockHandler = new Mock(); + + var completePayload = new MultiTestRunFinalizationCompletePayload() + { + FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(false, false, null), + Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } + }; + + var finalizationComplete = new Message() + { + MessageType = MessageType.MultiTestRunFinalizationComplete, + Payload = JToken.FromObject(completePayload) + }; + + var progressPayload = new MultiTestRunFinalizationProgressPayload() + { + FinalizationProgressEventArgs = new MultiTestRunFinalizationProgressEventArgs(1, "cc", 50, 2) + }; + + var finalizationProgress = new Message() + { + MessageType = MessageType.MultiTestRunFinalizationProgress, + Payload = JToken.FromObject(progressPayload) + }; + this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationProgress)); + + mockHandler.Setup(mh => mh.HandleMultiTestRunFinalizationProgress(It.IsAny())).Callback( + () => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete))); + + await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, false, mockHandler.Object, CancellationToken.None); + + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationProgress(It.Is(a => a.CurrentHandlerIndex == 1 && a.CurrentHandlerName == "cc" && a.CurrentHandlerProgress == 50 && a.HandlersCount == 2)), Times.Once, "Finalization Progress must be called"); + mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Never); + } + [TestMethod] public async Task FinalizeTestsShouldSendCancelMessageIfCancellationTokenCancelled() { @@ -2009,7 +2060,7 @@ public async Task FinalizeTestsShouldSendCancelMessageIfCancellationTokenCancell mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel)); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is>(a => a.Count == 1)), Times.Once, "Discovery Complete must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Once, "TestMessage event must be called"); } @@ -2039,7 +2090,7 @@ public async Task FinalizeTestsShouldSendCancelMessageIfCancellationTokenCancell mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel)); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is>(a => a.Count == 1)), Times.Once, "Discovery Complete must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Finalizationomplete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Never, "TestMessage event must be called"); } @@ -2051,7 +2102,7 @@ public async Task FinalizeTestsShouldAbortOnExceptionInSendMessage() await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, false, mockHandler.Object, CancellationToken.None); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(null), Times.Once, "Discovery Complete must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is(a => !a.IsCanceled && a.IsAborted && a.Error is IOException), null), Times.Once, "Finalization Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Error, It.IsAny()), Times.Once, "TestMessage event must be called"); this.mockCommunicationManager.Verify(cm => cm.StopServer(), Times.Never); } From 6c308b595fef821d04575d5890d2b82b9d8e1e9f Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Mon, 22 Jun 2020 18:30:27 +0200 Subject: [PATCH 45/58] acceptance tests changes --- .../MultiTestRunFinalizationManager.cs | 23 ++-- .../CodeCoverageDataAttachmentsHandler.cs | 7 +- .../CodeCoverageTests.cs | 127 +++++++++++++++++- .../MultiTestRunFinalizationEventHandler.cs | 18 +-- .../MultiTestRunFinalizationManagerTests.cs | 61 +++++++++ 5 files changed, 211 insertions(+), 25 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index 5e7d14b69d..0d64c60b39 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -72,12 +72,12 @@ private async Task> InternalFinalizeMultiTestRunAsync( if (completedTask == task) { - return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, false, null), await task, eventHandler); + return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, false, null), await task, stopwatch, eventHandler); } else { eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Informational, "Finalization was cancelled."); - return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, false, null), attachments, eventHandler); + return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, false, null), attachments, stopwatch, eventHandler); } } } @@ -87,19 +87,14 @@ private async Task> InternalFinalizeMultiTestRunAsync( { EqtTrace.Warning("MultiTestRunFinalizationManager: operation was cancelled."); } - return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, false, null), attachments, eventHandler); + return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, false, null), attachments, stopwatch, eventHandler); } catch (Exception e) { EqtTrace.Error("MultiTestRunFinalizationManager: Exception in FinalizeMultiTestRunAsync: " + e); eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); - return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, true, e), attachments, eventHandler); - } - finally - { - stopwatch.Stop(); - requestData.MetricsCollection.Add(TelemetryDataConstants.TimeTakenInSecForFinalization, stopwatch.Elapsed.TotalSeconds); + return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, true, e), attachments, stopwatch, eventHandler); } } @@ -111,6 +106,7 @@ private Collection ProcessAttachments(Collection a { IDataCollectorAttachments dataCollectorAttachmentsHandler = dataCollectorAttachmentsHandlers[i]; string attachmentsHandlerName = dataCollectorAttachmentsHandler.GetType().FullName; + int attachmentsHandlerIndex = i + 1; Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); if (attachementUri != null) @@ -125,8 +121,10 @@ private Collection ProcessAttachments(Collection a IProgress progressReporter = new Progress((int progress) => eventsHandler?.HandleMultiTestRunFinalizationProgress( - new MultiTestRunFinalizationProgressEventArgs(i + 1, attachmentsHandlerName, progress, dataCollectorAttachmentsHandlers.Length))); + new MultiTestRunFinalizationProgressEventArgs(attachmentsHandlerIndex, attachmentsHandlerName, progress, dataCollectorAttachmentsHandlers.Length))); + ICollection processedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), progressReporter, cancellationToken); + foreach (var attachment in processedAttachments) { attachments.Add(attachment); @@ -138,12 +136,15 @@ private Collection ProcessAttachments(Collection a return attachments; } - private Collection FinalizeOperation(IRequestData requestData, MultiTestRunFinalizationCompleteEventArgs completeArgs, Collection attachments, IMultiTestRunFinalizationEventsHandler eventHandler) + private Collection FinalizeOperation(IRequestData requestData, MultiTestRunFinalizationCompleteEventArgs completeArgs, Collection attachments, Stopwatch stopwatch, IMultiTestRunFinalizationEventsHandler eventHandler) { testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); requestData.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsAfterFinalization, attachments.Count); requestData.MetricsCollection.Add(TelemetryDataConstants.FinalizationState, completeArgs.IsAborted ? FinalizationFailed : completeArgs.IsCanceled ? FinalizationCanceled : FinalizationCompleted); + stopwatch.Stop(); + requestData.MetricsCollection.Add(TelemetryDataConstants.TimeTakenInSecForFinalization, stopwatch.Elapsed.TotalSeconds); + completeArgs.Metrics = requestData.MetricsCollection.Metrics; eventHandler?.HandleMultiTestRunFinalizationComplete(completeArgs, attachments); diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index 90ab94fd56..a603bd0569 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -79,12 +79,13 @@ private string MergeCodeCoverageFiles(IList files, IProgress progre for (int i = 1; i < files.Count; i++) { cancellationToken.ThrowIfCancellationRequested(); - methodInfo.Invoke(null, new object[] { files[i], outputfileName, fileName, true }); + progressReporter?.Report(100 * i / files.Count); cancellationToken.ThrowIfCancellationRequested(); - File.Copy(fileName, outputfileName, true); + methodInfo.Invoke(null, new object[] { files[i], outputfileName, fileName, true }); - progressReporter?.Report(100 * i / files.Count); + cancellationToken.ThrowIfCancellationRequested(); + File.Copy(fileName, outputfileName, true); } File.Delete(fileName); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs index 6818593723..e8848d57f4 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -3,8 +3,10 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests { + using Castle.Core.Internal; using Microsoft.TestPlatform.TestUtilities; using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; + using Microsoft.VisualStudio.TestPlatform.Common.Telemetry; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; @@ -109,6 +111,66 @@ public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.multiTestRunFinalizationEventHandler.Attachments.Count); AssertCoverageResults(this.multiTestRunFinalizationEventHandler.Attachments); + + Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsAborted); + Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); + Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); + + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 2 : 0, multiTestRunFinalizationEventHandler.ProgressArgs.Count); + for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) + { + VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; + Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); + Assert.AreEqual("Microsoft.VisualStudio.TestPlatform.Utilities.CodeCoverageDataAttachmentsHandler", progressArgs.CurrentHandlerName); + Assert.AreEqual(1, progressArgs.HandlersCount); + Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentHandlerProgress); + } + + Assert.AreEqual("Completed", multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.FinalizationState]); + Assert.AreEqual(2L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsSentForFinalization]); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1L : 2L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsAfterFinalization]); + Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForFinalization)); + } + + [TestMethod] + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public async Task TestRunWithCodeCoverageAndFinalizationNoMetrics(RunnerInfo runnerInfo) + { + // arrange + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + this.Setup(); + + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(1), this.runEventHandler); + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(1), this.runEventHandler); + + Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + Assert.AreEqual(2, this.runEventHandler.Attachments.Count); + + // act + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, false, multiTestRunFinalizationEventHandler, CancellationToken.None); + + // Assert + multiTestRunFinalizationEventHandler.EnsureSuccess(); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.multiTestRunFinalizationEventHandler.Attachments.Count); + + AssertCoverageResults(this.multiTestRunFinalizationEventHandler.Attachments); + + Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsAborted); + Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); + Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); + + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 2 : 0, multiTestRunFinalizationEventHandler.ProgressArgs.Count); + for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) + { + VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; + Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); + Assert.AreEqual("Microsoft.VisualStudio.TestPlatform.Utilities.CodeCoverageDataAttachmentsHandler", progressArgs.CurrentHandlerName); + Assert.AreEqual(1, progressArgs.HandlersCount); + Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentHandlerProgress); + } + + Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.IsNullOrEmpty()); } [TestMethod] @@ -135,6 +197,25 @@ public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerI Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 3, this.multiTestRunFinalizationEventHandler.Attachments.Count); AssertCoverageResults(this.multiTestRunFinalizationEventHandler.Attachments); + + Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsAborted); + Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); + Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); + + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 3 : 0, multiTestRunFinalizationEventHandler.ProgressArgs.Count); + for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) + { + VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; + Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); + Assert.AreEqual("Microsoft.VisualStudio.TestPlatform.Utilities.CodeCoverageDataAttachmentsHandler", progressArgs.CurrentHandlerName); + Assert.AreEqual(1, progressArgs.HandlersCount); + Assert.AreEqual(i == 0 ? 33 : i == 1 ? 66 : 100, progressArgs.CurrentHandlerProgress); + } + + Assert.AreEqual("Completed", multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.FinalizationState]); + Assert.AreEqual(3L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsSentForFinalization]); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1L : 3L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsAfterFinalization]); + Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForFinalization)); } [TestMethod] @@ -146,6 +227,8 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); this.Setup(); + if (!testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework)) return; + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(1), this.runEventHandler); Assert.AreEqual(3, this.runEventHandler.TestResults.Count); Assert.AreEqual(1, this.runEventHandler.Attachments.Count); @@ -155,7 +238,20 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run CancellationTokenSource cts = new CancellationTokenSource(); Task finalization = this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(attachments, true, multiTestRunFinalizationEventHandler, cts.Token); - await Task.Delay(TimeSpan.FromSeconds(1)); + + while (true) + { + try + { + if (multiTestRunFinalizationEventHandler.ProgressArgs.Count >= 3) + break; + } + catch + { + // ignore + } + await Task.Delay(100); + } // act cts.Cancel(); @@ -164,7 +260,34 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run await finalization; multiTestRunFinalizationEventHandler.EnsureSuccess(); - Assert.AreEqual(1000, this.multiTestRunFinalizationEventHandler.Attachments.Count); + Assert.AreEqual(1000, this.multiTestRunFinalizationEventHandler.Attachments.Count); + + Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsAborted); + Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); + Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); + + Assert.IsTrue((testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 3 : 0) <= multiTestRunFinalizationEventHandler.ProgressArgs.Count); + for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) + { + VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; + Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); + Assert.AreEqual("Microsoft.VisualStudio.TestPlatform.Utilities.CodeCoverageDataAttachmentsHandler", progressArgs.CurrentHandlerName); + Assert.AreEqual(1, progressArgs.HandlersCount); + + if (i == 5) + { + Assert.AreEqual(0, progressArgs.CurrentHandlerProgress); + } + else if (i == 15) + { + Assert.AreEqual(1, progressArgs.CurrentHandlerProgress); + } + } + + Assert.AreEqual("Canceled", multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.FinalizationState]); + Assert.AreEqual(1000L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsSentForFinalization]); + Assert.AreEqual(1000L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsAfterFinalization]); + Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForFinalization)); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs index baa457c62a..0c867da64e 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs @@ -13,15 +13,11 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests /// public class MultiTestRunFinalizationEventHandler : IMultiTestRunFinalizationEventsHandler { - /// - /// Gets the attachments. - /// public List Attachments { get; private set; } - /// - /// Gets the metrics. - /// - public IDictionary Metrics { get; private set; } + public MultiTestRunFinalizationCompleteEventArgs CompleteArgs { get; private set; } + + public List ProgressArgs { get; private set; } /// /// Gets the log message. @@ -39,6 +35,7 @@ public MultiTestRunFinalizationEventHandler() { this.Errors = new List(); this.Attachments = new List(); + this.ProgressArgs = new List(); } public void EnsureSuccess() @@ -53,7 +50,8 @@ public void HandleLogMessage(TestMessageLevel level, string message) { this.LogMessage = message; this.TestMessageLevel = level; - if (level == TestMessageLevel.Error) { + if (level == TestMessageLevel.Error) + { this.Errors.Add(message); } } @@ -94,6 +92,8 @@ public void HandleMultiTestRunFinalizationComplete(MultiTestRunFinalizationCompl { Errors.Add(finalizationCompleteEventArgs.Error.Message); } + + CompleteArgs = finalizationCompleteEventArgs; } public void HandleFinalisedAttachments(IEnumerable attachments) @@ -103,7 +103,7 @@ public void HandleFinalisedAttachments(IEnumerable attachments) public void HandleMultiTestRunFinalizationProgress(MultiTestRunFinalizationProgressEventArgs finalizationProgressEventArgs) { - throw new NotImplementedException(); + ProgressArgs.Add(finalizationProgressEventArgs); } } } diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs index e5b8d4d44a..8eaedf817d 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs @@ -511,6 +511,62 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe VerifyMetrics(1, 1, "Canceled"); } + [TestMethod] + public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEvents_IfHandlersPropagesEvents() + { + // arrange + List inputAttachments = new List + { + new AttachmentSet(new Uri(uri1), "uri1_input"), + new AttachmentSet(new Uri(uri2), "uri2_input") + }; + + List outputAttachments1 = new List + { + new AttachmentSet(new Uri(uri1), "uri1_output") + }; + + List outputAttachments2 = new List + { + new AttachmentSet(new Uri(uri2), "uri2_output") + }; + + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns((ICollection i1, IProgress progress, CancellationToken cancellation) => + { + progress.Report(25); + progress.Report(50); + progress.Report(75); + progress.Report(100); + return outputAttachments1; + }); + + mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns((ICollection i1, IProgress progress, CancellationToken cancellation) => + { + progress.Report(50); + progress.Report(100); + return outputAttachments2; + }); + + // act + await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, CancellationToken.None); + + // assert + VerifyCompleteEvent(false, false, false, outputAttachments1[0], outputAttachments2[0]); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Exactly(6)); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 25)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 50)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 75)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 100)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 50)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 100)))); + mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), CancellationToken.None)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[1])), It.IsAny>(), CancellationToken.None)); + + VerifyMetrics(2, 2, "Completed"); + } + private void VerifyMetrics(int inputCount, int outputCount, string status = "Completed") { mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(inputCount)); @@ -536,5 +592,10 @@ private bool VerifyProgressArgs(MultiTestRunFinalizationProgressEventArgs args, Assert.IsTrue(args.CurrentHandlerName.StartsWith("Castle.Proxies.ObjectProxy")); return progress == args.CurrentHandlerProgress; } + + private bool VerifyProgressArgsForTwoHandlers(MultiTestRunFinalizationProgressEventArgs args, long handlerIndex, long progress) + { + return progress == args.CurrentHandlerProgress && args.CurrentHandlerIndex == handlerIndex && args.CurrentHandlerName.StartsWith("Castle.Proxies.ObjectProxy") && args.HandlersCount == 2; + } } } From 4f1ede1b6499e9916ec51af4a99aa8b4a6ea2374 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Mon, 22 Jun 2020 21:41:33 +0200 Subject: [PATCH 46/58] More changes --- .../MultiTestRunFinalizationManager.cs | 45 ++++-- ...ltiTestRunFinalizationCompleteEventArgs.cs | 10 +- ...ltiTestRunFinalizationProgressEventArgs.cs | 10 +- .../IDataCollectorAttachments.cs | 3 +- .../CodeCoverageDataAttachmentsHandler.cs | 29 ++-- .../VsTestConsoleRequestSender.cs | 2 +- .../CodeCoverageTests.cs | 23 +-- ...tiTestRunFinalizationEventsHandlerTests.cs | 4 +- .../MultiTestRunFinalizationManagerTests.cs | 131 +++++++++--------- ...CodeCoverageDataAttachmentsHandlerTests.cs | 28 +++- .../VsTestConsoleRequestSenderTests.cs | 18 +-- 11 files changed, 185 insertions(+), 118 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index 0d64c60b39..af23cbcaee 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -14,6 +14,7 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization { @@ -72,12 +73,12 @@ private async Task> InternalFinalizeMultiTestRunAsync( if (completedTask == task) { - return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, false, null), await task, stopwatch, eventHandler); + return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, null), await task, stopwatch, eventHandler); } else { eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Informational, "Finalization was cancelled."); - return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, false, null), attachments, stopwatch, eventHandler); + return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, null), attachments, stopwatch, eventHandler); } } } @@ -87,14 +88,14 @@ private async Task> InternalFinalizeMultiTestRunAsync( { EqtTrace.Warning("MultiTestRunFinalizationManager: operation was cancelled."); } - return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, false, null), attachments, stopwatch, eventHandler); + return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, null), attachments, stopwatch, eventHandler); } catch (Exception e) { EqtTrace.Error("MultiTestRunFinalizationManager: Exception in FinalizeMultiTestRunAsync: " + e); eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); - return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, true, e), attachments, stopwatch, eventHandler); + return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, e), attachments, stopwatch, eventHandler); } } @@ -102,10 +103,11 @@ private Collection ProcessAttachments(Collection a { if (attachments == null || !attachments.Any()) return attachments; + var logger = CreateMessageLogger(eventsHandler); + for (int i = 0; i < dataCollectorAttachmentsHandlers.Length; i++) { IDataCollectorAttachments dataCollectorAttachmentsHandler = dataCollectorAttachmentsHandlers[i]; - string attachmentsHandlerName = dataCollectorAttachmentsHandler.GetType().FullName; int attachmentsHandlerIndex = i + 1; Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); @@ -121,9 +123,9 @@ private Collection ProcessAttachments(Collection a IProgress progressReporter = new Progress((int progress) => eventsHandler?.HandleMultiTestRunFinalizationProgress( - new MultiTestRunFinalizationProgressEventArgs(attachmentsHandlerIndex, attachmentsHandlerName, progress, dataCollectorAttachmentsHandlers.Length))); + new MultiTestRunFinalizationProgressEventArgs(attachmentsHandlerIndex, dataCollectorAttachmentsHandler.GetExtensionUri(), progress, dataCollectorAttachmentsHandlers.Length))); - ICollection processedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), progressReporter, cancellationToken); + ICollection processedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), progressReporter, logger, cancellationToken); foreach (var attachment in processedAttachments) { @@ -140,7 +142,7 @@ private Collection FinalizeOperation(IRequestData requestData, Mu { testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); requestData.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsAfterFinalization, attachments.Count); - requestData.MetricsCollection.Add(TelemetryDataConstants.FinalizationState, completeArgs.IsAborted ? FinalizationFailed : completeArgs.IsCanceled ? FinalizationCanceled : FinalizationCompleted); + requestData.MetricsCollection.Add(TelemetryDataConstants.FinalizationState, completeArgs.Error != null ? FinalizationFailed : completeArgs.IsCanceled ? FinalizationCanceled : FinalizationCompleted); stopwatch.Stop(); requestData.MetricsCollection.Add(TelemetryDataConstants.TimeTakenInSecForFinalization, stopwatch.Elapsed.TotalSeconds); @@ -150,5 +152,32 @@ private Collection FinalizeOperation(IRequestData requestData, Mu return attachments; } + + private IMessageLogger CreateMessageLogger(IMultiTestRunFinalizationEventsHandler eventsHandler) + { + return eventsHandler != null ? (IMessageLogger)new FinalizationMessageLogger(eventsHandler) : new NullMessageLogger(); + } + + private class FinalizationMessageLogger : IMessageLogger + { + private readonly IMultiTestRunFinalizationEventsHandler eventsHandler; + + public FinalizationMessageLogger(IMultiTestRunFinalizationEventsHandler eventsHandler) + { + this.eventsHandler = eventsHandler ?? throw new ArgumentNullException(nameof(eventsHandler)); + } + + public void SendMessage(TestMessageLevel testMessageLevel, string message) + { + eventsHandler.HandleLogMessage(testMessageLevel, message); + } + } + + private class NullMessageLogger : IMessageLogger + { + public void SendMessage(TestMessageLevel testMessageLevel, string message) + { + } + } } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs index db61554c9d..4f73073caa 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs @@ -14,21 +14,13 @@ public class MultiTestRunFinalizationCompleteEventArgs : EventArgs /// Default constructor. /// /// Specifies whether the finalization is canceled. - /// Specifies whether the finalization is aborted. /// Specifies the error encountered during the execution of the finalization. - public MultiTestRunFinalizationCompleteEventArgs(bool isCanceled, bool isAborted, Exception error) + public MultiTestRunFinalizationCompleteEventArgs(bool isCanceled, Exception error) { this.IsCanceled = isCanceled; - this.IsAborted = isAborted; this.Error = error; } - /// - /// Gets a value indicating whether the finalization is aborted or not. - /// - [DataMember] - public bool IsAborted { get; private set; } - /// /// Gets a value indicating whether the finalization is canceled or not. /// diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs index 760987ec4a..529be7baaf 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs @@ -13,13 +13,13 @@ public class MultiTestRunFinalizationProgressEventArgs : EventArgs /// Default constructor. /// /// Specifies current handler index. - /// Specifies current handler name. + /// Specifies current handler Uri. /// Specifies current handler progress. /// Specifies the overall number of handlers. - public MultiTestRunFinalizationProgressEventArgs(long currentHandlerIndex, string currentHandlerName, long currentHandlerProgress, long handlersCount) + public MultiTestRunFinalizationProgressEventArgs(long currentHandlerIndex, Uri currentHandlerUri, long currentHandlerProgress, long handlersCount) { CurrentHandlerIndex = currentHandlerIndex; - CurrentHandlerName = currentHandlerName; + CurrentHandlerUri = currentHandlerUri; CurrentHandlerProgress = currentHandlerProgress; HandlersCount = handlersCount; } @@ -31,10 +31,10 @@ public MultiTestRunFinalizationProgressEventArgs(long currentHandlerIndex, strin public long CurrentHandlerIndex { get; private set; } /// - /// Gets a current handler name. + /// Gets a current handler URI. /// [DataMember] - public string CurrentHandlerName { get; private set; } + public Uri CurrentHandlerUri { get; private set; } /// /// Gets a current handler progress. diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs index 4c1d2bdabf..cd9124743b 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs @@ -3,6 +3,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection { + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using System; using System.Collections.Generic; using System.Threading; @@ -25,7 +26,7 @@ public interface IDataCollectorAttachments /// Progress reporter. Accepts integers from 0 to 100 /// Cancellation token /// Gets the attachment set after Test Run Session - ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, IProgress progressReporter, CancellationToken cancellationToken); + ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, IProgress progressReporter, IMessageLogger logger, CancellationToken cancellationToken); /// /// Gets the attachment Uri, which is handled by current Collector diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index a603bd0569..d31fda0a56 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -9,10 +9,10 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities using System.IO; using System.Linq; using System.Reflection; - using System.Resources; using System.Threading; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; public class CodeCoverageDataAttachmentsHandler : IDataCollectorAttachments @@ -34,10 +34,10 @@ public Uri GetExtensionUri() public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments) { - return HandleDataCollectionAttachmentSets(dataCollectionAttachments, null, CancellationToken.None); + return HandleDataCollectionAttachmentSets(dataCollectionAttachments, null, null, CancellationToken.None); } - public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, IProgress progressReporter, CancellationToken cancellationToken) + public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, IProgress progressReporter, IMessageLogger logger, CancellationToken cancellationToken) { if (dataCollectionAttachments != null && dataCollectionAttachments.Any()) { @@ -60,10 +60,15 @@ public ICollection HandleDataCollectionAttachmentSets(ICollection private string MergeCodeCoverageFiles(IList files, IProgress progressReporter, CancellationToken cancellationToken) { - string fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + CoverageFileExtension); + if(files.Count == 1) + { + return files[0]; + } + + string tempFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + CoverageFileExtension); string outputfileName = files[0]; - File.Create(fileName).Dispose(); + File.Create(tempFileName).Dispose(); var assemblyPath = Path.Combine(Path.GetDirectoryName(typeof(CodeCoverageDataAttachmentsHandler).GetTypeInfo().Assembly.GetAssemblyLocation()), CodeCoverageAnalysisAssemblyName + ".dll"); try @@ -76,19 +81,27 @@ private string MergeCodeCoverageFiles(IList files, IProgress progre if (methodInfo != null) { + IList filesToDelete = new List(files.Count) { tempFileName }; + for (int i = 1; i < files.Count; i++) { cancellationToken.ThrowIfCancellationRequested(); progressReporter?.Report(100 * i / files.Count); cancellationToken.ThrowIfCancellationRequested(); - methodInfo.Invoke(null, new object[] { files[i], outputfileName, fileName, true }); + methodInfo.Invoke(null, new object[] { files[i], outputfileName, tempFileName, true }); cancellationToken.ThrowIfCancellationRequested(); - File.Copy(fileName, outputfileName, true); + File.Copy(tempFileName, outputfileName, true); + + filesToDelete.Add(files[i]); } - File.Delete(fileName); + cancellationToken.ThrowIfCancellationRequested(); + foreach (string fileName in filesToDelete) + { + File.Delete(fileName); + } } progressReporter?.Report(100); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index 783c254c95..556c875d17 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -782,7 +782,7 @@ private async Task SendMessageAndListenAndReportFinalizationResultAsync(IEnumera { EqtTrace.Error("Aborting Test Session End Operation: {0}", exception); eventHandler.HandleLogMessage(TestMessageLevel.Error, TranslationLayerResources.AbortedMultiTestRunFinalization); - eventHandler.HandleMultiTestRunFinalizationComplete(new MultiTestRunFinalizationCompleteEventArgs(false, true, exception), null); + eventHandler.HandleMultiTestRunFinalizationComplete(new MultiTestRunFinalizationCompleteEventArgs(false, exception), null); // Earlier we were closing the connection with vstest.console in case of exceptions // Removing that code because vstest.console might be in a healthy state and letting the client diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs index e8848d57f4..8030f48881 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -112,7 +112,6 @@ public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) AssertCoverageResults(this.multiTestRunFinalizationEventHandler.Attachments); - Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsAborted); Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); @@ -121,7 +120,7 @@ public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); - Assert.AreEqual("Microsoft.VisualStudio.TestPlatform.Utilities.CodeCoverageDataAttachmentsHandler", progressArgs.CurrentHandlerName); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); Assert.AreEqual(1, progressArgs.HandlersCount); Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentHandlerProgress); } @@ -130,6 +129,9 @@ public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) Assert.AreEqual(2L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsSentForFinalization]); Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1L : 2L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsAfterFinalization]); Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForFinalization)); + + Assert.IsTrue(File.Exists(runEventHandler.Attachments.First().Attachments.First().Uri.LocalPath)); + Assert.IsTrue(File.Exists(runEventHandler.Attachments.Last().Attachments.First().Uri.LocalPath) != testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework)); } [TestMethod] @@ -156,7 +158,6 @@ public async Task TestRunWithCodeCoverageAndFinalizationNoMetrics(RunnerInfo run AssertCoverageResults(this.multiTestRunFinalizationEventHandler.Attachments); - Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsAborted); Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); @@ -165,12 +166,15 @@ public async Task TestRunWithCodeCoverageAndFinalizationNoMetrics(RunnerInfo run { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); - Assert.AreEqual("Microsoft.VisualStudio.TestPlatform.Utilities.CodeCoverageDataAttachmentsHandler", progressArgs.CurrentHandlerName); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); Assert.AreEqual(1, progressArgs.HandlersCount); Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentHandlerProgress); } Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.IsNullOrEmpty()); + + Assert.IsTrue(File.Exists(runEventHandler.Attachments.First().Attachments.First().Uri.LocalPath)); + Assert.IsTrue(File.Exists(runEventHandler.Attachments.Last().Attachments.First().Uri.LocalPath) != testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework)); } [TestMethod] @@ -198,7 +202,6 @@ public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerI AssertCoverageResults(this.multiTestRunFinalizationEventHandler.Attachments); - Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsAborted); Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); @@ -207,7 +210,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerI { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); - Assert.AreEqual("Microsoft.VisualStudio.TestPlatform.Utilities.CodeCoverageDataAttachmentsHandler", progressArgs.CurrentHandlerName); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); Assert.AreEqual(1, progressArgs.HandlersCount); Assert.AreEqual(i == 0 ? 33 : i == 1 ? 66 : 100, progressArgs.CurrentHandlerProgress); } @@ -216,6 +219,9 @@ public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerI Assert.AreEqual(3L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsSentForFinalization]); Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1L : 3L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsAfterFinalization]); Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForFinalization)); + + Assert.IsTrue(File.Exists(runEventHandler.Attachments.First().Attachments.First().Uri.LocalPath)); + Assert.IsTrue(File.Exists(runEventHandler.Attachments.Last().Attachments.First().Uri.LocalPath) != testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework)); } [TestMethod] @@ -262,7 +268,6 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run Assert.AreEqual(1000, this.multiTestRunFinalizationEventHandler.Attachments.Count); - Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsAborted); Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); @@ -271,7 +276,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); - Assert.AreEqual("Microsoft.VisualStudio.TestPlatform.Utilities.CodeCoverageDataAttachmentsHandler", progressArgs.CurrentHandlerName); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); Assert.AreEqual(1, progressArgs.HandlersCount); if (i == 5) @@ -288,6 +293,8 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run Assert.AreEqual(1000L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsSentForFinalization]); Assert.AreEqual(1000L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsAfterFinalization]); Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForFinalization)); + + Assert.IsTrue(File.Exists(runEventHandler.Attachments.First().Attachments.First().Uri.LocalPath)); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs index be9a766e63..a15f47e09e 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs @@ -38,7 +38,7 @@ public void EventsHandlerHandleLogMessageShouldSendTestMessage() public void EventsHandlerHandleMultiTestRunFinalizationCompleteShouldSendFinalizationCompleteMessage() { var attachments = new[] { new AttachmentSet(new System.Uri("http://www.bing.com/"), "code coverage") }; - var args = new MultiTestRunFinalizationCompleteEventArgs(false, false, null); + var args = new MultiTestRunFinalizationCompleteEventArgs(false, null); handler.HandleMultiTestRunFinalizationComplete(args, attachments); @@ -48,7 +48,7 @@ public void EventsHandlerHandleMultiTestRunFinalizationCompleteShouldSendFinaliz [TestMethod] public void EventsHandlerHandleMultiTestRunFinalizationProgressShouldSendFinalizationProgressMessage() { - var args = new MultiTestRunFinalizationProgressEventArgs(1, "CC", 90, 2); + var args = new MultiTestRunFinalizationProgressEventArgs(1, new System.Uri("http://www.bing.com/"), 90, 2); handler.HandleMultiTestRunFinalizationProgress(args); diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs index 8eaedf817d..70ceea583b 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs @@ -63,16 +63,16 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - VerifyCompleteEvent(false, false, false); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is(a => !a.IsAborted && !a.IsCanceled), It.Is>(c => c.Count == 0))); + VerifyCompleteEvent(false, false); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is(a => !a.IsCanceled), It.Is>(c => c.Count == 0))); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(0)); mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(0, 0); } @@ -90,8 +90,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNoAttachments_IfNoAttach Assert.AreEqual(0, result.Count); mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(0, 0); } @@ -109,13 +109,13 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachmentT await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - VerifyCompleteEvent(false, false, false, inputAttachments[0]); + VerifyCompleteEvent(false, false, inputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1); } @@ -137,8 +137,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachment_ Assert.IsTrue(result.Contains(inputAttachments[0])); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1); } @@ -157,19 +157,19 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachmentThro new AttachmentSet(new Uri(uri1), "uri1_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns(outputAttachments); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachments); // act await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - VerifyCompleteEvent(false, false, false, outputAttachments[0]); + VerifyCompleteEvent(false, false, outputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1); } @@ -188,7 +188,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachment_IfR new AttachmentSet(new Uri(uri1), "uri1_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns(outputAttachments); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachments); // act var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); @@ -200,8 +200,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachment_IfR mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(1)); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1); } @@ -215,19 +215,19 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug new AttachmentSet(new Uri(uri1), "uri1_input") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Throws(new Exception("exception message")); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Throws(new Exception("exception message")); // act await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - VerifyCompleteEvent(true, false, true, inputAttachments[0]); + VerifyCompleteEvent(false, true, inputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "exception message"), Times.Once); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Failed"); } @@ -241,7 +241,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfRel new AttachmentSet(new Uri(uri1), "uri1_input") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Throws(new Exception("exception message")); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Throws(new Exception("exception message")); // act var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); @@ -251,8 +251,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfRel Assert.IsTrue(result.Contains(inputAttachments[0])); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Failed"); } @@ -271,12 +271,12 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - VerifyCompleteEvent(false, true, false, inputAttachments[0]); + VerifyCompleteEvent(true, false, inputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Canceled"); } @@ -299,8 +299,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe Assert.IsTrue(result.Contains(inputAttachments[0])); mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Canceled"); } @@ -328,20 +328,20 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachmentsThro new AttachmentSet(new Uri(uri2), "uri2_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler1); - mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler2); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachmentsForHandler1); + mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachmentsForHandler2); // act await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert - VerifyCompleteEvent(false, false, false, inputAttachments[4], outputAttachmentsForHandler1.First(), outputAttachmentsForHandler2.First()); + VerifyCompleteEvent(false, false, inputAttachments[4], outputAttachmentsForHandler1.First(), outputAttachmentsForHandler2.First()); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), cancellationTokenSource.Token)); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); VerifyMetrics(5, 3); } @@ -369,8 +369,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachments_IfR new AttachmentSet(new Uri(uri2), "uri2_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler1); - mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns(outputAttachmentsForHandler2); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachmentsForHandler1); + mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachmentsForHandler2); // act var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); @@ -382,8 +382,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachments_IfR Assert.IsTrue(result.Contains(outputAttachmentsForHandler2[0])); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), cancellationTokenSource.Token)); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); VerifyMetrics(5, 3); } @@ -404,7 +404,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug var innerTaskCompletionSource = new TaskCompletionSource(); - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns((ICollection i1, IProgress progress, CancellationToken cancellation) => + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => { try { @@ -412,6 +412,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug { Task.Delay(100).Wait(); Console.WriteLine($"Iteration: {i}"); + logger.SendMessage(TestMessageLevel.Informational, $"Iteration: {i}"); cancellation.ThrowIfCancellationRequested(); progress.Report(i + 1); @@ -437,7 +438,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug await innerTaskCompletionSource.Task; // assert - VerifyCompleteEvent(false, true, false, inputAttachments[0]); + VerifyCompleteEvent(true, false, inputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Exactly(4)); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 1)))); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 2)))); @@ -446,8 +447,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Informational, "Finalization was cancelled.")); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Canceled"); } @@ -468,7 +469,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe var innerTaskCompletionSource = new TaskCompletionSource(); - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns((ICollection i1, IProgress p, CancellationToken cancellation) => + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress p, IMessageLogger logger, CancellationToken cancellation) => { try { @@ -476,6 +477,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe { Task.Delay(100).Wait(); Console.WriteLine($"Iteration: {i}"); + logger.SendMessage(TestMessageLevel.Informational, $"Iteration: {i}"); cancellation.ThrowIfCancellationRequested(); @@ -505,8 +507,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe Assert.IsTrue(result.Contains(inputAttachments[0])); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Canceled"); } @@ -531,18 +533,20 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven new AttachmentSet(new Uri(uri2), "uri2_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns((ICollection i1, IProgress progress, CancellationToken cancellation) => + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => { progress.Report(25); progress.Report(50); progress.Report(75); + logger.SendMessage(TestMessageLevel.Error, "error"); progress.Report(100); return outputAttachments1; }); - mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny())).Returns((ICollection i1, IProgress progress, CancellationToken cancellation) => + mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => { progress.Report(50); + logger.SendMessage(TestMessageLevel.Informational, "info"); progress.Report(100); return outputAttachments2; }); @@ -551,18 +555,21 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, CancellationToken.None); // assert - VerifyCompleteEvent(false, false, false, outputAttachments1[0], outputAttachments2[0]); + VerifyCompleteEvent(false, false, outputAttachments1[0], outputAttachments2[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Exactly(6)); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 25)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 50)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 75)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 100)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 50)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 100)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 25, uri1)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 50, uri1)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 75, uri1)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 100, uri1)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 50, uri2)))); + mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 100, uri2)))); mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), CancellationToken.None)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[1])), It.IsAny>(), CancellationToken.None)); + mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), CancellationToken.None)); + mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), CancellationToken.None)); + + mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Informational, "info")); + mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "error")); VerifyMetrics(2, 2, "Completed"); } @@ -578,10 +585,10 @@ private void VerifyMetrics(int inputCount, int outputCount, string status = "Com mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.TimeTakenInSecForFinalization, It.IsAny())); } - private void VerifyCompleteEvent(bool isAborted, bool isCanceled, bool containsError, params AttachmentSet[] expectedSets) + private void VerifyCompleteEvent(bool isCanceled, bool containsError, params AttachmentSet[] expectedSets) { mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete( - It.Is(a => a.IsAborted == isAborted && a.IsCanceled == isCanceled && (a.Error != null) == containsError), + It.Is(a => a.IsCanceled == isCanceled && (a.Error != null) == containsError), It.Is>(c => c.Count == expectedSets.Length && expectedSets.All(e => c.Contains(e))))); } @@ -589,13 +596,13 @@ private bool VerifyProgressArgs(MultiTestRunFinalizationProgressEventArgs args, { Assert.AreEqual(1, args.CurrentHandlerIndex); Assert.AreEqual(2, args.HandlersCount); - Assert.IsTrue(args.CurrentHandlerName.StartsWith("Castle.Proxies.ObjectProxy")); + Assert.AreEqual(uri1, args.CurrentHandlerUri.AbsoluteUri); return progress == args.CurrentHandlerProgress; } - private bool VerifyProgressArgsForTwoHandlers(MultiTestRunFinalizationProgressEventArgs args, long handlerIndex, long progress) + private bool VerifyProgressArgsForTwoHandlers(MultiTestRunFinalizationProgressEventArgs args, long handlerIndex, long progress, string uri) { - return progress == args.CurrentHandlerProgress && args.CurrentHandlerIndex == handlerIndex && args.CurrentHandlerName.StartsWith("Castle.Proxies.ObjectProxy") && args.HandlersCount == 2; + return progress == args.CurrentHandlerProgress && args.CurrentHandlerIndex == handlerIndex && args.CurrentHandlerUri.AbsoluteUri == uri && args.HandlersCount == 2; } } } diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs index 145c86993a..06a55ac0cb 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; + using System.Linq; using System.Threading; [TestClass] @@ -26,12 +27,12 @@ public void HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoAttachme { Collection attachment = new Collection(); ICollection resultAttachmentSets = - coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, CancellationToken.None); + coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, null, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 0); - resultAttachmentSets = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(null, mockProgressReporter.Object, CancellationToken.None); + resultAttachmentSets = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(null, mockProgressReporter.Object, null, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 0); @@ -39,6 +40,22 @@ public void HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoAttachme mockProgressReporter.Verify(p => p.Report(It.IsAny()), Times.Never); } + [TestMethod] + public void HandleDataCollectionAttachmentSetsShouldReturnInputIfOnly1Attachment() + { + var attachmentSet = new AttachmentSet(new Uri("//badrui//"), string.Empty); + attachmentSet.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\aa"), "coverage")); + + Collection attachment = new Collection { attachmentSet }; + ICollection resultAttachmentSets = + coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, null, CancellationToken.None); + + Assert.IsNotNull(resultAttachmentSets); + Assert.IsTrue(resultAttachmentSets.Count == 1); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", resultAttachmentSets.First().Uri.AbsoluteUri); + Assert.AreEqual("file:///C:/temp/aa", resultAttachmentSets.First().Attachments.First().Uri.AbsoluteUri); + } + [TestMethod] public void HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested() { @@ -49,12 +66,13 @@ public void HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested Collection attachment = new Collection { + attachmentSet, attachmentSet }; - Assert.ThrowsException(() => coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, cts.Token)); + Assert.ThrowsException(() => coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, null, cts.Token)); - Assert.AreEqual(1, attachment.Count); + Assert.AreEqual(2, attachment.Count); mockProgressReporter.Verify(p => p.Report(It.IsAny()), Times.Never); } @@ -76,7 +94,7 @@ public void HandleDataCollectionAttachmentSetsShouldReturnExistingAttachmentsIfF attachmentSet2 }; - var result = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, cts.Token); + var result = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, null, cts.Token); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Contains(attachmentSet1)); diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs index 3658178a24..d23c9b84e4 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs @@ -1904,7 +1904,7 @@ public async Task FinalizeTestsShouldCompleteWithZeroAttachments() var payload = new MultiTestRunFinalizationCompletePayload() { - FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(false, false, null), + FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(false, null), Attachments = new AttachmentSet[0] }; @@ -1919,7 +1919,7 @@ public async Task FinalizeTestsShouldCompleteWithZeroAttachments() mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is(a => !a.IsAborted && !a.IsCanceled && a.Error == null), It.Is>(a => a.Count == 0)), Times.Once, "Finalization Complete must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is(a => !a.IsCanceled && a.Error == null), It.Is>(a => a.Count == 0)), Times.Once, "Finalization Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never, "TestMessage event must not be called"); } @@ -1932,7 +1932,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachment() var payload = new MultiTestRunFinalizationCompletePayload() { - FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(true, true, new Exception("msg")), + FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(true, new Exception("msg")), Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } }; var finalizationComplete = new Message() @@ -1946,7 +1946,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachment() mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is(a => a.IsAborted && a.IsCanceled && a.Error != null), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is(a => a.IsCanceled && a.Error != null), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never, "TestMessage event must not be called"); } @@ -1959,7 +1959,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndTestMessage() var payload = new MultiTestRunFinalizationCompletePayload() { - FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(false, false, null), + FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(false, null), Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } }; @@ -1993,7 +1993,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndProgressMessage var completePayload = new MultiTestRunFinalizationCompletePayload() { - FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(false, false, null), + FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(false, null), Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } }; @@ -2005,7 +2005,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndProgressMessage var progressPayload = new MultiTestRunFinalizationProgressPayload() { - FinalizationProgressEventArgs = new MultiTestRunFinalizationProgressEventArgs(1, "cc", 50, 2) + FinalizationProgressEventArgs = new MultiTestRunFinalizationProgressEventArgs(1, new System.Uri("http://www.bing.com/"), 50, 2) }; var finalizationProgress = new Message() @@ -2023,7 +2023,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndProgressMessage mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationProgress(It.Is(a => a.CurrentHandlerIndex == 1 && a.CurrentHandlerName == "cc" && a.CurrentHandlerProgress == 50 && a.HandlersCount == 2)), Times.Once, "Finalization Progress must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationProgress(It.Is(a => a.CurrentHandlerIndex == 1 && a.CurrentHandlerUri == new System.Uri("http://www.bing.com/") && a.CurrentHandlerProgress == 50 && a.HandlersCount == 2)), Times.Once, "Finalization Progress must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Never); } @@ -2102,7 +2102,7 @@ public async Task FinalizeTestsShouldAbortOnExceptionInSendMessage() await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, false, mockHandler.Object, CancellationToken.None); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is(a => !a.IsCanceled && a.IsAborted && a.Error is IOException), null), Times.Once, "Finalization Complete must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is(a => !a.IsCanceled && a.Error is IOException), null), Times.Once, "Finalization Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Error, It.IsAny()), Times.Once, "TestMessage event must be called"); this.mockCommunicationManager.Verify(cm => cm.StopServer(), Times.Never); } From e635ec5faf910e5fe7c51a61bbd8efee9705c98e Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Mon, 22 Jun 2020 22:15:37 +0200 Subject: [PATCH 47/58] Fixing resources accesability --- ...tform.VsTestConsole.TranslationLayer.csproj | 2 +- .../Resources/Resources.Designer.cs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj index f625e66f36..e2952d93f7 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.csproj @@ -37,7 +37,7 @@ - ResXFileCodeGenerator + PublicResXFileCodeGenerator Resources.Designer.cs diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs index d1cee45a68..d20d874ef0 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs @@ -22,7 +22,7 @@ namespace Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Res [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { + public class Resources { private static global::System.Resources.ResourceManager resourceMan; @@ -36,7 +36,7 @@ internal Resources() { /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { + public static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Resources.Reso" + @@ -52,7 +52,7 @@ internal Resources() { /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { + public static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -64,7 +64,7 @@ internal Resources() { /// /// Looks up a localized string similar to The active Multi Test Runs Finalization was aborted.. /// - internal static string AbortedMultiTestRunFinalization { + public static string AbortedMultiTestRunFinalization { get { return ResourceManager.GetString("AbortedMultiTestRunFinalization", resourceCulture); } @@ -73,7 +73,7 @@ internal static string AbortedMultiTestRunFinalization { /// /// Looks up a localized string similar to The active Tests Discovery was aborted.. /// - internal static string AbortedTestsDiscovery { + public static string AbortedTestsDiscovery { get { return ResourceManager.GetString("AbortedTestsDiscovery", resourceCulture); } @@ -82,7 +82,7 @@ internal static string AbortedTestsDiscovery { /// /// Looks up a localized string similar to The active Tests Run was aborted.. /// - internal static string AbortedTestsRun { + public static string AbortedTestsRun { get { return ResourceManager.GetString("AbortedTestsRun", resourceCulture); } @@ -91,7 +91,7 @@ internal static string AbortedTestsRun { /// /// Looks up a localized string similar to Failed to receive message from vstest.console process. /// - internal static string FailedToReceiveMessage { + public static string FailedToReceiveMessage { get { return ResourceManager.GetString("FailedToReceiveMessage", resourceCulture); } @@ -100,7 +100,7 @@ internal static string FailedToReceiveMessage { /// /// Looks up a localized string similar to File {0} does not exists. /// - internal static string InvalidFilePath { + public static string InvalidFilePath { get { return ResourceManager.GetString("InvalidFilePath", resourceCulture); } @@ -109,7 +109,7 @@ internal static string InvalidFilePath { /// /// Looks up a localized string similar to vstest.console process exited abnormally. /// - internal static string VsTestProcessExitedAbnormally { + public static string VsTestProcessExitedAbnormally { get { return ResourceManager.GetString("VsTestProcessExitedAbnormally", resourceCulture); } From 303cee86825aa1dd70b17ac62aa8062fdcdf5ba1 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Mon, 22 Jun 2020 23:19:06 +0200 Subject: [PATCH 48/58] Fix test --- .../MultiTestRunFinalizationManagerTests.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs index 70ceea583b..0b5c678a8a 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs @@ -533,6 +533,18 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven new AttachmentSet(new Uri(uri2), "uri2_output") }; + var innerTaskCompletionSource = new TaskCompletionSource(); + + int counter = 0; + mockEventsHandler.Setup(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny())).Callback(() => + { + counter++; + if(counter == 6) + { + innerTaskCompletionSource.TrySetResult(null); + } + }); + mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => { progress.Report(25); @@ -555,6 +567,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, CancellationToken.None); // assert + await innerTaskCompletionSource.Task; VerifyCompleteEvent(false, false, outputAttachments1[0], outputAttachments2[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Exactly(6)); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 25, uri1)))); From 676c02bb535b579bb5d92e373165b60e1f91ffe4 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 23 Jun 2020 08:21:01 +0200 Subject: [PATCH 49/58] Fix race conditions in acceptance tests --- .../CodeCoverageTests.cs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs index 8030f48881..6d2047e105 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -115,14 +115,16 @@ public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); - Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 2 : 0, multiTestRunFinalizationEventHandler.ProgressArgs.Count); for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); Assert.AreEqual(1, progressArgs.HandlersCount); - Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentHandlerProgress); + if (multiTestRunFinalizationEventHandler.ProgressArgs.Count == 2) + { + Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentHandlerProgress); + } } Assert.AreEqual("Completed", multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.FinalizationState]); @@ -161,14 +163,16 @@ public async Task TestRunWithCodeCoverageAndFinalizationNoMetrics(RunnerInfo run Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); - Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 2 : 0, multiTestRunFinalizationEventHandler.ProgressArgs.Count); for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); Assert.AreEqual(1, progressArgs.HandlersCount); - Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentHandlerProgress); + if (multiTestRunFinalizationEventHandler.ProgressArgs.Count == 2) + { + Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentHandlerProgress); + } } Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.IsNullOrEmpty()); @@ -205,14 +209,17 @@ public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerI Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); - Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 3 : 0, multiTestRunFinalizationEventHandler.ProgressArgs.Count); for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); Assert.AreEqual(1, progressArgs.HandlersCount); - Assert.AreEqual(i == 0 ? 33 : i == 1 ? 66 : 100, progressArgs.CurrentHandlerProgress); + + if (multiTestRunFinalizationEventHandler.ProgressArgs.Count == 3) + { + Assert.AreEqual(i == 0 ? 33 : i == 1 ? 66 : 100, progressArgs.CurrentHandlerProgress); + } } Assert.AreEqual("Completed", multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.FinalizationState]); @@ -279,14 +286,10 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); Assert.AreEqual(1, progressArgs.HandlersCount); - if (i == 5) + if (i == 0) { Assert.AreEqual(0, progressArgs.CurrentHandlerProgress); - } - else if (i == 15) - { - Assert.AreEqual(1, progressArgs.CurrentHandlerProgress); - } + } } Assert.AreEqual("Canceled", multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.FinalizationState]); From 571028e6409c9a92ae7788cc48e62c6fee92f3a0 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 30 Jun 2020 16:13:08 +0200 Subject: [PATCH 50/58] RFC changes merged --- .../MultiTestRunFinalizationEventsHandler.cs | 2 +- .../MultiTestRunFinalizationManager.cs | 31 ++- ...ltiTestRunFinalizationCompleteEventArgs.cs | 2 +- ...ltiTestRunFinalizationProgressEventArgs.cs | 35 ++-- .../IMultiTestRunFinalizationEventsHandler.cs | 8 +- .../IDataCollectorAttachmentProcessor.cs | 38 ++++ .../IDataCollectorAttachments.cs | 12 +- .../CodeCoverageDataAttachmentsHandler.cs | 26 ++- .../Interfaces/IVsTestConsoleWrapperAsync.cs | 7 +- .../VsTestConsoleWrapper.cs | 2 +- .../CodeCoverageTests.cs | 44 ++-- .../MultiTestRunFinalizationEventHandler.cs | 2 +- ...tiTestRunFinalizationEventsHandlerTests.cs | 2 +- .../MultiTestRunFinalizationManagerTests.cs | 188 +++++++++--------- ...CodeCoverageDataAttachmentsHandlerTests.cs | 30 +-- .../VsTestConsoleRequestSenderTests.cs | 4 +- .../VsTestConsoleWrapperAsyncTests.cs | 1 + .../VsTestConsoleWrapperTests.cs | 1 + 18 files changed, 235 insertions(+), 200 deletions(-) create mode 100644 src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs diff --git a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs index b31d7463a9..f0359712de 100644 --- a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs @@ -55,7 +55,7 @@ public void HandleMultiTestRunFinalizationProgress(MultiTestRunFinalizationProgr } /// - public void HandleFinalisedAttachments(IEnumerable attachments) + public void HandleProcessedAttachmentsChunk(IEnumerable attachments) { throw new System.NotImplementedException(); } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index af23cbcaee..661090959f 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -28,15 +28,15 @@ public class MultiTestRunFinalizationManager : IMultiTestRunFinalizationManager private static string FinalizationFailed = "Failed"; private readonly ITestPlatformEventSource testPlatformEventSource; - private readonly IDataCollectorAttachments[] dataCollectorAttachmentsHandlers; + private readonly IDataCollectorAttachmentProcessor[] dataCollectorAttachmentsProcessors; /// /// Initializes a new instance of the class. /// - public MultiTestRunFinalizationManager(ITestPlatformEventSource testPlatformEventSource, params IDataCollectorAttachments[] dataCollectorAttachmentsHandlers) + public MultiTestRunFinalizationManager(ITestPlatformEventSource testPlatformEventSource, params IDataCollectorAttachmentProcessor[] dataCollectorAttachmentsProcessors) { this.testPlatformEventSource = testPlatformEventSource ?? throw new ArgumentNullException(nameof(testPlatformEventSource)); - this.dataCollectorAttachmentsHandlers = dataCollectorAttachmentsHandlers ?? throw new ArgumentNullException(nameof(dataCollectorAttachmentsHandlers)); + this.dataCollectorAttachmentsProcessors = dataCollectorAttachmentsProcessors ?? throw new ArgumentNullException(nameof(dataCollectorAttachmentsProcessors)); } /// @@ -64,10 +64,7 @@ private async Task> InternalFinalizeMultiTestRunAsync( var taskCompletionSource = new TaskCompletionSource>(); using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled())) { - Task> task = Task.Run(() => - { - return ProcessAttachments(new Collection(attachments.ToList()), eventHandler, cancellationToken); - }); + Task> task = Task.Run(async () => await ProcessAttachmentsAsync(new Collection(attachments.ToList()), eventHandler, cancellationToken)); var completedTask = await Task.WhenAny(task, taskCompletionSource.Task).ConfigureAwait(false); @@ -77,7 +74,7 @@ private async Task> InternalFinalizeMultiTestRunAsync( } else { - eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Informational, "Finalization was cancelled."); + eventHandler?.HandleLogMessage(TestMessageLevel.Informational, "Finalization was cancelled."); return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, null), attachments, stopwatch, eventHandler); } } @@ -94,26 +91,26 @@ private async Task> InternalFinalizeMultiTestRunAsync( { EqtTrace.Error("MultiTestRunFinalizationManager: Exception in FinalizeMultiTestRunAsync: " + e); - eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); + eventHandler?.HandleLogMessage(TestMessageLevel.Error, e.Message); return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, e), attachments, stopwatch, eventHandler); } } - private Collection ProcessAttachments(Collection attachments, IMultiTestRunFinalizationEventsHandler eventsHandler, CancellationToken cancellationToken) + private async Task> ProcessAttachmentsAsync(Collection attachments, IMultiTestRunFinalizationEventsHandler eventsHandler, CancellationToken cancellationToken) { if (attachments == null || !attachments.Any()) return attachments; var logger = CreateMessageLogger(eventsHandler); - for (int i = 0; i < dataCollectorAttachmentsHandlers.Length; i++) + for (int i = 0; i < dataCollectorAttachmentsProcessors.Length; i++) { - IDataCollectorAttachments dataCollectorAttachmentsHandler = dataCollectorAttachmentsHandlers[i]; + var dataCollectorAttachmentsProcessor = dataCollectorAttachmentsProcessors[i]; int attachmentsHandlerIndex = i + 1; - Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); - if (attachementUri != null) + ICollection attachementProcessorUris = dataCollectorAttachmentsProcessor.GetExtensionUris()?.ToList(); + if (attachementProcessorUris != null && attachementProcessorUris.Any()) { - var attachmentsToBeProcessed = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); + var attachmentsToBeProcessed = attachments.Where(dataCollectionAttachment => attachementProcessorUris.Any(uri => uri.Equals(dataCollectionAttachment.Uri))).ToArray(); if (attachmentsToBeProcessed.Any()) { foreach (var attachment in attachmentsToBeProcessed) @@ -123,9 +120,9 @@ private Collection ProcessAttachments(Collection a IProgress progressReporter = new Progress((int progress) => eventsHandler?.HandleMultiTestRunFinalizationProgress( - new MultiTestRunFinalizationProgressEventArgs(attachmentsHandlerIndex, dataCollectorAttachmentsHandler.GetExtensionUri(), progress, dataCollectorAttachmentsHandlers.Length))); + new MultiTestRunFinalizationProgressEventArgs(attachmentsHandlerIndex, attachementProcessorUris, progress, dataCollectorAttachmentsProcessors.Length))); - ICollection processedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), progressReporter, logger, cancellationToken); + ICollection processedAttachments = await dataCollectorAttachmentsProcessor.ProcessAttachmentSetsAsync(new Collection(attachmentsToBeProcessed), progressReporter, logger, cancellationToken).ConfigureAwait(false); foreach (var attachment in processedAttachments) { diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs index 4f73073caa..0ca669e6a1 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs @@ -34,7 +34,7 @@ public MultiTestRunFinalizationCompleteEventArgs(bool isCanceled, Exception erro public Exception Error { get; private set; } /// - /// Get or Sets the Metrics + /// Get or Sets the Metrics (used for telemetry) /// [DataMember] public IDictionary Metrics { get; set; } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs index 529be7baaf..9710add944 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs @@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client { using System; + using System.Collections.Generic; using System.Runtime.Serialization; [DataContract] @@ -12,40 +13,40 @@ public class MultiTestRunFinalizationProgressEventArgs : EventArgs /// /// Default constructor. /// - /// Specifies current handler index. - /// Specifies current handler Uri. - /// Specifies current handler progress. - /// Specifies the overall number of handlers. - public MultiTestRunFinalizationProgressEventArgs(long currentHandlerIndex, Uri currentHandlerUri, long currentHandlerProgress, long handlersCount) + /// Specifies current attachment processor index. + /// Specifies current processor Uris. + /// Specifies current processor progress. + /// Specifies the overall number of processors. + public MultiTestRunFinalizationProgressEventArgs(long currentAttachmentProcessorIndex, ICollection currentAttachmentProcessorUris, long currentAttachmentProcessorProgress, long attachmentProcessorsCount) { - CurrentHandlerIndex = currentHandlerIndex; - CurrentHandlerUri = currentHandlerUri; - CurrentHandlerProgress = currentHandlerProgress; - HandlersCount = handlersCount; + CurrentAttachmentProcessorIndex = currentAttachmentProcessorIndex; + CurrentAttachmentProcessorUris = currentAttachmentProcessorUris; + CurrentAttachmentProcessorProgress = currentAttachmentProcessorProgress; + AttachmentProcessorsCount = attachmentProcessorsCount; } /// - /// Gets a current handler index. + /// Gets a current attachment processor index. /// [DataMember] - public long CurrentHandlerIndex { get; private set; } + public long CurrentAttachmentProcessorIndex { get; private set; } /// - /// Gets a current handler URI. + /// Gets a current attachment processor URI. /// [DataMember] - public Uri CurrentHandlerUri { get; private set; } + public ICollection CurrentAttachmentProcessorUris { get; private set; } /// - /// Gets a current handler progress. + /// Gets a current attachment processor progress. /// [DataMember] - public long CurrentHandlerProgress { get; private set; } + public long CurrentAttachmentProcessorProgress { get; private set; } /// - /// Gets the overall number of handlers. + /// Gets the overall number of attachment processors. /// [DataMember] - public long HandlersCount { get; private set; } + public long AttachmentProcessorsCount { get; private set; } } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs index 8c00b00c60..3983bd571e 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs @@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client { /// - /// Interface contract for handling multi test run finalization complete events + /// Interface contract for handling multi test run finalization events /// public interface IMultiTestRunFinalizationEventsHandler : ITestMessageEventHandler { @@ -18,10 +18,10 @@ public interface IMultiTestRunFinalizationEventsHandler : ITestMessageEventHandl void HandleMultiTestRunFinalizationComplete(MultiTestRunFinalizationCompleteEventArgs finalizationCompleteEventArgs, IEnumerable lastChunk); /// - /// Dispatch FinalisedAttachments event to listeners. + /// Dispatch ProcessedAttachmentsChunk event to listeners. /// - /// Finalised attachment sets. - void HandleFinalisedAttachments(IEnumerable attachments); + /// Processed attachment sets. + void HandleProcessedAttachmentsChunk(IEnumerable attachments); /// /// Dispatch MultiTestRunFinalizationProgress event to listeners. diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs new file mode 100644 index 0000000000..7b996d950d --- /dev/null +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection +{ + using System; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + + /// + /// Interface for data collectors add-ins that choose to reprocess generated attachments + /// + public interface IDataCollectorAttachmentProcessor + { + /// + /// Gets the attachments Uris, which are handled by attachment processor + /// + IEnumerable GetExtensionUris(); + + /// + /// Indicates whether attachment processor is supporting incremental processing of attachments + /// + bool SupportsIncrementalProcessing { get; } + + /// + /// Reprocess attachments generated by independent test executions + /// + /// Attachments to be processed + /// Progress reporter. Accepts integers from 0 to 100 + /// Message logger + /// Cancellation token + /// Attachments after reprocessing + Task> ProcessAttachmentSetsAsync(ICollection attachments, IProgress progressReporter, IMessageLogger logger, CancellationToken cancellationToken); + } +} diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs index cd9124743b..a342d74ea6 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs @@ -3,14 +3,13 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection { - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using System; using System.Collections.Generic; - using System.Threading; /// /// Interface for data collectors add-ins that choose to handle attachment(s) generated /// + [Obsolete("Interface is deprecated. Please use IDataCollectorAttachmentProcessor instead")] public interface IDataCollectorAttachments { /// @@ -19,15 +18,6 @@ public interface IDataCollectorAttachments /// Gets the attachment set after Test Run Session ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments); - /// - /// Gets the attachment set after Test Run Session - /// - /// Attachments to be processed - /// Progress reporter. Accepts integers from 0 to 100 - /// Cancellation token - /// Gets the attachment set after Test Run Session - ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, IProgress progressReporter, IMessageLogger logger, CancellationToken cancellationToken); - /// /// Gets the attachment Uri, which is handled by current Collector /// diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index d31fda0a56..2b911f6926 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -10,12 +10,13 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities using System.Linq; using System.Reflection; using System.Threading; + using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; - public class CodeCoverageDataAttachmentsHandler : IDataCollectorAttachments + public class CodeCoverageDataAttachmentsHandler : IDataCollectorAttachmentProcessor { private const string CoverageUri = "datacollector://microsoft/CodeCoverage/2.0"; private const string CoverageFileExtension = ".coverage"; @@ -27,35 +28,32 @@ public class CodeCoverageDataAttachmentsHandler : IDataCollectorAttachments private static readonly Uri CodeCoverageDataCollectorUri = new Uri(CoverageUri); - public Uri GetExtensionUri() - { - return CodeCoverageDataCollectorUri; - } + public bool SupportsIncrementalProcessing => true; - public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments) + public IEnumerable GetExtensionUris() { - return HandleDataCollectionAttachmentSets(dataCollectionAttachments, null, null, CancellationToken.None); - } + yield return CodeCoverageDataCollectorUri; + } - public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, IProgress progressReporter, IMessageLogger logger, CancellationToken cancellationToken) + public Task> ProcessAttachmentSetsAsync(ICollection attachments, IProgress progressReporter, IMessageLogger logger, CancellationToken cancellationToken) { - if (dataCollectionAttachments != null && dataCollectionAttachments.Any()) + if (attachments != null && attachments.Any()) { - var codeCoverageFiles = dataCollectionAttachments.Select(coverageAttachment => coverageAttachment.Attachments[0].Uri.LocalPath).ToArray(); + var codeCoverageFiles = attachments.Select(coverageAttachment => coverageAttachment.Attachments[0].Uri.LocalPath).ToArray(); var outputFile = MergeCodeCoverageFiles(codeCoverageFiles, progressReporter, cancellationToken); var attachmentSet = new AttachmentSet(CodeCoverageDataCollectorUri, CoverageFriendlyName); if (!string.IsNullOrEmpty(outputFile)) { attachmentSet.Attachments.Add(new UriDataAttachment(new Uri(outputFile), CoverageFriendlyName)); - return new Collection { attachmentSet }; + return Task.FromResult((ICollection)new Collection { attachmentSet }); } // In case merging fails(esp in dotnet core we cannot merge), so return filtered list of Code Coverage Attachments - return dataCollectionAttachments; + return Task.FromResult(attachments); } - return new Collection(); + return Task.FromResult((ICollection)new Collection()); } private string MergeCodeCoverageFiles(IList files, IProgress progressReporter, CancellationToken cancellationToken) diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs index 56e322d711..d9f67417cf 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs @@ -81,9 +81,10 @@ public interface IVsTestConsoleWrapperAsync /// Provides back all attachments to TestPlatform for additional processing (for example merging) /// /// Collection of attachments - /// Enables metrics collection - /// EventHandler to receive session complete event + /// Indicates that all test executions are done and all data is provided + /// Enables metrics collection (used for telemetry) + /// EventHandler to receive session complete event /// Cancellation token - Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool collectMetrics, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); + Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool multiTestRunCompleted, bool collectMetrics, IMultiTestRunFinalizationEventsHandler eventsHandler, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index 116a9d3240..e2750b80fe 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -407,7 +407,7 @@ public async Task RunTestsWithCustomTestHostAsync(IEnumerable testCase } /// - public async Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool collectMetrics, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) + public async Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool multiTestRunCompleted, bool collectMetrics, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) { this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStart(); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs index 6d2047e105..cc3c7efe62 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -104,7 +104,7 @@ public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) Assert.AreEqual(2, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, true, multiTestRunFinalizationEventHandler, CancellationToken.None); // Assert multiTestRunFinalizationEventHandler.EnsureSuccess(); @@ -118,12 +118,13 @@ public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; - Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); - Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); - Assert.AreEqual(1, progressArgs.HandlersCount); + Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorIndex); + Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorUris.Count); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentAttachmentProcessorUris.First().AbsoluteUri); + Assert.AreEqual(1, progressArgs.AttachmentProcessorsCount); if (multiTestRunFinalizationEventHandler.ProgressArgs.Count == 2) { - Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentHandlerProgress); + Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentAttachmentProcessorProgress); } } @@ -152,7 +153,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationNoMetrics(RunnerInfo run Assert.AreEqual(2, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, false, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, false, multiTestRunFinalizationEventHandler, CancellationToken.None); // Assert multiTestRunFinalizationEventHandler.EnsureSuccess(); @@ -166,12 +167,13 @@ public async Task TestRunWithCodeCoverageAndFinalizationNoMetrics(RunnerInfo run for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; - Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); - Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); - Assert.AreEqual(1, progressArgs.HandlersCount); + Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorIndex); + Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorUris.Count); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentAttachmentProcessorUris.First().AbsoluteUri); + Assert.AreEqual(1, progressArgs.AttachmentProcessorsCount); if (multiTestRunFinalizationEventHandler.ProgressArgs.Count == 2) { - Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentHandlerProgress); + Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentAttachmentProcessorProgress); } } @@ -198,7 +200,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerI Assert.AreEqual(3, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, true, multiTestRunFinalizationEventHandler, CancellationToken.None); // Assert multiTestRunFinalizationEventHandler.EnsureSuccess(); @@ -212,13 +214,13 @@ public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerI for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; - Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); - Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); - Assert.AreEqual(1, progressArgs.HandlersCount); + Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorIndex); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentAttachmentProcessorUris.First().AbsoluteUri); + Assert.AreEqual(1, progressArgs.AttachmentProcessorsCount); if (multiTestRunFinalizationEventHandler.ProgressArgs.Count == 3) { - Assert.AreEqual(i == 0 ? 33 : i == 1 ? 66 : 100, progressArgs.CurrentHandlerProgress); + Assert.AreEqual(i == 0 ? 33 : i == 1 ? 66 : 100, progressArgs.CurrentAttachmentProcessorProgress); } } @@ -250,7 +252,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run CancellationTokenSource cts = new CancellationTokenSource(); - Task finalization = this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(attachments, true, multiTestRunFinalizationEventHandler, cts.Token); + Task finalization = this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(attachments, true, true, multiTestRunFinalizationEventHandler, cts.Token); while (true) { @@ -282,13 +284,13 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; - Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); - Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); - Assert.AreEqual(1, progressArgs.HandlersCount); + Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorIndex); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentAttachmentProcessorUris.First().AbsoluteUri); + Assert.AreEqual(1, progressArgs.AttachmentProcessorsCount); if (i == 0) { - Assert.AreEqual(0, progressArgs.CurrentHandlerProgress); + Assert.AreEqual(0, progressArgs.CurrentAttachmentProcessorProgress); } } @@ -316,7 +318,7 @@ public async Task EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runn Assert.AreEqual(6, this.runEventHandler.TestResults.Count); Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, true, multiTestRunFinalizationEventHandler, CancellationToken.None); // act this.vstestConsoleWrapper?.EndSession(); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs index 0c867da64e..ed3fc68204 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs @@ -96,7 +96,7 @@ public void HandleMultiTestRunFinalizationComplete(MultiTestRunFinalizationCompl CompleteArgs = finalizationCompleteEventArgs; } - public void HandleFinalisedAttachments(IEnumerable attachments) + public void HandleProcessedAttachmentsChunk(IEnumerable attachments) { throw new NotImplementedException(); } diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs index a15f47e09e..852554361c 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs @@ -48,7 +48,7 @@ public void EventsHandlerHandleMultiTestRunFinalizationCompleteShouldSendFinaliz [TestMethod] public void EventsHandlerHandleMultiTestRunFinalizationProgressShouldSendFinalizationProgressMessage() { - var args = new MultiTestRunFinalizationProgressEventArgs(1, new System.Uri("http://www.bing.com/"), 90, 2); + var args = new MultiTestRunFinalizationProgressEventArgs(1, new[] { new System.Uri("http://www.bing.com/") }, 90, 2); handler.HandleMultiTestRunFinalizationProgress(args); diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs index 0b5c678a8a..a8f7aa866e 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs @@ -28,8 +28,8 @@ public class MultiTestRunFinalizationManagerTests private readonly Mock mockRequestData; private readonly Mock mockMetricsCollection; private readonly Mock mockEventSource; - private readonly Mock mockAttachmentHandler1; - private readonly Mock mockAttachmentHandler2; + private readonly Mock mockAttachmentHandler1; + private readonly Mock mockAttachmentHandler2; private readonly Mock mockEventsHandler; private readonly MultiTestRunFinalizationManager manager; private readonly CancellationTokenSource cancellationTokenSource; @@ -41,12 +41,12 @@ public MultiTestRunFinalizationManagerTests() mockRequestData.Setup(r => r.MetricsCollection).Returns(mockMetricsCollection.Object); mockEventSource = new Mock(); - mockAttachmentHandler1 = new Mock(); - mockAttachmentHandler2 = new Mock(); + mockAttachmentHandler1 = new Mock(); + mockAttachmentHandler2 = new Mock(); mockEventsHandler = new Mock(); - mockAttachmentHandler1.Setup(h => h.GetExtensionUri()).Returns(new Uri(uri1)); - mockAttachmentHandler2.Setup(h => h.GetExtensionUri()).Returns(new Uri(uri2)); + mockAttachmentHandler1.Setup(h => h.GetExtensionUris()).Returns(new[] { new Uri(uri1) }); + mockAttachmentHandler2.Setup(h => h.GetExtensionUris()).Returns(new[] { new Uri(uri2) }); manager = new MultiTestRunFinalizationManager(mockEventSource.Object, mockAttachmentHandler1.Object, mockAttachmentHandler2.Object); @@ -69,10 +69,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(0)); mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(0, 0); } @@ -88,10 +88,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNoAttachments_IfNoAttach // assert Assert.AreEqual(0, result.Count); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(0, 0); } @@ -112,10 +112,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachmentT VerifyCompleteEvent(false, false, inputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1); } @@ -135,10 +135,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachment_ // assert Assert.AreEqual(1, result.Count); Assert.IsTrue(result.Contains(inputAttachments[0])); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1); } @@ -157,7 +157,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachmentThro new AttachmentSet(new Uri(uri1), "uri1_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachments); + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachments); // act await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); @@ -166,10 +166,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachmentThro VerifyCompleteEvent(false, false, outputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1); } @@ -188,7 +188,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachment_IfR new AttachmentSet(new Uri(uri1), "uri1_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachments); + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachments); // act var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); @@ -198,10 +198,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachment_IfR Assert.IsTrue(result.Contains(outputAttachments[0])); mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(1)); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1); } @@ -215,7 +215,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug new AttachmentSet(new Uri(uri1), "uri1_input") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Throws(new Exception("exception message")); + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Throws(new Exception("exception message")); // act await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); @@ -224,10 +224,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug VerifyCompleteEvent(false, true, inputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "exception message"), Times.Once); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Failed"); } @@ -241,7 +241,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfRel new AttachmentSet(new Uri(uri1), "uri1_input") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Throws(new Exception("exception message")); + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Throws(new Exception("exception message")); // act var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); @@ -249,10 +249,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfRel // assert Assert.AreEqual(1, result.Count); Assert.IsTrue(result.Contains(inputAttachments[0])); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Failed"); } @@ -273,10 +273,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug // assert VerifyCompleteEvent(true, false, inputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Canceled"); } @@ -297,10 +297,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe // assert Assert.AreEqual(1, result.Count); Assert.IsTrue(result.Contains(inputAttachments[0])); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Canceled"); } @@ -328,8 +328,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachmentsThro new AttachmentSet(new Uri(uri2), "uri2_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachmentsForHandler1); - mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachmentsForHandler2); + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachmentsForHandler1); + mockAttachmentHandler2.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachmentsForHandler2); // act await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); @@ -338,10 +338,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachmentsThro VerifyCompleteEvent(false, false, inputAttachments[4], outputAttachmentsForHandler1.First(), outputAttachmentsForHandler2.First()); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); VerifyMetrics(5, 3); } @@ -369,8 +369,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachments_IfR new AttachmentSet(new Uri(uri2), "uri2_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachmentsForHandler1); - mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachmentsForHandler2); + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachmentsForHandler1); + mockAttachmentHandler2.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachmentsForHandler2); // act var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); @@ -380,10 +380,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachments_IfR Assert.IsTrue(result.Contains(inputAttachments[4])); Assert.IsTrue(result.Contains(outputAttachmentsForHandler1[0])); Assert.IsTrue(result.Contains(outputAttachmentsForHandler2[0])); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); VerifyMetrics(5, 3); } @@ -397,14 +397,14 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug new AttachmentSet(new Uri(uri1), "uri1_input") }; - List outputAttachments = new List + ICollection outputAttachments = new List { new AttachmentSet(new Uri(uri1), "uri1_output") }; var innerTaskCompletionSource = new TaskCompletionSource(); - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => { try { @@ -429,7 +429,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug innerTaskCompletionSource.TrySetResult(null); } - return outputAttachments; + return Task.FromResult(outputAttachments); }); // act @@ -445,10 +445,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 3)))); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 4)))); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Informational, "Finalization was cancelled.")); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Canceled"); } @@ -462,14 +462,14 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe new AttachmentSet(new Uri(uri1), "uri1_input") }; - List outputAttachments = new List + ICollection outputAttachments = new List { new AttachmentSet(new Uri(uri1), "uri1_output") }; var innerTaskCompletionSource = new TaskCompletionSource(); - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress p, IMessageLogger logger, CancellationToken cancellation) => + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress p, IMessageLogger logger, CancellationToken cancellation) => { try { @@ -493,7 +493,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe innerTaskCompletionSource.TrySetResult(null); } - return outputAttachments; + return Task.FromResult(outputAttachments); }); // act @@ -505,10 +505,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); Assert.IsTrue(result.Contains(inputAttachments[0])); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Canceled"); } @@ -523,12 +523,12 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven new AttachmentSet(new Uri(uri2), "uri2_input") }; - List outputAttachments1 = new List + ICollection outputAttachments1 = new List { new AttachmentSet(new Uri(uri1), "uri1_output") }; - List outputAttachments2 = new List + ICollection outputAttachments2 = new List { new AttachmentSet(new Uri(uri2), "uri2_output") }; @@ -545,22 +545,22 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven } }); - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => { progress.Report(25); progress.Report(50); progress.Report(75); logger.SendMessage(TestMessageLevel.Error, "error"); progress.Report(100); - return outputAttachments1; + return Task.FromResult(outputAttachments1); }); - mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => + mockAttachmentHandler2.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => { progress.Report(50); logger.SendMessage(TestMessageLevel.Informational, "info"); progress.Report(100); - return outputAttachments2; + return Task.FromResult(outputAttachments2); }); // act @@ -568,7 +568,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven // assert await innerTaskCompletionSource.Task; - VerifyCompleteEvent(false, false, outputAttachments1[0], outputAttachments2[0]); + VerifyCompleteEvent(false, false, outputAttachments1.First(), outputAttachments2.First()); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Exactly(6)); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 25, uri1)))); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 50, uri1)))); @@ -576,10 +576,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 100, uri1)))); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 50, uri2)))); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 100, uri2)))); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), CancellationToken.None)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), CancellationToken.None)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), CancellationToken.None)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), CancellationToken.None)); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Informational, "info")); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "error")); @@ -607,15 +607,19 @@ private void VerifyCompleteEvent(bool isCanceled, bool containsError, params Att private bool VerifyProgressArgs(MultiTestRunFinalizationProgressEventArgs args, int progress) { - Assert.AreEqual(1, args.CurrentHandlerIndex); - Assert.AreEqual(2, args.HandlersCount); - Assert.AreEqual(uri1, args.CurrentHandlerUri.AbsoluteUri); - return progress == args.CurrentHandlerProgress; + Assert.AreEqual(1, args.CurrentAttachmentProcessorIndex); + Assert.AreEqual(2, args.AttachmentProcessorsCount); + Assert.AreEqual(1, args.CurrentAttachmentProcessorUris.Count); + Assert.AreEqual(uri1, args.CurrentAttachmentProcessorUris.First().AbsoluteUri); + return progress == args.CurrentAttachmentProcessorProgress; } private bool VerifyProgressArgsForTwoHandlers(MultiTestRunFinalizationProgressEventArgs args, long handlerIndex, long progress, string uri) { - return progress == args.CurrentHandlerProgress && args.CurrentHandlerIndex == handlerIndex && args.CurrentHandlerUri.AbsoluteUri == uri && args.HandlersCount == 2; + return progress == args.CurrentAttachmentProcessorProgress && + args.CurrentAttachmentProcessorIndex == handlerIndex && + args.CurrentAttachmentProcessorUris.First().AbsoluteUri == uri && + args.AttachmentProcessorsCount == 2; } } } diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs index 06a55ac0cb..ff89d295bd 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs @@ -1,14 +1,16 @@ namespace Microsoft.TestPlatform.Utilities.UnitTests { - using Microsoft.VisualStudio.TestPlatform.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.Utilities; - using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading; + using System.Threading.Tasks; + + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.Utilities; + using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] public class CodeCoverageDataAttachmentsHandlerTests @@ -23,16 +25,16 @@ public CodeCoverageDataAttachmentsHandlerTests() } [TestMethod] - public void HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoAttachmentsOrAttachmentsAreNull() + public async Task HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoAttachmentsOrAttachmentsAreNull() { Collection attachment = new Collection(); - ICollection resultAttachmentSets = - coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, null, CancellationToken.None); + ICollection resultAttachmentSets = await + coverageDataAttachmentsHandler.ProcessAttachmentSetsAsync(attachment, mockProgressReporter.Object, null, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 0); - resultAttachmentSets = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(null, mockProgressReporter.Object, null, CancellationToken.None); + resultAttachmentSets = await coverageDataAttachmentsHandler.ProcessAttachmentSetsAsync(null, mockProgressReporter.Object, null, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 0); @@ -41,14 +43,14 @@ public void HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoAttachme } [TestMethod] - public void HandleDataCollectionAttachmentSetsShouldReturnInputIfOnly1Attachment() + public async Task HandleDataCollectionAttachmentSetsShouldReturnInputIfOnly1Attachment() { var attachmentSet = new AttachmentSet(new Uri("//badrui//"), string.Empty); attachmentSet.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\aa"), "coverage")); Collection attachment = new Collection { attachmentSet }; - ICollection resultAttachmentSets = - coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, null, CancellationToken.None); + ICollection resultAttachmentSets = await + coverageDataAttachmentsHandler.ProcessAttachmentSetsAsync(attachment, mockProgressReporter.Object, null, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 1); @@ -57,7 +59,7 @@ public void HandleDataCollectionAttachmentSetsShouldReturnInputIfOnly1Attachment } [TestMethod] - public void HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested() + public async Task HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested() { var attachmentSet = new AttachmentSet(new Uri("//badrui//"), string.Empty); attachmentSet.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\aa"), "coverage")); @@ -70,7 +72,7 @@ public void HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested attachmentSet }; - Assert.ThrowsException(() => coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, null, cts.Token)); + await Assert.ThrowsExceptionAsync(async () => await coverageDataAttachmentsHandler.ProcessAttachmentSetsAsync(attachment, mockProgressReporter.Object, null, cts.Token)); Assert.AreEqual(2, attachment.Count); @@ -78,7 +80,7 @@ public void HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested } [TestMethod] - public void HandleDataCollectionAttachmentSetsShouldReturnExistingAttachmentsIfFailedToLoadLibrary() + public async Task HandleDataCollectionAttachmentSetsShouldReturnExistingAttachmentsIfFailedToLoadLibrary() { var attachmentSet1 = new AttachmentSet(new Uri("//badrui//"), string.Empty); attachmentSet1.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\aa"), "coverage")); @@ -94,7 +96,7 @@ public void HandleDataCollectionAttachmentSetsShouldReturnExistingAttachmentsIfF attachmentSet2 }; - var result = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, null, cts.Token); + var result = await coverageDataAttachmentsHandler.ProcessAttachmentSetsAsync(attachment, mockProgressReporter.Object, null, cts.Token); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Contains(attachmentSet1)); diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs index d23c9b84e4..b90aabfbc8 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs @@ -2005,7 +2005,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndProgressMessage var progressPayload = new MultiTestRunFinalizationProgressPayload() { - FinalizationProgressEventArgs = new MultiTestRunFinalizationProgressEventArgs(1, new System.Uri("http://www.bing.com/"), 50, 2) + FinalizationProgressEventArgs = new MultiTestRunFinalizationProgressEventArgs(1, new[] { new Uri("http://www.bing.com/") }, 50, 2) }; var finalizationProgress = new Message() @@ -2023,7 +2023,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndProgressMessage mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationProgress(It.Is(a => a.CurrentHandlerIndex == 1 && a.CurrentHandlerUri == new System.Uri("http://www.bing.com/") && a.CurrentHandlerProgress == 50 && a.HandlersCount == 2)), Times.Once, "Finalization Progress must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationProgress(It.Is(a => a.CurrentAttachmentProcessorIndex == 1 && a.CurrentAttachmentProcessorUris.First() == new Uri("http://www.bing.com/") && a.CurrentAttachmentProcessorProgress == 50 && a.AttachmentProcessorsCount == 2)), Times.Once, "Finalization Progress must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Never); } diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs index 67b2010580..302302f9d5 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs @@ -318,6 +318,7 @@ public async Task FinalizeMultiTestRunAsyncShouldSucceed() await this.consoleWrapper.FinalizeMultiTestRunAsync( attachments, true, + true, new Mock().Object, cancellationToken); diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs index b27f781ba1..5f3f099a76 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs @@ -316,6 +316,7 @@ public async Task FinalizeMultiTestRunAsyncShouldSucceed() await this.consoleWrapper.FinalizeMultiTestRunAsync( attachments, true, + true, new Mock().Object, cancellationToken); From 2afcc44986b18392bac757fd3f810ada7eee9917 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Wed, 1 Jul 2020 09:16:53 +0200 Subject: [PATCH 51/58] Log warning in case of unexpected message id --- .../VsTestConsoleRequestSender.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index 556c875d17..ef2c9644ec 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -775,6 +775,10 @@ private async Task SendMessageAndListenAndReportFinalizationResultAsync(IEnumera var testMessagePayload = this.dataSerializer.DeserializePayload(message); eventHandler.HandleLogMessage(testMessagePayload.MessageLevel, testMessagePayload.Message); } + else + { + EqtTrace.Warning($"VsTestConsoleRequestSender.SendMessageAndListenAndReportAttachments: Unexpected message received {message.MessageType}."); + } } } } From ebf1a79dacdf61168c70dc6778e63da18d04818c Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Wed, 1 Jul 2020 09:22:15 +0200 Subject: [PATCH 52/58] Fix spelling --- .../MultiTestRunFinalizationManager.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index 661090959f..d98e034d5c 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -107,10 +107,10 @@ private async Task> ProcessAttachmentsAsync(Collection var dataCollectorAttachmentsProcessor = dataCollectorAttachmentsProcessors[i]; int attachmentsHandlerIndex = i + 1; - ICollection attachementProcessorUris = dataCollectorAttachmentsProcessor.GetExtensionUris()?.ToList(); - if (attachementProcessorUris != null && attachementProcessorUris.Any()) + ICollection attachmentProcessorUris = dataCollectorAttachmentsProcessor.GetExtensionUris()?.ToList(); + if (attachmentProcessorUris != null && attachmentProcessorUris.Any()) { - var attachmentsToBeProcessed = attachments.Where(dataCollectionAttachment => attachementProcessorUris.Any(uri => uri.Equals(dataCollectionAttachment.Uri))).ToArray(); + var attachmentsToBeProcessed = attachments.Where(dataCollectionAttachment => attachmentProcessorUris.Any(uri => uri.Equals(dataCollectionAttachment.Uri))).ToArray(); if (attachmentsToBeProcessed.Any()) { foreach (var attachment in attachmentsToBeProcessed) @@ -120,7 +120,7 @@ private async Task> ProcessAttachmentsAsync(Collection IProgress progressReporter = new Progress((int progress) => eventsHandler?.HandleMultiTestRunFinalizationProgress( - new MultiTestRunFinalizationProgressEventArgs(attachmentsHandlerIndex, attachementProcessorUris, progress, dataCollectorAttachmentsProcessors.Length))); + new MultiTestRunFinalizationProgressEventArgs(attachmentsHandlerIndex, attachmentProcessorUris, progress, dataCollectorAttachmentsProcessors.Length))); ICollection processedAttachments = await dataCollectorAttachmentsProcessor.ProcessAttachmentSetsAsync(new Collection(attachmentsToBeProcessed), progressReporter, logger, cancellationToken).ConfigureAwait(false); From e37a6f707901c3a8919bd6cb38f9f222bbd16fe6 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Wed, 1 Jul 2020 09:31:54 +0200 Subject: [PATCH 53/58] Additional comment --- .../IDataCollectorAttachmentProcessor.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs index 7b996d950d..4b0581973b 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs @@ -22,6 +22,18 @@ public interface IDataCollectorAttachmentProcessor /// /// Indicates whether attachment processor is supporting incremental processing of attachments + /// + /// `SupportsIncrementalProcessing` should indicate if attachment processor is supporting incremental processing of attachments. It means that `ProcessAttachmentSetsAsync` should be [associative](https://en.wikipedia.org/wiki/Associative_property). + /// + /// If `SupportsIncrementalProcessing` is `True` Test Platform may try to speed up whole process by reprocessing data collector attachments as soon as possible when any two test executions are done.For example let's assume we have 5 test executions which are generating 5 data collector attachments: `a1`, `a2`, `a3`, `a4` and `a5`. Test platform could perform invocations: + /// * `var result1 = await ProcessAttachmentSetsAsync([a1, a2, a3], ...);` when first 3 executions are done + /// * `var result2 = await ProcessAttachmentSetsAsync(result1.Concat([a4]), ...);` when 4th execution is done + /// * `var finalResult = await ProcessAttachmentSetsAsync(result2.Concat([a5]), ...);` when last test execution is done + /// + /// If `SupportsIncrementalProcessing` is `False` then Test Platform will wait for all test executions to finish and call `ProcessAttachmentSetsAsync` only once: + /// * `var finalResult = await ProcessAttachmentSetsAsync([a1, a2, a3, a4, a5], ...);` + /// + /// By default `SupportsIncrementalProcessing` should be `False`, unless processing can take longer time and it's beneficial to start the process as soon as possible. /// bool SupportsIncrementalProcessing { get; } From 5e51a03360a485e6c8a0de95bafc1c387372d0b3 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Wed, 1 Jul 2020 09:57:39 +0200 Subject: [PATCH 54/58] Restore some stuff in interfaces --- .../Interfaces/IVsTestConsoleWrapper.cs | 10 +++++----- .../Interfaces/IVsTestConsoleWrapperAsync.cs | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs index 9cd3c6b5b9..79e09b98dd 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper.cs @@ -39,12 +39,12 @@ public interface IVsTestConsoleWrapper : IVsTestConsoleWrapperAsync /// Settings XML for test discovery /// Options to be passed into the platform. /// EventHandler to receive discovery events - void DiscoverTests(IEnumerable sources, string discoverySettings, TestPlatformOptions options, ITestDiscoveryEventsHandler2 discoveryEventsHandler); + void DiscoverTests(IEnumerable sources, string discoverySettings, TestPlatformOptions options, ITestDiscoveryEventsHandler2 discoveryEventsHandler); /// /// Cancels the last discovery request. /// - void CancelDiscovery(); + new void CancelDiscovery(); /// /// Starts a test run given a list of sources. @@ -121,16 +121,16 @@ public interface IVsTestConsoleWrapper : IVsTestConsoleWrapperAsync /// /// Cancel the last test run. /// - void CancelTestRun(); + new void CancelTestRun(); /// /// Abort the last test run. /// - void AbortTestRun(); + new void AbortTestRun(); /// /// Ends the test session and stops processing requests. /// - void EndSession(); + new void EndSession(); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs index d9f67417cf..14b32ab427 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs @@ -37,6 +37,11 @@ public interface IVsTestConsoleWrapperAsync /// Task DiscoverTestsAsync(IEnumerable sources, string discoverySettings, TestPlatformOptions options, ITestDiscoveryEventsHandler2 discoveryEventsHandler); + /// + /// See . + /// + void CancelDiscovery(); + /// /// Asynchronous equivalent of . /// @@ -77,6 +82,16 @@ public interface IVsTestConsoleWrapperAsync /// Task RunTestsWithCustomTestHostAsync(IEnumerable testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher); + /// + /// See . + /// + void CancelTestRun(); + + /// + /// See . + /// + void AbortTestRun(); + /// /// Provides back all attachments to TestPlatform for additional processing (for example merging) /// @@ -86,5 +101,10 @@ public interface IVsTestConsoleWrapperAsync /// EventHandler to receive session complete event /// Cancellation token Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool multiTestRunCompleted, bool collectMetrics, IMultiTestRunFinalizationEventsHandler eventsHandler, CancellationToken cancellationToken); + + /// + /// See . + /// + void EndSession(); } } From 1267291f562aa4d444f673ae3f896d198e512532 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Wed, 1 Jul 2020 12:09:40 +0200 Subject: [PATCH 55/58] Big renaming --- ...tRunAttachmentsProcessingEventsHandler.cs} | 29 ++-- .../DesignMode/DesignModeClient.cs | 24 +-- .../RequestHelper/ITestRequestManager.cs | 12 +- ...> ITestRunAttachmentsProcessingManager.cs} | 14 +- .../Telemetry/TelemetryDataConstants.cs | 12 +- .../Messages/MessageType.cs | 16 +- ...unAttachmentsProcessingCompletePayload.cs} | 8 +- ...unAttachmentsProcessingProgressPayload.cs} | 8 +- .../Interfaces/ITestPlatformEventSource.cs | 24 +-- .../Tracing/TestPlatformEventSource.cs | 36 ++-- .../TestPlatformInstrumentationEvents.cs | 24 +-- .../TestRunAttachmentsProcessingManager.cs} | 72 ++++---- .../Parallel/ParallelProxyExecutionManager.cs | 6 +- .../ParallelDataCollectionEventsHandler.cs | 8 +- ...AttachmentsProcessingCompleteEventArgs.cs} | 12 +- ...AttachmentsProcessingProgressEventArgs.cs} | 4 +- .../IMultiTestRunFinalizationEventsHandler.cs | 32 ---- ...stRunAttachmentsProcessingEventsHandler.cs | 32 ++++ ...=> TestRunAttachmentsProcessingPayload.cs} | 4 +- .../ITranslationLayerRequestSenderAsync.cs | 4 +- .../Interfaces/IVsTestConsoleWrapperAsync.cs | 2 +- .../Resources/Resources.Designer.cs | 6 +- .../Resources/Resources.resx | 4 +- .../Resources/xlf/Resources.cs.xlf | 6 +- .../Resources/xlf/Resources.de.xlf | 6 +- .../Resources/xlf/Resources.es.xlf | 6 +- .../Resources/xlf/Resources.fr.xlf | 6 +- .../Resources/xlf/Resources.it.xlf | 6 +- .../Resources/xlf/Resources.ja.xlf | 6 +- .../Resources/xlf/Resources.ko.xlf | 6 +- .../Resources/xlf/Resources.pl.xlf | 6 +- .../Resources/xlf/Resources.pt-BR.xlf | 6 +- .../Resources/xlf/Resources.ru.xlf | 6 +- .../Resources/xlf/Resources.tr.xlf | 6 +- .../Resources/xlf/Resources.xlf | 6 +- .../Resources/xlf/Resources.zh-Hans.xlf | 6 +- .../Resources/xlf/Resources.zh-Hant.xlf | 6 +- .../VsTestConsoleRequestSender.cs | 36 ++-- .../VsTestConsoleWrapper.cs | 6 +- .../TestPlatformHelpers/TestRequestManager.cs | 54 +++--- .../CodeCoverageTests.cs | 116 ++++++------- ...stRunAttachmentsProcessingEventHandler.cs} | 24 +-- ...ttachmentsProcessingEventsHandlerTests.cs} | 28 ++-- .../DesignMode/DesignModeClientTests.cs | 72 ++++---- ...stRunAttachmentsProcessingManagerTests.cs} | 150 ++++++++--------- ...arallelDataCollectionEventsHandlerTests.cs | 18 +- .../VsTestConsoleRequestSenderTests.cs | 154 +++++++++--------- .../VsTestConsoleWrapperAsyncTests.cs | 8 +- .../VsTestConsoleWrapperTests.cs | 8 +- ...llyQualifiedTestsArgumentProcessorTests.cs | 20 +-- .../ListTestsArgumentProcessorTests.cs | 18 +- .../RunSpecificTestsArgumentProcessorTests.cs | 48 +++--- .../RunTestsArgumentProcessorTests.cs | 18 +- .../TestRequestManagerTests.cs | 118 +++++++------- 54 files changed, 687 insertions(+), 686 deletions(-) rename src/Microsoft.TestPlatform.Client/{MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs => AttachmentsProcessing/TestRunAttachmentsProcessingEventsHandler.cs} (55%) rename src/Microsoft.TestPlatform.Common/Interfaces/Engine/{IMultiTestRunFinalizationManager.cs => ITestRunAttachmentsProcessingManager.cs} (59%) rename src/Microsoft.TestPlatform.CommunicationUtilities/Messages/{MultiTestRunFinalizationCompletePayload.cs => TestRunAttachmentsProcessingCompletePayload.cs} (68%) rename src/Microsoft.TestPlatform.CommunicationUtilities/Messages/{MultiTestRunFinalizationProgressPayload.cs => TestRunAttachmentsProcessingProgressPayload.cs} (57%) rename src/Microsoft.TestPlatform.CrossPlatEngine/{MultiTestRunFinalization/MultiTestRunFinalizationManager.cs => AttachmentsProcessing/TestRunAttachmentsProcessingManager.cs} (56%) rename src/Microsoft.TestPlatform.ObjectModel/Client/Events/{MultiTestRunFinalizationCompleteEventArgs.cs => TestRunAttachmentsProcessingCompleteEventArgs.cs} (65%) rename src/Microsoft.TestPlatform.ObjectModel/Client/Events/{MultiTestRunFinalizationProgressEventArgs.cs => TestRunAttachmentsProcessingProgressEventArgs.cs} (87%) delete mode 100644 src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs create mode 100644 src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestRunAttachmentsProcessingEventsHandler.cs rename src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/{MultiTestRunFinalizationPayload.cs => TestRunAttachmentsProcessingPayload.cs} (79%) rename test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/{MultiTestRunFinalizationEventHandler.cs => TestRunAttachmentsProcessingEventHandler.cs} (68%) rename test/Microsoft.TestPlatform.Client.UnitTests/{MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs => AttachmentsProcessing/TestRunAttachmentsProcessingEventsHandlerTests.cs} (57%) rename test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/{MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs => AttachmentsProcessing/TestRunAttachmentsProcessingManagerTests.cs} (74%) diff --git a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.Client/AttachmentsProcessing/TestRunAttachmentsProcessingEventsHandler.cs similarity index 55% rename from src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs rename to src/Microsoft.TestPlatform.Client/AttachmentsProcessing/TestRunAttachmentsProcessingEventsHandler.cs index f0359712de..3a5674db16 100644 --- a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.Client/AttachmentsProcessing/TestRunAttachmentsProcessingEventsHandler.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization +namespace Microsoft.VisualStudio.TestPlatform.Client.TestRunAttachmentsProcessing { using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; @@ -11,47 +11,48 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization using System.Collections.Generic; /// - /// The multi test finalization events handler. + /// The test run attachments processing events handler. /// - public class MultiTestRunFinalizationEventsHandler : IMultiTestRunFinalizationEventsHandler + /// + public class TestRunAttachmentsProcessingEventsHandler : ITestRunAttachmentsProcessingEventsHandler { private readonly ICommunicationManager communicationManager; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The communication manager. - public MultiTestRunFinalizationEventsHandler(ICommunicationManager communicationManager) + public TestRunAttachmentsProcessingEventsHandler(ICommunicationManager communicationManager) { this.communicationManager = communicationManager; } /// - public void HandleMultiTestRunFinalizationComplete(MultiTestRunFinalizationCompleteEventArgs finalizationCompleteEventArgs, IEnumerable lastChunk) + public void HandleTestRunAttachmentsProcessingComplete(TestRunAttachmentsProcessingCompleteEventArgs attachmentsProcessingCompleteEventArgs, IEnumerable lastChunk) { if (EqtTrace.IsInfoEnabled) { - EqtTrace.Info("Multi test run finalization completed."); + EqtTrace.Info("Test run attachments processing completed."); } - var payload = new MultiTestRunFinalizationCompletePayload() + var payload = new TestRunAttachmentsProcessingCompletePayload() { - FinalizationCompleteEventArgs = finalizationCompleteEventArgs, + AttachmentsProcessingCompleteEventArgs = attachmentsProcessingCompleteEventArgs, Attachments = lastChunk }; - this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationComplete, payload); + this.communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, payload); } /// - public void HandleMultiTestRunFinalizationProgress(MultiTestRunFinalizationProgressEventArgs finalizationProgressEventArgs) + public void HandleTestRunAttachmentsProcessingProgress(TestRunAttachmentsProcessingProgressEventArgs AttachmentsProcessingProgressEventArgs) { - var payload = new MultiTestRunFinalizationProgressPayload() + var payload = new TestRunAttachmentsProcessingProgressPayload() { - FinalizationProgressEventArgs = finalizationProgressEventArgs, + AttachmentsProcessingProgressEventArgs = AttachmentsProcessingProgressEventArgs, }; - this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationProgress, payload); + this.communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingProgress, payload); } /// diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index d49af32336..6b16b27a55 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode using System.Net; using System.Threading; using System.Threading.Tasks; - using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization; + using Microsoft.VisualStudio.TestPlatform.Client.TestRunAttachmentsProcessing; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; @@ -199,11 +199,11 @@ private void ProcessRequests(ITestRequestManager testRequestManager) break; } - case MessageType.MultiTestRunFinalizationStart: + case MessageType.TestRunAttachmentsProcessingStart: { - var multiTestRunFinalizationPayload = - this.communicationManager.DeserializePayload(message); - this.StartMultiTestRunFinalization(multiTestRunFinalizationPayload, testRequestManager); + var testRunAttachmentsProcessingPayload = + this.communicationManager.DeserializePayload(message); + this.StartTestRunAttachmentsProcessing(testRunAttachmentsProcessingPayload, testRequestManager); break; } @@ -225,9 +225,9 @@ private void ProcessRequests(ITestRequestManager testRequestManager) break; } - case MessageType.MultiTestRunFinalizationCancel: + case MessageType.TestRunAttachmentsProcessingCancel: { - testRequestManager.CancelMultiTestRunFinalization(); + testRequestManager.CancelTestRunAttachmentsProcessing(); break; } @@ -472,29 +472,29 @@ private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITe }); } - private void StartMultiTestRunFinalization(MultiTestRunFinalizationPayload finalizationPayload, ITestRequestManager testRequestManager) + private void StartTestRunAttachmentsProcessing(TestRunAttachmentsProcessingPayload attachmentsProcessingPayload, ITestRequestManager testRequestManager) { Task.Run( delegate { try { - testRequestManager.FinalizeMultiTestRun(finalizationPayload, new MultiTestRunFinalizationEventsHandler(this.communicationManager), this.protocolConfig); + testRequestManager.ProcessTestRunAttachments(attachmentsProcessingPayload, new TestRunAttachmentsProcessingEventsHandler(this.communicationManager), this.protocolConfig); } catch (Exception ex) { - EqtTrace.Error("DesignModeClient: Exception in StartMultiTestRunFinalization: " + ex); + EqtTrace.Error("DesignModeClient: Exception in StartTestRunAttachmentsProcessing: " + ex); var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() }; this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); - var payload = new MultiTestRunFinalizationCompletePayload() + var payload = new TestRunAttachmentsProcessingCompletePayload() { Attachments = null }; // Send run complete to translation layer - this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationComplete, payload); + this.communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, payload); } }); } diff --git a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs index eb18c4fa0b..0a0e68e301 100644 --- a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs +++ b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs @@ -45,11 +45,11 @@ public interface ITestRequestManager : IDisposable void RunTests(TestRunRequestPayload testRunRequestPayLoad, ITestHostLauncher customTestHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig); /// - /// Finalize multi test run + /// Processes test run attachments /// - /// Multi test run finalization payload - /// Multi test run finalization events handler - void FinalizeMultiTestRun(MultiTestRunFinalizationPayload multiTestRunFinalizationPayload, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationEventsHandler, ProtocolConfig protocolConfig); + /// Test run attachments processing payload + /// Test run attachments processing events handler + void ProcessTestRunAttachments(TestRunAttachmentsProcessingPayload testRunAttachmentsProcessingPayload, ITestRunAttachmentsProcessingEventsHandler testRunAttachmentsProcessingEventsHandler, ProtocolConfig protocolConfig); /// /// Cancel the current TestRun request @@ -67,8 +67,8 @@ public interface ITestRequestManager : IDisposable void CancelDiscovery(); /// - /// Cancels the current multi test run finalization request + /// Cancels the current test run attachments processing request /// - void CancelMultiTestRunFinalization(); + void CancelTestRunAttachmentsProcessing(); } } diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/ITestRunAttachmentsProcessingManager.cs similarity index 59% rename from src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs rename to src/Microsoft.TestPlatform.Common/Interfaces/Engine/ITestRunAttachmentsProcessingManager.cs index d13ea35f71..d6b88d89c8 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/IMultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/ITestRunAttachmentsProcessingManager.cs @@ -10,24 +10,24 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine { /// - /// Orchestrates multi test run finalization operations. + /// Orchestrates test run attachments processing operations. /// - internal interface IMultiTestRunFinalizationManager + internal interface ITestRunAttachmentsProcessingManager { /// - /// Finalizes multi test run and provides results through handler + /// Processes attachments and provides results through handler /// /// Collection of attachments - /// EventHandler for handling multi test run finalization event + /// EventHandler for handling test run attachments processing event /// Cancellation token - Task FinalizeMultiTestRunAsync(IRequestData requestData, IEnumerable attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken); + Task ProcessTestRunAttachmentsAsync(IRequestData requestData, IEnumerable attachments, ITestRunAttachmentsProcessingEventsHandler eventHandler, CancellationToken cancellationToken); /// - /// Finalizes multi test run + /// Processes attachments /// /// Collection of attachments /// Cancellation token /// Collection of attachments. - Task> FinalizeMultiTestRunAsync(IRequestData requestData, IEnumerable attachments, CancellationToken cancellationToken); + Task> ProcessTestRunAttachmentsAsync(IRequestData requestData, IEnumerable attachments, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.Common/Telemetry/TelemetryDataConstants.cs b/src/Microsoft.TestPlatform.Common/Telemetry/TelemetryDataConstants.cs index 671350a63e..be35c610c2 100644 --- a/src/Microsoft.TestPlatform.Common/Telemetry/TelemetryDataConstants.cs +++ b/src/Microsoft.TestPlatform.Common/Telemetry/TelemetryDataConstants.cs @@ -90,19 +90,19 @@ public static class TelemetryDataConstants public static string NumberOfAdapterUsedToDiscoverTests = "VS.TestDiscovery.AdaptersUsedCount"; - // *********************Finalization**************************** - public static string NumberOfAttachmentsSentForFinalization = "VS.TestFinalization.InitialAttachmentsCount"; + // *********************Attachments Processing**************************** + public static string NumberOfAttachmentsSentForProcessing = "VS.AttachmentsProcessing.InitialAttachmentsCount"; - public static string NumberOfAttachmentsAfterFinalization = "VS.TestFinalization.FinalAttachmentsCount"; + public static string NumberOfAttachmentsAfterProcessing = "VS.AttachmentsProcessing.FinalAttachmentsCount"; - public static string TimeTakenInSecForFinalization = "VS.TestFinalization.TotalTimeTakenInSec"; - public static string FinalizationState = "VS.TestFinalization.FinalizationState"; + public static string TimeTakenInSecForAttachmentsProcessing = "VS.AttachmentsProcessing.TotalTimeTakenInSec"; + public static string AttachmentsProcessingState = "VS.AttachmentsProcessing.State"; // **************Events Name ********************************** public static string TestDiscoveryCompleteEvent = "vs/testplatform/testdiscoverysession"; public static string TestExecutionCompleteEvent = "vs/testplatform/testrunsession"; - public static string TestFinalizationCompleteEvent = "vs/testplatform/testfinalizationsession"; + public static string TestAttachmentsProcessingCompleteEvent = "vs/testplatform/testattachmentsprocessingsession"; } } diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs index 802c8e5c87..76cfeec873 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs @@ -124,24 +124,24 @@ public static class MessageType public const string CustomTestHostLaunchCallback = "TestExecution.CustomTestHostLaunchCallback"; /// - /// Multi test run finalization + /// Test run attachments processing /// - public const string MultiTestRunFinalizationStart = "MultiTestRunFinalization.Start"; + public const string TestRunAttachmentsProcessingStart = "TestRunAttachmentsProcessing.Start"; /// - /// Multi test run finalization callback + /// Test run attachments processing callback /// - public const string MultiTestRunFinalizationComplete = "MultiTestRunFinalization.Complete"; + public const string TestRunAttachmentsProcessingComplete = "TestRunAttachmentsProcessing.Complete"; /// - /// Multi test run finalization progress + /// Test run attachments processing progress /// - public const string MultiTestRunFinalizationProgress = "MultiTestRunFinalization.Progress"; + public const string TestRunAttachmentsProcessingProgress = "TestRunAttachmentsProcessing.Progress"; /// - /// Cancel multi test run finalization + /// Cancel test run attachments processing /// - public const string MultiTestRunFinalizationCancel = "MultiTestRunFinalization.Cancel"; + public const string TestRunAttachmentsProcessingCancel = "TestRunAttachmentsProcessing.Cancel"; /// /// Extensions Initialization diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationCompletePayload.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestRunAttachmentsProcessingCompletePayload.cs similarity index 68% rename from src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationCompletePayload.cs rename to src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestRunAttachmentsProcessingCompletePayload.cs index 4d9ef24169..40ac9c4c8b 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationCompletePayload.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestRunAttachmentsProcessingCompletePayload.cs @@ -9,14 +9,14 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; /// - /// Multi test run finalization complete payload. + /// Test run attachments processing complete payload. /// - public class MultiTestRunFinalizationCompletePayload + public class TestRunAttachmentsProcessingCompletePayload { /// - /// Gets or sets the multi test run finalization complete args. + /// Gets or sets the test run attachments processing complete args. /// - public MultiTestRunFinalizationCompleteEventArgs FinalizationCompleteEventArgs { get; set; } + public TestRunAttachmentsProcessingCompleteEventArgs AttachmentsProcessingCompleteEventArgs { get; set; } /// /// Gets or sets the attachments. diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationProgressPayload.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestRunAttachmentsProcessingProgressPayload.cs similarity index 57% rename from src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationProgressPayload.cs rename to src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestRunAttachmentsProcessingProgressPayload.cs index 6190ada03c..80082ae30d 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MultiTestRunFinalizationProgressPayload.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/TestRunAttachmentsProcessingProgressPayload.cs @@ -6,13 +6,13 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; /// - /// Multi test run finalization complete payload. + /// Test run attachments processing complete payload. /// - public class MultiTestRunFinalizationProgressPayload + public class TestRunAttachmentsProcessingProgressPayload { /// - /// Gets or sets the multi test run finalization complete args. + /// Gets or sets the test run attachments processing complete args. /// - public MultiTestRunFinalizationProgressEventArgs FinalizationProgressEventArgs { get; set; } + public TestRunAttachmentsProcessingProgressEventArgs AttachmentsProcessingProgressEventArgs { get; set; } } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs index 262803cf48..7f88ccbf83 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs @@ -184,39 +184,39 @@ public interface ITestPlatformEventSource void MetricsDisposeStop(); /// - /// The multi test run finalization request start. + /// The test run attachments processing request start. /// - void MultiTestRunFinalizationRequestStart(); + void TestRunAttachmentsProcessingRequestStart(); /// - /// The multi test run finalization request stop. + /// The test run attachments processing request stop. /// - void MultiTestRunFinalizationRequestStop(); + void TestRunAttachmentsProcessingRequestStop(); /// - /// The multi test run finalization start. + /// The test run attachments processing start. /// /// /// The number of attachments. /// - void MultiTestRunFinalizationStart(long numberOfAttachments); + void TestRunAttachmentsProcessingStart(long numberOfAttachments); /// - /// The multi test run finalization stop. + /// The test run attachments processing stop. /// /// /// The number of attachments. /// - void MultiTestRunFinalizationStop(long numberOfAttachments); + void TestRunAttachmentsProcessingStop(long numberOfAttachments); /// - /// Mark the start of translation layer multi test run finalization request. + /// Mark the start of translation layer test run attachments processing request. /// - void TranslationLayerMultiTestRunFinalizationStart(); + void TranslationLayerTestRunAttachmentsProcessingStart(); /// - /// Mark the completion of translation layer multi test run finalization request. + /// Mark the completion of translation layer test run attachments processing request. /// - void TranslationLayerMultiTestRunFinalizationStop(); + void TranslationLayerTestRunAttachmentsProcessingStop(); } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs index cf7a4f5845..74adb6a2af 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs @@ -239,45 +239,45 @@ public void MetricsDisposeStop() } /// - [Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationRequestStartEventId)] - public void MultiTestRunFinalizationRequestStart() + [Event(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingRequestStartEventId)] + public void TestRunAttachmentsProcessingRequestStart() { - this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationRequestStartEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingRequestStartEventId); } /// - [Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationRequestStopEventId)] - public void MultiTestRunFinalizationRequestStop() + [Event(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingRequestStopEventId)] + public void TestRunAttachmentsProcessingRequestStop() { - this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationRequestStopEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingRequestStopEventId); } /// - [Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId)] - public void MultiTestRunFinalizationStart(long numberOfAttachments) + [Event(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingStartEventId)] + public void TestRunAttachmentsProcessingStart(long numberOfAttachments) { - this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId, numberOfAttachments); + this.WriteEvent(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingStartEventId, numberOfAttachments); } /// - [Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStopEventId)] - public void MultiTestRunFinalizationStop(long numberOfAttachments) + [Event(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingStopEventId)] + public void TestRunAttachmentsProcessingStop(long numberOfAttachments) { - this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStopEventId, numberOfAttachments); + this.WriteEvent(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingStopEventId, numberOfAttachments); } /// - [Event(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunFinalizationStartEventId)] - public void TranslationLayerMultiTestRunFinalizationStart() + [Event(TestPlatformInstrumentationEvents.TranslationLayerTestRunAttachmentsProcessingStartEventId)] + public void TranslationLayerTestRunAttachmentsProcessingStart() { - this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunFinalizationStartEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerTestRunAttachmentsProcessingStartEventId); } /// - [Event(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunFinalizationStopEventId)] - public void TranslationLayerMultiTestRunFinalizationStop() + [Event(TestPlatformInstrumentationEvents.TranslationLayerTestRunAttachmentsProcessingStopEventId)] + public void TranslationLayerTestRunAttachmentsProcessingStop() { - this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerMultiTestRunFinalizationStopEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerTestRunAttachmentsProcessingStopEventId); } } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs index 2fa7f1e87a..1aa2311048 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs @@ -159,33 +159,33 @@ internal class TestPlatformInstrumentationEvents public const int MetricsDisposeStopEventId = 0x39; /// - /// The session finalization start event id. + /// The session attachments processing start event id. /// - public const int MultiTestRunFinalizationStartEventId = 0x40; + public const int TestRunAttachmentsProcessingStartEventId = 0x40; /// - /// The session finalization stop event id. + /// The session attachments processing stop event id. /// - public const int MultiTestRunFinalizationStopEventId = 0x41; + public const int TestRunAttachmentsProcessingStopEventId = 0x41; /// - /// The session finalization request start event id. + /// The session attachments processing request start event id. /// - public const int MultiTestRunFinalizationRequestStartEventId = 0x42; + public const int TestRunAttachmentsProcessingRequestStartEventId = 0x42; /// - /// The session finalization request stop event id. + /// The session attachments processing request stop event id. /// - public const int MultiTestRunFinalizationRequestStopEventId = 0x43; + public const int TestRunAttachmentsProcessingRequestStopEventId = 0x43; /// - /// Events fired on session finalization start of translation layer. + /// Events fired on session attachments processing start of translation layer. /// - public const int TranslationLayerMultiTestRunFinalizationStartEventId = 0x44; + public const int TranslationLayerTestRunAttachmentsProcessingStartEventId = 0x44; /// - /// Events fired on session finalization complete in translation layer. + /// Events fired on session attachments processing complete in translation layer. /// - public const int TranslationLayerMultiTestRunFinalizationStopEventId = 0x45; + public const int TranslationLayerTestRunAttachmentsProcessingStopEventId = 0x45; } } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/AttachmentsProcessing/TestRunAttachmentsProcessingManager.cs similarity index 56% rename from src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs rename to src/Microsoft.TestPlatform.CrossPlatEngine/AttachmentsProcessing/TestRunAttachmentsProcessingManager.cs index d98e034d5c..6eff75838a 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/AttachmentsProcessing/TestRunAttachmentsProcessingManager.cs @@ -16,48 +16,48 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; -namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization +namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestRunAttachmentsProcessing { /// - /// Orchestrates multi test run finalization operations. + /// Orchestrates test run attachments processing operations. /// - public class MultiTestRunFinalizationManager : IMultiTestRunFinalizationManager + public class TestRunAttachmentsProcessingManager : ITestRunAttachmentsProcessingManager { - private static string FinalizationCompleted = "Completed"; - private static string FinalizationCanceled = "Canceled"; - private static string FinalizationFailed = "Failed"; + private static string AttachmentsProcessingCompleted = "Completed"; + private static string AttachmentsProcessingCanceled = "Canceled"; + private static string AttachmentsProcessingFailed = "Failed"; private readonly ITestPlatformEventSource testPlatformEventSource; private readonly IDataCollectorAttachmentProcessor[] dataCollectorAttachmentsProcessors; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public MultiTestRunFinalizationManager(ITestPlatformEventSource testPlatformEventSource, params IDataCollectorAttachmentProcessor[] dataCollectorAttachmentsProcessors) + public TestRunAttachmentsProcessingManager(ITestPlatformEventSource testPlatformEventSource, params IDataCollectorAttachmentProcessor[] dataCollectorAttachmentsProcessors) { this.testPlatformEventSource = testPlatformEventSource ?? throw new ArgumentNullException(nameof(testPlatformEventSource)); this.dataCollectorAttachmentsProcessors = dataCollectorAttachmentsProcessors ?? throw new ArgumentNullException(nameof(dataCollectorAttachmentsProcessors)); } /// - public async Task FinalizeMultiTestRunAsync(IRequestData requestData, IEnumerable attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) + public async Task ProcessTestRunAttachmentsAsync(IRequestData requestData, IEnumerable attachments, ITestRunAttachmentsProcessingEventsHandler eventHandler, CancellationToken cancellationToken) { - await InternalFinalizeMultiTestRunAsync(requestData, new Collection(attachments.ToList()), eventHandler, cancellationToken).ConfigureAwait(false); + await InternalProcessTestRunAttachmentsAsync(requestData, new Collection(attachments.ToList()), eventHandler, cancellationToken).ConfigureAwait(false); } /// - public Task> FinalizeMultiTestRunAsync(IRequestData requestData, IEnumerable attachments, CancellationToken cancellationToken) + public Task> ProcessTestRunAttachmentsAsync(IRequestData requestData, IEnumerable attachments, CancellationToken cancellationToken) { - return InternalFinalizeMultiTestRunAsync(requestData, new Collection(attachments.ToList()), null, cancellationToken); + return InternalProcessTestRunAttachmentsAsync(requestData, new Collection(attachments.ToList()), null, cancellationToken); } - private async Task> InternalFinalizeMultiTestRunAsync(IRequestData requestData, Collection attachments, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) + private async Task> InternalProcessTestRunAttachmentsAsync(IRequestData requestData, Collection attachments, ITestRunAttachmentsProcessingEventsHandler eventHandler, CancellationToken cancellationToken) { Stopwatch stopwatch = Stopwatch.StartNew(); try { - testPlatformEventSource.MultiTestRunFinalizationStart(attachments?.Count ?? 0); - requestData.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsSentForFinalization, attachments?.Count ?? 0); + testPlatformEventSource.TestRunAttachmentsProcessingStart(attachments?.Count ?? 0); + requestData.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsSentForProcessing, attachments?.Count ?? 0); cancellationToken.ThrowIfCancellationRequested(); @@ -70,12 +70,12 @@ private async Task> InternalFinalizeMultiTestRunAsync( if (completedTask == task) { - return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, null), await task, stopwatch, eventHandler); + return FinalizeOperation(requestData, new TestRunAttachmentsProcessingCompleteEventArgs(false, null), await task, stopwatch, eventHandler); } else { - eventHandler?.HandleLogMessage(TestMessageLevel.Informational, "Finalization was cancelled."); - return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, null), attachments, stopwatch, eventHandler); + eventHandler?.HandleLogMessage(TestMessageLevel.Informational, "Attachments processing was cancelled."); + return FinalizeOperation(requestData, new TestRunAttachmentsProcessingCompleteEventArgs(true, null), attachments, stopwatch, eventHandler); } } } @@ -83,20 +83,20 @@ private async Task> InternalFinalizeMultiTestRunAsync( { if (EqtTrace.IsWarningEnabled) { - EqtTrace.Warning("MultiTestRunFinalizationManager: operation was cancelled."); + EqtTrace.Warning("TestRunAttachmentsProcessingManager: operation was cancelled."); } - return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, null), attachments, stopwatch, eventHandler); + return FinalizeOperation(requestData, new TestRunAttachmentsProcessingCompleteEventArgs(true, null), attachments, stopwatch, eventHandler); } catch (Exception e) { - EqtTrace.Error("MultiTestRunFinalizationManager: Exception in FinalizeMultiTestRunAsync: " + e); + EqtTrace.Error("TestRunAttachmentsProcessingManager: Exception in ProcessTestRunAttachmentsAsync: " + e); eventHandler?.HandleLogMessage(TestMessageLevel.Error, e.Message); - return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, e), attachments, stopwatch, eventHandler); + return FinalizeOperation(requestData, new TestRunAttachmentsProcessingCompleteEventArgs(false, e), attachments, stopwatch, eventHandler); } } - private async Task> ProcessAttachmentsAsync(Collection attachments, IMultiTestRunFinalizationEventsHandler eventsHandler, CancellationToken cancellationToken) + private async Task> ProcessAttachmentsAsync(Collection attachments, ITestRunAttachmentsProcessingEventsHandler eventsHandler, CancellationToken cancellationToken) { if (attachments == null || !attachments.Any()) return attachments; @@ -119,8 +119,8 @@ private async Task> ProcessAttachmentsAsync(Collection } IProgress progressReporter = new Progress((int progress) => - eventsHandler?.HandleMultiTestRunFinalizationProgress( - new MultiTestRunFinalizationProgressEventArgs(attachmentsHandlerIndex, attachmentProcessorUris, progress, dataCollectorAttachmentsProcessors.Length))); + eventsHandler?.HandleTestRunAttachmentsProcessingProgress( + new TestRunAttachmentsProcessingProgressEventArgs(attachmentsHandlerIndex, attachmentProcessorUris, progress, dataCollectorAttachmentsProcessors.Length))); ICollection processedAttachments = await dataCollectorAttachmentsProcessor.ProcessAttachmentSetsAsync(new Collection(attachmentsToBeProcessed), progressReporter, logger, cancellationToken).ConfigureAwait(false); @@ -135,31 +135,31 @@ private async Task> ProcessAttachmentsAsync(Collection return attachments; } - private Collection FinalizeOperation(IRequestData requestData, MultiTestRunFinalizationCompleteEventArgs completeArgs, Collection attachments, Stopwatch stopwatch, IMultiTestRunFinalizationEventsHandler eventHandler) + private Collection FinalizeOperation(IRequestData requestData, TestRunAttachmentsProcessingCompleteEventArgs completeArgs, Collection attachments, Stopwatch stopwatch, ITestRunAttachmentsProcessingEventsHandler eventHandler) { - testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); - requestData.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsAfterFinalization, attachments.Count); - requestData.MetricsCollection.Add(TelemetryDataConstants.FinalizationState, completeArgs.Error != null ? FinalizationFailed : completeArgs.IsCanceled ? FinalizationCanceled : FinalizationCompleted); + testPlatformEventSource.TestRunAttachmentsProcessingStop(attachments.Count); + requestData.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsAfterProcessing, attachments.Count); + requestData.MetricsCollection.Add(TelemetryDataConstants.AttachmentsProcessingState, completeArgs.Error != null ? AttachmentsProcessingFailed : completeArgs.IsCanceled ? AttachmentsProcessingCanceled : AttachmentsProcessingCompleted); stopwatch.Stop(); - requestData.MetricsCollection.Add(TelemetryDataConstants.TimeTakenInSecForFinalization, stopwatch.Elapsed.TotalSeconds); + requestData.MetricsCollection.Add(TelemetryDataConstants.TimeTakenInSecForAttachmentsProcessing, stopwatch.Elapsed.TotalSeconds); completeArgs.Metrics = requestData.MetricsCollection.Metrics; - eventHandler?.HandleMultiTestRunFinalizationComplete(completeArgs, attachments); + eventHandler?.HandleTestRunAttachmentsProcessingComplete(completeArgs, attachments); return attachments; } - private IMessageLogger CreateMessageLogger(IMultiTestRunFinalizationEventsHandler eventsHandler) + private IMessageLogger CreateMessageLogger(ITestRunAttachmentsProcessingEventsHandler eventsHandler) { - return eventsHandler != null ? (IMessageLogger)new FinalizationMessageLogger(eventsHandler) : new NullMessageLogger(); + return eventsHandler != null ? (IMessageLogger)new AttachmentsProcessingMessageLogger(eventsHandler) : new NullMessageLogger(); } - private class FinalizationMessageLogger : IMessageLogger + private class AttachmentsProcessingMessageLogger : IMessageLogger { - private readonly IMultiTestRunFinalizationEventsHandler eventsHandler; + private readonly ITestRunAttachmentsProcessingEventsHandler eventsHandler; - public FinalizationMessageLogger(IMultiTestRunFinalizationEventsHandler eventsHandler) + public AttachmentsProcessingMessageLogger(ITestRunAttachmentsProcessingEventsHandler eventsHandler) { this.eventsHandler = eventsHandler ?? throw new ArgumentNullException(nameof(eventsHandler)); } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs index 86df14a387..d5cc0cecb4 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs @@ -16,7 +16,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestRunAttachmentsProcessing; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; @@ -262,7 +262,7 @@ private ParallelRunEventsHandler GetEventsHandler(IProxyExecutionManager concurr var concurrentManagerWithDataCollection = concurrentManager as ProxyExecutionManagerWithDataCollection; // TODO : use TestPluginCache to iterate over all IDataCollectorAttachments - var finalizationManager = new MultiTestRunFinalizationManager(TestPlatformEventSource.Instance, new CodeCoverageDataAttachmentsHandler()); + var attachmentsProcessingManager = new TestRunAttachmentsProcessingManager(TestPlatformEventSource.Instance, new CodeCoverageDataAttachmentsHandler()); return new ParallelDataCollectionEventsHandler( this.requestData, @@ -270,7 +270,7 @@ private ParallelRunEventsHandler GetEventsHandler(IProxyExecutionManager concurr this.currentRunEventsHandler, this, this.currentRunDataAggregator, - finalizationManager, + attachmentsProcessingManager, concurrentManagerWithDataCollection.CancellationToken); } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs index f6c2ea0829..a50d5fe6ff 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ParallelDataCollectionEventsHandler.cs @@ -16,7 +16,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection internal class ParallelDataCollectionEventsHandler : ParallelRunEventsHandler { private readonly ParallelRunDataAggregator runDataAggregator; - private readonly IMultiTestRunFinalizationManager finalizationManager; + private readonly ITestRunAttachmentsProcessingManager attachmentsProcessingManager; private readonly CancellationToken cancellationToken; public ParallelDataCollectionEventsHandler(IRequestData requestData, @@ -24,11 +24,11 @@ public ParallelDataCollectionEventsHandler(IRequestData requestData, ITestRunEventsHandler actualRunEventsHandler, IParallelProxyExecutionManager parallelProxyExecutionManager, ParallelRunDataAggregator runDataAggregator, - IMultiTestRunFinalizationManager finalizationManager, + ITestRunAttachmentsProcessingManager attachmentsProcessingManager, CancellationToken cancellationToken) : this(requestData, proxyExecutionManager, actualRunEventsHandler, parallelProxyExecutionManager, runDataAggregator, JsonDataSerializer.Instance) { - this.finalizationManager = finalizationManager; + this.attachmentsProcessingManager = attachmentsProcessingManager; this.cancellationToken = cancellationToken; } @@ -56,7 +56,7 @@ public override void HandleTestRunComplete( if (parallelRunComplete) { - runDataAggregator.RunContextAttachments = finalizationManager.FinalizeMultiTestRunAsync(requestData, runDataAggregator.RunContextAttachments, cancellationToken).Result ?? runDataAggregator.RunContextAttachments; + runDataAggregator.RunContextAttachments = attachmentsProcessingManager.ProcessTestRunAttachmentsAsync(requestData, runDataAggregator.RunContextAttachments, cancellationToken).Result ?? runDataAggregator.RunContextAttachments; var completedArgs = new TestRunCompleteEventArgs(this.runDataAggregator.GetAggregatedRunStats(), this.runDataAggregator.IsCanceled, diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/TestRunAttachmentsProcessingCompleteEventArgs.cs similarity index 65% rename from src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs rename to src/Microsoft.TestPlatform.ObjectModel/Client/Events/TestRunAttachmentsProcessingCompleteEventArgs.cs index 0ca669e6a1..b5e446ff68 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/TestRunAttachmentsProcessingCompleteEventArgs.cs @@ -8,27 +8,27 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client using System.Runtime.Serialization; [DataContract] - public class MultiTestRunFinalizationCompleteEventArgs : EventArgs + public class TestRunAttachmentsProcessingCompleteEventArgs : EventArgs { /// /// Default constructor. /// - /// Specifies whether the finalization is canceled. - /// Specifies the error encountered during the execution of the finalization. - public MultiTestRunFinalizationCompleteEventArgs(bool isCanceled, Exception error) + /// Specifies whether the attachments processing is canceled. + /// Specifies the error encountered during the execution of the attachments processing. + public TestRunAttachmentsProcessingCompleteEventArgs(bool isCanceled, Exception error) { this.IsCanceled = isCanceled; this.Error = error; } /// - /// Gets a value indicating whether the finalization is canceled or not. + /// Gets a value indicating whether the attachments processing is canceled or not. /// [DataMember] public bool IsCanceled { get; private set; } /// - /// Gets the error encountered during the finalization of the test runs. Null if there is no error. + /// Gets the error encountered during the attachments processing of the test runs. Null if there is no error. /// [DataMember] public Exception Error { get; private set; } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/TestRunAttachmentsProcessingProgressEventArgs.cs similarity index 87% rename from src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs rename to src/Microsoft.TestPlatform.ObjectModel/Client/Events/TestRunAttachmentsProcessingProgressEventArgs.cs index 9710add944..8218336e5b 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/TestRunAttachmentsProcessingProgressEventArgs.cs @@ -8,7 +8,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client using System.Runtime.Serialization; [DataContract] - public class MultiTestRunFinalizationProgressEventArgs : EventArgs + public class TestRunAttachmentsProcessingProgressEventArgs : EventArgs { /// /// Default constructor. @@ -17,7 +17,7 @@ public class MultiTestRunFinalizationProgressEventArgs : EventArgs /// Specifies current processor Uris. /// Specifies current processor progress. /// Specifies the overall number of processors. - public MultiTestRunFinalizationProgressEventArgs(long currentAttachmentProcessorIndex, ICollection currentAttachmentProcessorUris, long currentAttachmentProcessorProgress, long attachmentProcessorsCount) + public TestRunAttachmentsProcessingProgressEventArgs(long currentAttachmentProcessorIndex, ICollection currentAttachmentProcessorUris, long currentAttachmentProcessorProgress, long attachmentProcessorsCount) { CurrentAttachmentProcessorIndex = currentAttachmentProcessorIndex; CurrentAttachmentProcessorUris = currentAttachmentProcessorUris; diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs deleted file mode 100644 index 3983bd571e..0000000000 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs +++ /dev/null @@ -1,32 +0,0 @@ -// 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.Collections.Generic; - -namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client -{ - /// - /// Interface contract for handling multi test run finalization events - /// - public interface IMultiTestRunFinalizationEventsHandler : ITestMessageEventHandler - { - /// - /// Dispatch MultiTestRunFinalizationComplete event to listeners. - /// - /// Finalization Complete event args. - /// Last set of processed attachment sets. - void HandleMultiTestRunFinalizationComplete(MultiTestRunFinalizationCompleteEventArgs finalizationCompleteEventArgs, IEnumerable lastChunk); - - /// - /// Dispatch ProcessedAttachmentsChunk event to listeners. - /// - /// Processed attachment sets. - void HandleProcessedAttachmentsChunk(IEnumerable attachments); - - /// - /// Dispatch MultiTestRunFinalizationProgress event to listeners. - /// - /// Finalization Progress event args. - void HandleMultiTestRunFinalizationProgress(MultiTestRunFinalizationProgressEventArgs finalizationProgressEventArgs); - } -} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestRunAttachmentsProcessingEventsHandler.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestRunAttachmentsProcessingEventsHandler.cs new file mode 100644 index 0000000000..f6235a92e9 --- /dev/null +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestRunAttachmentsProcessingEventsHandler.cs @@ -0,0 +1,32 @@ +// 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.Collections.Generic; + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client +{ + /// + /// Interface contract for handling test run attachments processing events + /// + public interface ITestRunAttachmentsProcessingEventsHandler : ITestMessageEventHandler + { + /// + /// Dispatch TestRunAttachmentsProcessingComplete event to listeners. + /// + /// AttachmentsProcessing Complete event args. + /// Last set of processed attachment sets. + void HandleTestRunAttachmentsProcessingComplete(TestRunAttachmentsProcessingCompleteEventArgs attachmentsProcessingCompleteEventArgs, IEnumerable lastChunk); + + /// + /// Dispatch ProcessedAttachmentsChunk event to listeners. + /// + /// Processed attachment sets. + void HandleProcessedAttachmentsChunk(IEnumerable attachments); + + /// + /// Dispatch TestRunAttachmentsProcessingProgress event to listeners. + /// + /// AttachmentsProcessing Progress event args. + void HandleTestRunAttachmentsProcessingProgress(TestRunAttachmentsProcessingProgressEventArgs AttachmentsProcessingProgressEventArgs); + } +} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/TestRunAttachmentsProcessingPayload.cs similarity index 79% rename from src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs rename to src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/TestRunAttachmentsProcessingPayload.cs index 844b86e8dc..6abdb68082 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/MultiTestRunFinalizationPayload.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Payloads/TestRunAttachmentsProcessingPayload.cs @@ -7,9 +7,9 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client using System.Runtime.Serialization; /// - /// Class used to define the MultiTestRunFinalizationPayload sent by the Vstest.console translation layers into design mode + /// Class used to define the TestRunAttachmentsProcessingPayload sent by the Vstest.console translation layers into design mode /// - public class MultiTestRunFinalizationPayload + public class TestRunAttachmentsProcessingPayload { /// /// Collection of attachments. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs index 19ef32c915..23166126d7 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSenderAsync.cs @@ -53,8 +53,8 @@ internal interface ITranslationLayerRequestSenderAsync : IDisposable /// /// Collection of attachments /// Enables metrics collection - /// Events handler + /// Events handler /// Cancellation token - Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool collectMetrics, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); + Task ProcessTestRunAttachmentsAsync(IEnumerable attachments, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler testRunAttachmentsProcessingCompleteEventsHandler, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs index 14b32ab427..9c5af36304 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs @@ -100,7 +100,7 @@ public interface IVsTestConsoleWrapperAsync /// Enables metrics collection (used for telemetry) /// EventHandler to receive session complete event /// Cancellation token - Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool multiTestRunCompleted, bool collectMetrics, IMultiTestRunFinalizationEventsHandler eventsHandler, CancellationToken cancellationToken); + Task ProcessTestRunAttachmentsAsync(IEnumerable attachments, bool multiTestRunCompleted, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler eventsHandler, CancellationToken cancellationToken); /// /// See . diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs index d20d874ef0..a218efe7f5 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.Designer.cs @@ -62,11 +62,11 @@ internal Resources() { } /// - /// Looks up a localized string similar to The active Multi Test Runs Finalization was aborted.. + /// Looks up a localized string similar to The active Test Run Attachments Processing was aborted.. /// - public static string AbortedMultiTestRunFinalization { + public static string AbortedTestRunAttachmentsProcessing { get { - return ResourceManager.GetString("AbortedMultiTestRunFinalization", resourceCulture); + return ResourceManager.GetString("AbortedTestRunAttachmentsProcessing", resourceCulture); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx index ff17cc093a..eb053d0a74 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/Resources.resx @@ -117,8 +117,8 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. The active Tests Discovery was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.cs.xlf index 819e22e1d4..378546e5aa 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.cs.xlf @@ -61,9 +61,9 @@ Soubor {0} neexistuje. - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.de.xlf index 0b8284ad05..ead9e18cd3 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.de.xlf @@ -61,9 +61,9 @@ Die Datei "{0}" ist nicht vorhanden. - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.es.xlf index c3f256ea4f..704f3fc1d1 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.es.xlf @@ -61,9 +61,9 @@ El archivo {0} no existe - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.fr.xlf index 9a0dfc259c..788ee98fbb 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.fr.xlf @@ -61,9 +61,9 @@ Le fichier {0} n'existe pas - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.it.xlf index 1928a75bf6..471c34b6ce 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.it.xlf @@ -61,9 +61,9 @@ Il file {0} non esiste - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ja.xlf index 0c65c579e2..9bbf726d85 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ja.xlf @@ -61,9 +61,9 @@ ファイル {0} が存在しません - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ko.xlf index 273ff35d2c..250d2e203d 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ko.xlf @@ -61,9 +61,9 @@ {0} 파일이 없습니다. - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pl.xlf index 59a2514c1a..d9a8a303ef 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pl.xlf @@ -61,9 +61,9 @@ Plik {0} nie istnieje - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pt-BR.xlf index a2dfe8395f..ac67cd51d7 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.pt-BR.xlf @@ -61,9 +61,9 @@ O arquivo {0} não existe - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ru.xlf index d4c27e0dc4..40d4023b26 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.ru.xlf @@ -61,9 +61,9 @@ Файл {0} не существует. - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.tr.xlf index 8bc197a0b0..f1817063cc 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.tr.xlf @@ -61,9 +61,9 @@ {0} dosyası yok - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.xlf index 1772dac841..7c79b0d188 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.xlf @@ -23,9 +23,9 @@ File {0} does not exists - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hans.xlf index 6824d9b9db..35db394ca4 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hans.xlf @@ -61,9 +61,9 @@ 文件 {0} 不存在 - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hant.xlf index 2d27648708..77b761a7ee 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Resources/xlf/Resources.zh-Hant.xlf @@ -61,9 +61,9 @@ 檔案 {0} 不存在 - - The active Multi Test Runs Finalization was aborted. - The active Multi Test Runs Finalization was aborted. + + The active Test Run Attachments Processing was aborted. + The active Test Run Attachments Processing was aborted. diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index ef2c9644ec..f61b47fdce 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -384,9 +384,9 @@ public void EndSession() } /// - public Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool collectMetrics, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) + public Task ProcessTestRunAttachmentsAsync(IEnumerable attachments, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) { - return this.SendMessageAndListenAndReportFinalizationResultAsync(attachments, collectMetrics, testSessionEventsHandler, cancellationToken); + return this.SendMessageAndListenAndReportAttachmentsProcessingResultAsync(attachments, collectMetrics, testSessionEventsHandler, cancellationToken); } /// @@ -731,44 +731,44 @@ private async Task SendMessageAndListenAndReportTestResultsAsync(string messageT this.testPlatformEventSource.TranslationLayerExecutionStop(); } - private async Task SendMessageAndListenAndReportFinalizationResultAsync(IEnumerable attachments, bool collectMetrics, IMultiTestRunFinalizationEventsHandler eventHandler, CancellationToken cancellationToken) + private async Task SendMessageAndListenAndReportAttachmentsProcessingResultAsync(IEnumerable attachments, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler eventHandler, CancellationToken cancellationToken) { try { - var payload = new MultiTestRunFinalizationPayload + var payload = new TestRunAttachmentsProcessingPayload { Attachments = attachments, CollectMetrics = collectMetrics }; - this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationStart, payload); - var isMultiTestRunFinalizationComplete = false; + this.communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingStart, payload); + var isTestRunAttachmentsProcessingComplete = false; - using (cancellationToken.Register(() => this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationCancel))) + using (cancellationToken.Register(() => this.communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingCancel))) { // Cycle through the messages that the vstest.console sends. // Currently each of the operations are not separate tasks since they should not each take much time. // This is just a notification. - while (!isMultiTestRunFinalizationComplete) + while (!isTestRunAttachmentsProcessingComplete) { var message = await this.TryReceiveMessageAsync().ConfigureAwait(false); - if (string.Equals(MessageType.MultiTestRunFinalizationComplete, message.MessageType)) + if (string.Equals(MessageType.TestRunAttachmentsProcessingComplete, message.MessageType)) { if (EqtTrace.IsInfoEnabled) { EqtTrace.Info("VsTestConsoleRequestSender.SendMessageAndListenAndReportAttachments: Process complete."); } - var multiTestRunFinalizationCompletePayload = this.dataSerializer.DeserializePayload(message); + var testRunAttachmentsProcessingCompletePayload = this.dataSerializer.DeserializePayload(message); - eventHandler.HandleMultiTestRunFinalizationComplete(multiTestRunFinalizationCompletePayload.FinalizationCompleteEventArgs, multiTestRunFinalizationCompletePayload.Attachments); - isMultiTestRunFinalizationComplete = true; + eventHandler.HandleTestRunAttachmentsProcessingComplete(testRunAttachmentsProcessingCompletePayload.AttachmentsProcessingCompleteEventArgs, testRunAttachmentsProcessingCompletePayload.Attachments); + isTestRunAttachmentsProcessingComplete = true; } - else if (string.Equals(MessageType.MultiTestRunFinalizationProgress, message.MessageType)) + else if (string.Equals(MessageType.TestRunAttachmentsProcessingProgress, message.MessageType)) { - var multiTestRunFinalizationProgressPayload = this.dataSerializer.DeserializePayload(message); - eventHandler.HandleMultiTestRunFinalizationProgress(multiTestRunFinalizationProgressPayload.FinalizationProgressEventArgs); + var testRunAttachmentsProcessingProgressPayload = this.dataSerializer.DeserializePayload(message); + eventHandler.HandleTestRunAttachmentsProcessingProgress(testRunAttachmentsProcessingProgressPayload.AttachmentsProcessingProgressEventArgs); } else if (string.Equals(MessageType.TestMessage, message.MessageType)) { @@ -785,8 +785,8 @@ private async Task SendMessageAndListenAndReportFinalizationResultAsync(IEnumera catch (Exception exception) { EqtTrace.Error("Aborting Test Session End Operation: {0}", exception); - eventHandler.HandleLogMessage(TestMessageLevel.Error, TranslationLayerResources.AbortedMultiTestRunFinalization); - eventHandler.HandleMultiTestRunFinalizationComplete(new MultiTestRunFinalizationCompleteEventArgs(false, exception), null); + eventHandler.HandleLogMessage(TestMessageLevel.Error, TranslationLayerResources.AbortedTestRunAttachmentsProcessing); + eventHandler.HandleTestRunAttachmentsProcessingComplete(new TestRunAttachmentsProcessingCompleteEventArgs(false, exception), null); // Earlier we were closing the connection with vstest.console in case of exceptions // Removing that code because vstest.console might be in a healthy state and letting the client @@ -795,7 +795,7 @@ private async Task SendMessageAndListenAndReportFinalizationResultAsync(IEnumera } finally { - this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStop(); + this.testPlatformEventSource.TranslationLayerTestRunAttachmentsProcessingStop(); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index e2750b80fe..c92a85f9db 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -407,12 +407,12 @@ public async Task RunTestsWithCustomTestHostAsync(IEnumerable testCase } /// - public async Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool multiTestRunCompleted, bool collectMetrics, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) + public async Task ProcessTestRunAttachmentsAsync(IEnumerable attachments, bool multiTestRunCompleted, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) { - this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStart(); + this.testPlatformEventSource.TranslationLayerTestRunAttachmentsProcessingStart(); await this.EnsureInitializedAsync().ConfigureAwait(false); - await requestSender.FinalizeMultiTestRunAsync(attachments, collectMetrics, testSessionEventsHandler, cancellationToken).ConfigureAwait(false); + await requestSender.ProcessTestRunAttachmentsAsync(attachments, collectMetrics, testSessionEventsHandler, cancellationToken).ConfigureAwait(false); } #endregion diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index ac53184926..3fc25a44e8 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -13,7 +13,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers using System.Xml; using System.Xml.XPath; using Microsoft.VisualStudio.TestPlatform.Client; - using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization; + using Microsoft.VisualStudio.TestPlatform.Client.TestRunAttachmentsProcessing; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.CommandLine.Internal; using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities; @@ -26,7 +26,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestRunAttachmentsProcessing; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; @@ -53,7 +53,7 @@ internal class TestRequestManager : ITestRequestManager private readonly Task metricsPublisher; private bool isDisposed; private IProcessHelper processHelper; - private IMultiTestRunFinalizationManager finalizationManager; + private ITestRunAttachmentsProcessingManager attachmentsProcessingManager; /// /// Maintains the current active execution request @@ -68,10 +68,10 @@ internal class TestRequestManager : ITestRequestManager private IDiscoveryRequest currentDiscoveryRequest; /// - /// Maintains the current active multi test run finalization cancellation token source - /// Assumption : There can only be one active finalization request. + /// Maintains the current active test run attachments processing cancellation token source + /// Assumption : There can only be one active attachments processing request. /// - private CancellationTokenSource currentFinalizationCancellationTokenSource; + private CancellationTokenSource currentAttachmentsProcessingCancellationTokenSource; #region Constructor @@ -84,11 +84,11 @@ public TestRequestManager() new InferHelper(AssemblyMetadataProvider.Instance), MetricsPublisherFactory.GetMetricsPublisher(IsTelemetryOptedIn(), CommandLineOptions.Instance.IsDesignMode), new ProcessHelper(), - new MultiTestRunFinalizationManager(TestPlatformEventSource.Instance, new CodeCoverageDataAttachmentsHandler())) + new TestRunAttachmentsProcessingManager(TestPlatformEventSource.Instance, new CodeCoverageDataAttachmentsHandler())) { } - internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform testPlatform, TestRunResultAggregator testRunResultAggregator, ITestPlatformEventSource testPlatformEventSource, InferHelper inferHelper, Task metricsPublisher, IProcessHelper processHelper, IMultiTestRunFinalizationManager finalizationManager) + internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform testPlatform, TestRunResultAggregator testRunResultAggregator, ITestPlatformEventSource testPlatformEventSource, InferHelper inferHelper, Task metricsPublisher, IProcessHelper processHelper, ITestRunAttachmentsProcessingManager attachmentsProcessingManager) { this.testPlatform = testPlatform; this.commandLineOptions = commandLineOptions; @@ -97,7 +97,7 @@ internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform this.inferHelper = inferHelper; this.metricsPublisher = metricsPublisher; this.processHelper = processHelper; - this.finalizationManager = finalizationManager; + this.attachmentsProcessingManager = attachmentsProcessingManager; } #endregion @@ -313,40 +313,40 @@ public void RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc } /// - public void FinalizeMultiTestRun(MultiTestRunFinalizationPayload finalizationPayload, IMultiTestRunFinalizationEventsHandler finalizationEventsHandler, ProtocolConfig protocolConfig) + public void ProcessTestRunAttachments(TestRunAttachmentsProcessingPayload attachmentsProcessingPayload, ITestRunAttachmentsProcessingEventsHandler attachmentsProcessingEventsHandler, ProtocolConfig protocolConfig) { - EqtTrace.Info("TestRequestManager.FinalizeMultiTestRun: Multi test run finalization started."); + EqtTrace.Info("TestRequestManager.ProcessTestRunAttachments: Test run attachments processing started."); - this.telemetryOptedIn = finalizationPayload.CollectMetrics; + this.telemetryOptedIn = attachmentsProcessingPayload.CollectMetrics; var requestData = this.GetRequestData(protocolConfig); // Make sure to run the run request inside a lock as the below section is not thread-safe - // There can be only one discovery, execution or finalization request at a given point in time + // There can be only one discovery, execution or attachments processing request at a given point in time lock (this.syncObject) { try { - EqtTrace.Info("TestRequestManager.FinalizeMultiTestRun: Synchronization context taken"); - this.testPlatformEventSource.MultiTestRunFinalizationRequestStart(); + EqtTrace.Info("TestRequestManager.ProcessTestRunAttachments: Synchronization context taken"); + this.testPlatformEventSource.TestRunAttachmentsProcessingRequestStart(); - this.currentFinalizationCancellationTokenSource = new CancellationTokenSource(); + this.currentAttachmentsProcessingCancellationTokenSource = new CancellationTokenSource(); - Task task = this.finalizationManager.FinalizeMultiTestRunAsync(requestData, finalizationPayload.Attachments, finalizationEventsHandler, this.currentFinalizationCancellationTokenSource.Token); + Task task = this.attachmentsProcessingManager.ProcessTestRunAttachmentsAsync(requestData, attachmentsProcessingPayload.Attachments, attachmentsProcessingEventsHandler, this.currentAttachmentsProcessingCancellationTokenSource.Token); task.Wait(); } finally { - if (this.currentFinalizationCancellationTokenSource != null) + if (this.currentAttachmentsProcessingCancellationTokenSource != null) { - this.currentFinalizationCancellationTokenSource.Dispose(); - this.currentFinalizationCancellationTokenSource = null; + this.currentAttachmentsProcessingCancellationTokenSource.Dispose(); + this.currentAttachmentsProcessingCancellationTokenSource = null; } - EqtTrace.Info("TestRequestManager.FinalizeMultiTestRun: Multi test run finalization completed."); - this.testPlatformEventSource.MultiTestRunFinalizationRequestStop(); + EqtTrace.Info("TestRequestManager.ProcessTestRunAttachments: Test run attachments processing completed."); + this.testPlatformEventSource.TestRunAttachmentsProcessingRequestStop(); - // Post the finalization complete event - this.metricsPublisher.Result.PublishMetrics(TelemetryDataConstants.TestFinalizationCompleteEvent, requestData.MetricsCollection.Metrics); + // Post the attachments processing complete event + this.metricsPublisher.Result.PublishMetrics(TelemetryDataConstants.TestAttachmentsProcessingCompleteEvent, requestData.MetricsCollection.Metrics); } } } @@ -393,10 +393,10 @@ public void AbortTestRun() } /// - public void CancelMultiTestRunFinalization() + public void CancelTestRunAttachmentsProcessing() { - EqtTrace.Info("TestRequestManager.CancelMultiTestRunFinalization: Sending cancel request."); - this.currentFinalizationCancellationTokenSource?.Cancel(); + EqtTrace.Info("TestRequestManager.CancelTestRunAttachmentsProcessing: Sending cancel request."); + this.currentAttachmentsProcessingCancellationTokenSource?.Cancel(); } #endregion diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs index cc3c7efe62..964a22cf1e 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -19,7 +19,7 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests using System.Xml; /// - /// The Multi test run finalization tests using VsTestConsoleWrapper API's + /// The Test run attachments processing tests using VsTestConsoleWrapper API's /// [TestClass] public class CodeCoverageTests : AcceptanceTestBase @@ -32,13 +32,13 @@ public class CodeCoverageTests : AcceptanceTestBase private IVsTestConsoleWrapper vstestConsoleWrapper; private RunEventHandler runEventHandler; - private MultiTestRunFinalizationEventHandler multiTestRunFinalizationEventHandler; + private TestRunAttachmentsProcessingEventHandler testRunAttachmentsProcessingEventHandler; private void Setup() { this.vstestConsoleWrapper = this.GetVsTestConsoleWrapper(); this.runEventHandler = new RunEventHandler(); - this.multiTestRunFinalizationEventHandler = new MultiTestRunFinalizationEventHandler(); + this.testRunAttachmentsProcessingEventHandler = new TestRunAttachmentsProcessingEventHandler(); } [TestCleanup] @@ -91,7 +91,7 @@ public void TestRunWithCodeCoverageParallel(RunnerInfo runnerInfo) [TestMethod] [NetFullTargetFrameworkDataSource] [NetCoreTargetFrameworkDataSource] - public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) + public async Task TestRunWithCodeCoverageAndAttachmentsProcessing(RunnerInfo runnerInfo) { // arrange AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); @@ -104,34 +104,34 @@ public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) Assert.AreEqual(2, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, true, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(runEventHandler.Attachments, true, true, testRunAttachmentsProcessingEventHandler, CancellationToken.None); // Assert - multiTestRunFinalizationEventHandler.EnsureSuccess(); - Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.multiTestRunFinalizationEventHandler.Attachments.Count); + testRunAttachmentsProcessingEventHandler.EnsureSuccess(); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.testRunAttachmentsProcessingEventHandler.Attachments.Count); - AssertCoverageResults(this.multiTestRunFinalizationEventHandler.Attachments); + AssertCoverageResults(this.testRunAttachmentsProcessingEventHandler.Attachments); - Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); - Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); + Assert.IsFalse(testRunAttachmentsProcessingEventHandler.CompleteArgs.IsCanceled); + Assert.IsNull(testRunAttachmentsProcessingEventHandler.CompleteArgs.Error); - for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) + for (int i = 0; i < testRunAttachmentsProcessingEventHandler.ProgressArgs.Count; i++) { - VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; + VisualStudio.TestPlatform.ObjectModel.Client.TestRunAttachmentsProcessingProgressEventArgs progressArgs = testRunAttachmentsProcessingEventHandler.ProgressArgs[i]; Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorIndex); Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorUris.Count); Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentAttachmentProcessorUris.First().AbsoluteUri); Assert.AreEqual(1, progressArgs.AttachmentProcessorsCount); - if (multiTestRunFinalizationEventHandler.ProgressArgs.Count == 2) + if (testRunAttachmentsProcessingEventHandler.ProgressArgs.Count == 2) { Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentAttachmentProcessorProgress); } } - Assert.AreEqual("Completed", multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.FinalizationState]); - Assert.AreEqual(2L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsSentForFinalization]); - Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1L : 2L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsAfterFinalization]); - Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForFinalization)); + Assert.AreEqual("Completed", testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.AttachmentsProcessingState]); + Assert.AreEqual(2L, testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsSentForProcessing]); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1L : 2L, testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsAfterProcessing]); + Assert.IsTrue(testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForAttachmentsProcessing)); Assert.IsTrue(File.Exists(runEventHandler.Attachments.First().Attachments.First().Uri.LocalPath)); Assert.IsTrue(File.Exists(runEventHandler.Attachments.Last().Attachments.First().Uri.LocalPath) != testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework)); @@ -140,7 +140,7 @@ public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) [TestMethod] [NetFullTargetFrameworkDataSource] [NetCoreTargetFrameworkDataSource] - public async Task TestRunWithCodeCoverageAndFinalizationNoMetrics(RunnerInfo runnerInfo) + public async Task TestRunWithCodeCoverageAndAttachmentsProcessingNoMetrics(RunnerInfo runnerInfo) { // arrange AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); @@ -153,31 +153,31 @@ public async Task TestRunWithCodeCoverageAndFinalizationNoMetrics(RunnerInfo run Assert.AreEqual(2, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, false, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(runEventHandler.Attachments, true, false, testRunAttachmentsProcessingEventHandler, CancellationToken.None); // Assert - multiTestRunFinalizationEventHandler.EnsureSuccess(); - Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.multiTestRunFinalizationEventHandler.Attachments.Count); + testRunAttachmentsProcessingEventHandler.EnsureSuccess(); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.testRunAttachmentsProcessingEventHandler.Attachments.Count); - AssertCoverageResults(this.multiTestRunFinalizationEventHandler.Attachments); + AssertCoverageResults(this.testRunAttachmentsProcessingEventHandler.Attachments); - Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); - Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); + Assert.IsFalse(testRunAttachmentsProcessingEventHandler.CompleteArgs.IsCanceled); + Assert.IsNull(testRunAttachmentsProcessingEventHandler.CompleteArgs.Error); - for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) + for (int i = 0; i < testRunAttachmentsProcessingEventHandler.ProgressArgs.Count; i++) { - VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; + VisualStudio.TestPlatform.ObjectModel.Client.TestRunAttachmentsProcessingProgressEventArgs progressArgs = testRunAttachmentsProcessingEventHandler.ProgressArgs[i]; Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorIndex); Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorUris.Count); Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentAttachmentProcessorUris.First().AbsoluteUri); Assert.AreEqual(1, progressArgs.AttachmentProcessorsCount); - if (multiTestRunFinalizationEventHandler.ProgressArgs.Count == 2) + if (testRunAttachmentsProcessingEventHandler.ProgressArgs.Count == 2) { Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentAttachmentProcessorProgress); } } - Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.IsNullOrEmpty()); + Assert.IsTrue(testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics.IsNullOrEmpty()); Assert.IsTrue(File.Exists(runEventHandler.Attachments.First().Attachments.First().Uri.LocalPath)); Assert.IsTrue(File.Exists(runEventHandler.Attachments.Last().Attachments.First().Uri.LocalPath) != testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework)); @@ -186,7 +186,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationNoMetrics(RunnerInfo run [TestMethod] [NetFullTargetFrameworkDataSource] [NetCoreTargetFrameworkDataSource] - public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerInfo runnerInfo) + public async Task TestRunWithCodeCoverageAndAttachmentsProcessingModuleDuplicated(RunnerInfo runnerInfo) { // arrange AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); @@ -200,34 +200,34 @@ public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerI Assert.AreEqual(3, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, true, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(runEventHandler.Attachments, true, true, testRunAttachmentsProcessingEventHandler, CancellationToken.None); // Assert - multiTestRunFinalizationEventHandler.EnsureSuccess(); - Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 3, this.multiTestRunFinalizationEventHandler.Attachments.Count); + testRunAttachmentsProcessingEventHandler.EnsureSuccess(); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 3, this.testRunAttachmentsProcessingEventHandler.Attachments.Count); - AssertCoverageResults(this.multiTestRunFinalizationEventHandler.Attachments); + AssertCoverageResults(this.testRunAttachmentsProcessingEventHandler.Attachments); - Assert.IsFalse(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); - Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); + Assert.IsFalse(testRunAttachmentsProcessingEventHandler.CompleteArgs.IsCanceled); + Assert.IsNull(testRunAttachmentsProcessingEventHandler.CompleteArgs.Error); - for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) + for (int i = 0; i < testRunAttachmentsProcessingEventHandler.ProgressArgs.Count; i++) { - VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; + VisualStudio.TestPlatform.ObjectModel.Client.TestRunAttachmentsProcessingProgressEventArgs progressArgs = testRunAttachmentsProcessingEventHandler.ProgressArgs[i]; Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorIndex); Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentAttachmentProcessorUris.First().AbsoluteUri); Assert.AreEqual(1, progressArgs.AttachmentProcessorsCount); - if (multiTestRunFinalizationEventHandler.ProgressArgs.Count == 3) + if (testRunAttachmentsProcessingEventHandler.ProgressArgs.Count == 3) { Assert.AreEqual(i == 0 ? 33 : i == 1 ? 66 : 100, progressArgs.CurrentAttachmentProcessorProgress); } } - Assert.AreEqual("Completed", multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.FinalizationState]); - Assert.AreEqual(3L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsSentForFinalization]); - Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1L : 3L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsAfterFinalization]); - Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForFinalization)); + Assert.AreEqual("Completed", testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.AttachmentsProcessingState]); + Assert.AreEqual(3L, testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsSentForProcessing]); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1L : 3L, testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsAfterProcessing]); + Assert.IsTrue(testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForAttachmentsProcessing)); Assert.IsTrue(File.Exists(runEventHandler.Attachments.First().Attachments.First().Uri.LocalPath)); Assert.IsTrue(File.Exists(runEventHandler.Attachments.Last().Attachments.First().Uri.LocalPath) != testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework)); @@ -236,7 +236,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerI [TestMethod] [NetFullTargetFrameworkDataSource] [NetCoreTargetFrameworkDataSource] - public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo runnerInfo) + public async Task TestRunWithCodeCoverageAndAttachmentsProcessingCancelled(RunnerInfo runnerInfo) { // arrange AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); @@ -252,13 +252,13 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run CancellationTokenSource cts = new CancellationTokenSource(); - Task finalization = this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(attachments, true, true, multiTestRunFinalizationEventHandler, cts.Token); + Task attachmentsProcessing = this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(attachments, true, true, testRunAttachmentsProcessingEventHandler, cts.Token); while (true) { try { - if (multiTestRunFinalizationEventHandler.ProgressArgs.Count >= 3) + if (testRunAttachmentsProcessingEventHandler.ProgressArgs.Count >= 3) break; } catch @@ -272,18 +272,18 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run cts.Cancel(); // Assert - await finalization; - multiTestRunFinalizationEventHandler.EnsureSuccess(); + await attachmentsProcessing; + testRunAttachmentsProcessingEventHandler.EnsureSuccess(); - Assert.AreEqual(1000, this.multiTestRunFinalizationEventHandler.Attachments.Count); + Assert.AreEqual(1000, this.testRunAttachmentsProcessingEventHandler.Attachments.Count); - Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.IsCanceled); - Assert.IsNull(multiTestRunFinalizationEventHandler.CompleteArgs.Error); + Assert.IsTrue(testRunAttachmentsProcessingEventHandler.CompleteArgs.IsCanceled); + Assert.IsNull(testRunAttachmentsProcessingEventHandler.CompleteArgs.Error); - Assert.IsTrue((testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 3 : 0) <= multiTestRunFinalizationEventHandler.ProgressArgs.Count); - for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) + Assert.IsTrue((testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 3 : 0) <= testRunAttachmentsProcessingEventHandler.ProgressArgs.Count); + for (int i = 0; i < testRunAttachmentsProcessingEventHandler.ProgressArgs.Count; i++) { - VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; + VisualStudio.TestPlatform.ObjectModel.Client.TestRunAttachmentsProcessingProgressEventArgs progressArgs = testRunAttachmentsProcessingEventHandler.ProgressArgs[i]; Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorIndex); Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentAttachmentProcessorUris.First().AbsoluteUri); Assert.AreEqual(1, progressArgs.AttachmentProcessorsCount); @@ -294,10 +294,10 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run } } - Assert.AreEqual("Canceled", multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.FinalizationState]); - Assert.AreEqual(1000L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsSentForFinalization]); - Assert.AreEqual(1000L, multiTestRunFinalizationEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsAfterFinalization]); - Assert.IsTrue(multiTestRunFinalizationEventHandler.CompleteArgs.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForFinalization)); + Assert.AreEqual("Canceled", testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.AttachmentsProcessingState]); + Assert.AreEqual(1000L, testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsSentForProcessing]); + Assert.AreEqual(1000L, testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics[TelemetryDataConstants.NumberOfAttachmentsAfterProcessing]); + Assert.IsTrue(testRunAttachmentsProcessingEventHandler.CompleteArgs.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForAttachmentsProcessing)); Assert.IsTrue(File.Exists(runEventHandler.Attachments.First().Attachments.First().Uri.LocalPath)); } @@ -318,7 +318,7 @@ public async Task EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runn Assert.AreEqual(6, this.runEventHandler.TestResults.Count); Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, true, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(runEventHandler.Attachments, true, true, testRunAttachmentsProcessingEventHandler, CancellationToken.None); // act this.vstestConsoleWrapper?.EndSession(); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/TestRunAttachmentsProcessingEventHandler.cs similarity index 68% rename from test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs rename to test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/TestRunAttachmentsProcessingEventHandler.cs index ed3fc68204..8a0b6513c6 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/TestRunAttachmentsProcessingEventHandler.cs @@ -11,13 +11,13 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; /// - public class MultiTestRunFinalizationEventHandler : IMultiTestRunFinalizationEventsHandler + public class TestRunAttachmentsProcessingEventHandler : ITestRunAttachmentsProcessingEventsHandler { public List Attachments { get; private set; } - public MultiTestRunFinalizationCompleteEventArgs CompleteArgs { get; private set; } + public TestRunAttachmentsProcessingCompleteEventArgs CompleteArgs { get; private set; } - public List ProgressArgs { get; private set; } + public List ProgressArgs { get; private set; } /// /// Gets the log message. @@ -31,11 +31,11 @@ public class MultiTestRunFinalizationEventHandler : IMultiTestRunFinalizationEve /// public TestMessageLevel TestMessageLevel { get; private set; } - public MultiTestRunFinalizationEventHandler() + public TestRunAttachmentsProcessingEventHandler() { this.Errors = new List(); this.Attachments = new List(); - this.ProgressArgs = new List(); + this.ProgressArgs = new List(); } public void EnsureSuccess() @@ -73,7 +73,7 @@ public bool AttachDebuggerToProcess(int pid) return true; } - public void HandleMultiTestRunFinalizationComplete(ICollection attachments) + public void HandleTestRunAttachmentsProcessingComplete(ICollection attachments) { if(attachments != null) { @@ -81,19 +81,19 @@ public void HandleMultiTestRunFinalizationComplete(ICollection at } } - public void HandleMultiTestRunFinalizationComplete(MultiTestRunFinalizationCompleteEventArgs finalizationCompleteEventArgs, IEnumerable lastChunk) + public void HandleTestRunAttachmentsProcessingComplete(TestRunAttachmentsProcessingCompleteEventArgs attachmentsProcessingCompleteEventArgs, IEnumerable lastChunk) { if (lastChunk != null) { this.Attachments.AddRange(lastChunk); } - if (finalizationCompleteEventArgs.Error != null) + if (attachmentsProcessingCompleteEventArgs.Error != null) { - Errors.Add(finalizationCompleteEventArgs.Error.Message); + Errors.Add(attachmentsProcessingCompleteEventArgs.Error.Message); } - CompleteArgs = finalizationCompleteEventArgs; + CompleteArgs = attachmentsProcessingCompleteEventArgs; } public void HandleProcessedAttachmentsChunk(IEnumerable attachments) @@ -101,9 +101,9 @@ public void HandleProcessedAttachmentsChunk(IEnumerable attachmen throw new NotImplementedException(); } - public void HandleMultiTestRunFinalizationProgress(MultiTestRunFinalizationProgressEventArgs finalizationProgressEventArgs) + public void HandleTestRunAttachmentsProcessingProgress(TestRunAttachmentsProcessingProgressEventArgs AttachmentsProcessingProgressEventArgs) { - ProgressArgs.Add(finalizationProgressEventArgs); + ProgressArgs.Add(AttachmentsProcessingProgressEventArgs); } } } diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/AttachmentsProcessing/TestRunAttachmentsProcessingEventsHandlerTests.cs similarity index 57% rename from test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs rename to test/Microsoft.TestPlatform.Client.UnitTests/AttachmentsProcessing/TestRunAttachmentsProcessingEventsHandlerTests.cs index 852554361c..2988e594c6 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/AttachmentsProcessing/TestRunAttachmentsProcessingEventsHandlerTests.cs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace Microsoft.TestPlatform.Client.UnitTests.MultiTestRunFinalization +namespace Microsoft.TestPlatform.Client.UnitTests.TestRunAttachmentsProcessing { - using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization; + using Microsoft.VisualStudio.TestPlatform.Client.TestRunAttachmentsProcessing; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -13,15 +13,15 @@ namespace Microsoft.TestPlatform.Client.UnitTests.MultiTestRunFinalization using Moq; [TestClass] - public class MultiTestRunFinalizationEventsHandlerTests + public class TestRunAttachmentsProcessingEventsHandlerTests { private readonly Mock mockCommunicationManager; - private readonly IMultiTestRunFinalizationEventsHandler handler; + private readonly ITestRunAttachmentsProcessingEventsHandler handler; - public MultiTestRunFinalizationEventsHandlerTests() + public TestRunAttachmentsProcessingEventsHandlerTests() { this.mockCommunicationManager = new Mock(); - this.handler = new MultiTestRunFinalizationEventsHandler(mockCommunicationManager.Object); + this.handler = new TestRunAttachmentsProcessingEventsHandler(mockCommunicationManager.Object); } [TestMethod] @@ -35,24 +35,24 @@ public void EventsHandlerHandleLogMessageShouldSendTestMessage() } [TestMethod] - public void EventsHandlerHandleMultiTestRunFinalizationCompleteShouldSendFinalizationCompleteMessage() + public void EventsHandlerHandleTestRunAttachmentsProcessingCompleteShouldSendAttachmentsProcessingCompleteMessage() { var attachments = new[] { new AttachmentSet(new System.Uri("http://www.bing.com/"), "code coverage") }; - var args = new MultiTestRunFinalizationCompleteEventArgs(false, null); + var args = new TestRunAttachmentsProcessingCompleteEventArgs(false, null); - handler.HandleMultiTestRunFinalizationComplete(args, attachments); + handler.HandleTestRunAttachmentsProcessingComplete(args, attachments); - mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.Is(p => p.Attachments == attachments && p.FinalizationCompleteEventArgs == args))); + mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, It.Is(p => p.Attachments == attachments && p.AttachmentsProcessingCompleteEventArgs == args))); } [TestMethod] - public void EventsHandlerHandleMultiTestRunFinalizationProgressShouldSendFinalizationProgressMessage() + public void EventsHandlerHandleTestRunAttachmentsProcessingProgressShouldSendAttachmentsProcessingProgressMessage() { - var args = new MultiTestRunFinalizationProgressEventArgs(1, new[] { new System.Uri("http://www.bing.com/") }, 90, 2); + var args = new TestRunAttachmentsProcessingProgressEventArgs(1, new[] { new System.Uri("http://www.bing.com/") }, 90, 2); - handler.HandleMultiTestRunFinalizationProgress(args); + handler.HandleTestRunAttachmentsProcessingProgress(args); - mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationProgress, It.Is(p => p.FinalizationProgressEventArgs == args))); + mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestRunAttachmentsProcessingProgress, It.Is(p => p.AttachmentsProcessingProgressEventArgs == args))); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs index 28818876d9..1066cc4f3d 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.UnitTests.DesignMode using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.Client.DesignMode; - using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization; + using Microsoft.VisualStudio.TestPlatform.Client.TestRunAttachmentsProcessing; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.Common.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; @@ -407,89 +407,89 @@ public void DesignModeClientConnectShouldSendTestMessageAndDiscoverCompleteOnTes } [TestMethod] - public void DesignModeClientConnectShouldSendTestMessageAndFinalizationCompleteOnExceptionInFinalization() + public void DesignModeClientConnectShouldSendTestMessageAndAttachmentsProcessingCompleteOnExceptionInAttachmentsProcessing() { - var payload = new MultiTestRunFinalizationPayload(); - var startFinalization = new Message { MessageType = MessageType.MultiTestRunFinalizationStart, Payload = JToken.FromObject(payload) }; + var payload = new TestRunAttachmentsProcessingPayload(); + var startAttachmentsProcessing = new Message { MessageType = MessageType.TestRunAttachmentsProcessingStart, Payload = JToken.FromObject(payload) }; this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); - this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startFinalization); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startAttachmentsProcessing); this.mockCommunicationManager - .Setup(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny())) + .Setup(cm => cm.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, It.IsAny())) .Callback(() => complateEvent.Set()); this.mockTestRequestManager.Setup( - rm => rm.FinalizeMultiTestRun( - It.IsAny(), - It.IsAny(), + rm => rm.ProcessTestRunAttachments( + It.IsAny(), + It.IsAny(), It.IsAny())) .Throws(new Exception()); this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); - Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "Finalization not completed."); + Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "AttachmentsProcessing not completed."); this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Once()); - this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.Is(p => p.Attachments == null)), Times.Once()); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, It.Is(p => p.Attachments == null)), Times.Once()); } [TestMethod] - public void DesignModeClientConnectShouldSendTestMessageAndDiscoverCompleteOnTestPlatformExceptionInFinalization() + public void DesignModeClientConnectShouldSendTestMessageAndDiscoverCompleteOnTestPlatformExceptionInAttachmentsProcessing() { - var payload = new MultiTestRunFinalizationPayload(); - var startFinalization = new Message { MessageType = MessageType.MultiTestRunFinalizationStart, Payload = JToken.FromObject(payload) }; + var payload = new TestRunAttachmentsProcessingPayload(); + var startAttachmentsProcessing = new Message { MessageType = MessageType.TestRunAttachmentsProcessingStart, Payload = JToken.FromObject(payload) }; this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); - this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startFinalization); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startAttachmentsProcessing); this.mockCommunicationManager - .Setup(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny())) + .Setup(cm => cm.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, It.IsAny())) .Callback(() => complateEvent.Set()); this.mockTestRequestManager.Setup( - rm => rm.FinalizeMultiTestRun( - It.IsAny(), - It.IsAny(), + rm => rm.ProcessTestRunAttachments( + It.IsAny(), + It.IsAny(), It.IsAny())) .Throws(new TestPlatformException("Hello world")); this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); - Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "Finalization not completed."); + Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "AttachmentsProcessing not completed."); this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Once()); - this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.Is(p => p.Attachments == null)), Times.Once()); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, It.Is(p => p.Attachments == null)), Times.Once()); } [TestMethod] - public void DesignModeClientConnectShouldCallRequestManagerForFinalizationStart() + public void DesignModeClientConnectShouldCallRequestManagerForAttachmentsProcessingStart() { - var payload = new MultiTestRunFinalizationPayload(); - var startFinalization = new Message { MessageType = MessageType.MultiTestRunFinalizationStart, Payload = JToken.FromObject(payload) }; + var payload = new TestRunAttachmentsProcessingPayload(); + var startAttachmentsProcessing = new Message { MessageType = MessageType.TestRunAttachmentsProcessingStart, Payload = JToken.FromObject(payload) }; this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); - this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startFinalization); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startAttachmentsProcessing); this.mockTestRequestManager .Setup( - rm => rm.FinalizeMultiTestRun( - It.IsAny(), - It.IsAny(), + rm => rm.ProcessTestRunAttachments( + It.IsAny(), + It.IsAny(), It.IsAny())) .Callback(() => complateEvent.Set()); this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); - Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "Finalization not completed."); + Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "AttachmentsProcessing not completed."); this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Never); - this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny()), Times.Never); - this.mockTestRequestManager.Verify(rm => rm.FinalizeMultiTestRun(It.IsAny(), It.IsAny(), It.IsAny())); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, It.IsAny()), Times.Never); + this.mockTestRequestManager.Verify(rm => rm.ProcessTestRunAttachments(It.IsAny(), It.IsAny(), It.IsAny())); } [TestMethod] - public void DesignModeClientConnectShouldCallRequestManagerForFinalizationCancel() + public void DesignModeClientConnectShouldCallRequestManagerForAttachmentsProcessingCancel() { - var cancelFinalization = new Message { MessageType = MessageType.MultiTestRunFinalizationCancel }; + var cancelAttachmentsProcessing = new Message { MessageType = MessageType.TestRunAttachmentsProcessingCancel }; this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); - this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(cancelFinalization); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(cancelAttachmentsProcessing); this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Never); - this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny()), Times.Never); - this.mockTestRequestManager.Verify(rm => rm.CancelMultiTestRunFinalization()); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, It.IsAny()), Times.Never); + this.mockTestRequestManager.Verify(rm => rm.CancelTestRunAttachmentsProcessing()); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/AttachmentsProcessing/TestRunAttachmentsProcessingManagerTests.cs similarity index 74% rename from test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs rename to test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/AttachmentsProcessing/TestRunAttachmentsProcessingManagerTests.cs index a8f7aa866e..9569bde562 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/AttachmentsProcessing/TestRunAttachmentsProcessingManagerTests.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace Microsoft.TestPlatform.CrossPlatEngine.UnitTests.MultiTestRunFinalization +namespace Microsoft.TestPlatform.CrossPlatEngine.UnitTests.TestRunAttachmentsProcessing { using System; using System.Collections.Generic; @@ -10,7 +10,7 @@ namespace Microsoft.TestPlatform.CrossPlatEngine.UnitTests.MultiTestRunFinalizat using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.Common.Telemetry; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestRunAttachmentsProcessing; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; @@ -19,7 +19,7 @@ namespace Microsoft.TestPlatform.CrossPlatEngine.UnitTests.MultiTestRunFinalizat using Moq; [TestClass] - public class MultiTestRunFinalizationManagerTests + public class TestRunAttachmentsProcessingManagerTests { private const string uri1 = "datacollector://microsoft/some1/1.0"; private const string uri2 = "datacollector://microsoft/some2/2.0"; @@ -30,11 +30,11 @@ public class MultiTestRunFinalizationManagerTests private readonly Mock mockEventSource; private readonly Mock mockAttachmentHandler1; private readonly Mock mockAttachmentHandler2; - private readonly Mock mockEventsHandler; - private readonly MultiTestRunFinalizationManager manager; + private readonly Mock mockEventsHandler; + private readonly TestRunAttachmentsProcessingManager manager; private readonly CancellationTokenSource cancellationTokenSource; - public MultiTestRunFinalizationManagerTests() + public TestRunAttachmentsProcessingManagerTests() { mockRequestData = new Mock(); mockMetricsCollection = new Mock(); @@ -43,32 +43,32 @@ public MultiTestRunFinalizationManagerTests() mockEventSource = new Mock(); mockAttachmentHandler1 = new Mock(); mockAttachmentHandler2 = new Mock(); - mockEventsHandler = new Mock(); + mockEventsHandler = new Mock(); mockAttachmentHandler1.Setup(h => h.GetExtensionUris()).Returns(new[] { new Uri(uri1) }); mockAttachmentHandler2.Setup(h => h.GetExtensionUris()).Returns(new[] { new Uri(uri2) }); - manager = new MultiTestRunFinalizationManager(mockEventSource.Object, mockAttachmentHandler1.Object, mockAttachmentHandler2.Object); + manager = new TestRunAttachmentsProcessingManager(mockEventSource.Object, mockAttachmentHandler1.Object, mockAttachmentHandler2.Object); cancellationTokenSource = new CancellationTokenSource(); } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroughEventsHandler_IfNoAttachmentsOnInput() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachmentsThroughEventsHandler_IfNoAttachmentsOnInput() { // arrange List inputAttachments = new List(); // act - await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert VerifyCompleteEvent(false, false); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete(It.Is(a => !a.IsCanceled), It.Is>(c => c.Count == 0))); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingComplete(It.Is(a => !a.IsCanceled), It.Is>(c => c.Count == 0))); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(0)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.IsAny()), Times.Never); + mockEventSource.Verify(s => s.TestRunAttachmentsProcessingStart(0)); + mockEventSource.Verify(s => s.TestRunAttachmentsProcessingStop(0)); mockAttachmentHandler1.Verify(h => h.GetExtensionUris(), Times.Never); mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); @@ -78,13 +78,13 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnNoAttachments_IfNoAttachmentsOnInput() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturnNoAttachments_IfNoAttachmentsOnInput() { // arrange List inputAttachments = new List(); // act - var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); + var result = await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); // assert Assert.AreEqual(0, result.Count); @@ -97,7 +97,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNoAttachments_IfNoAttach } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachmentThroughEventsHandler_If1NotRelatedAttachmentOnInput() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturn1NotProcessedAttachmentThroughEventsHandler_If1NotRelatedAttachmentOnInput() { // arrange List inputAttachments = new List @@ -106,11 +106,11 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachmentT }; // act - await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert VerifyCompleteEvent(false, false, inputAttachments[0]); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); @@ -121,7 +121,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachmentT } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachment_If1NotRelatedAttachmentOnInput() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturn1NotProcessedAttachment_If1NotRelatedAttachmentOnInput() { // arrange List inputAttachments = new List @@ -130,7 +130,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachment_ }; // act - var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); + var result = await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); // assert Assert.AreEqual(1, result.Count); @@ -144,7 +144,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachment_ } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachmentThroughEventsHandler_IfRelatedAttachmentOnInput() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturn1ProcessedAttachmentThroughEventsHandler_IfRelatedAttachmentOnInput() { // arrange List inputAttachments = new List @@ -160,11 +160,11 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachmentThro mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachments); // act - await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert VerifyCompleteEvent(false, false, outputAttachments[0]); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); @@ -175,7 +175,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachmentThro } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachment_IfRelatedAttachmentOnInput() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturn1ProcessedAttachment_IfRelatedAttachmentOnInput() { // arrange List inputAttachments = new List @@ -191,13 +191,13 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachment_IfR mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachments); // act - var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); + var result = await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); // assert Assert.AreEqual(1, result.Count); Assert.IsTrue(result.Contains(outputAttachments[0])); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(1)); + mockEventSource.Verify(s => s.TestRunAttachmentsProcessingStart(1)); + mockEventSource.Verify(s => s.TestRunAttachmentsProcessingStop(1)); mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); @@ -207,7 +207,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachment_IfR } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroughEventsHandler_IfRelatedAttachmentOnInputButHandlerThrowsException() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachmentsThroughEventsHandler_IfRelatedAttachmentOnInputButHandlerThrowsException() { // arrange List inputAttachments = new List @@ -218,11 +218,11 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Throws(new Exception("exception message")); // act - await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert VerifyCompleteEvent(false, true, inputAttachments[0]); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "exception message"), Times.Once); mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); @@ -233,7 +233,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfRelatedAttachmentOnInputButHandlerThrowsException() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachments_IfRelatedAttachmentOnInputButHandlerThrowsException() { // arrange List inputAttachments = new List @@ -244,7 +244,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfRel mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Throws(new Exception("exception message")); // act - var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); + var result = await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); // assert Assert.AreEqual(1, result.Count); @@ -258,7 +258,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfRel } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroughEventsHandler_IfOperationIsCancelled() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachmentsThroughEventsHandler_IfOperationIsCancelled() { // arrange cancellationTokenSource.Cancel(); @@ -268,11 +268,11 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug }; // act - await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert VerifyCompleteEvent(true, false, inputAttachments[0]); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.IsAny()), Times.Never); mockAttachmentHandler1.Verify(h => h.GetExtensionUris(), Times.Never); mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); @@ -282,7 +282,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOperationIsCancelled() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachments_IfOperationIsCancelled() { // arrange cancellationTokenSource.Cancel(); @@ -292,7 +292,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe }; // act - var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); + var result = await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); // assert Assert.AreEqual(1, result.Count); @@ -306,7 +306,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachmentsThroughEventsHandler_IfRelatedAttachmentsOnInput() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturnProcessedAttachmentsThroughEventsHandler_IfRelatedAttachmentsOnInput() { // arrange List inputAttachments = new List @@ -332,11 +332,11 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachmentsThro mockAttachmentHandler2.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachmentsForHandler2); // act - await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); // assert VerifyCompleteEvent(false, false, inputAttachments[4], outputAttachmentsForHandler1.First(), outputAttachmentsForHandler2.First()); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); @@ -347,7 +347,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachmentsThro } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachments_IfRelatedAttachmentsOnInput() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturnProcessedAttachments_IfRelatedAttachmentsOnInput() { // arrange List inputAttachments = new List @@ -373,7 +373,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachments_IfR mockAttachmentHandler2.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachmentsForHandler2); // act - var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); + var result = await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); // assert Assert.AreEqual(3, result.Count); @@ -389,7 +389,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachments_IfR } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroughEventsHandler_IfOperationCancelled() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachmentsThroughEventsHandler_IfOperationCancelled() { // arrange List inputAttachments = new List @@ -433,18 +433,18 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug }); // act - await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); - Console.WriteLine("Finalization done"); + await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); + Console.WriteLine("Attachments processing done"); await innerTaskCompletionSource.Task; // assert VerifyCompleteEvent(true, false, inputAttachments[0]); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Exactly(4)); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 1)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 2)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 3)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 4)))); - mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Informational, "Finalization was cancelled.")); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.IsAny()), Times.Exactly(4)); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.Is(a => VerifyProgressArgs(a, 1)))); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.Is(a => VerifyProgressArgs(a, 2)))); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.Is(a => VerifyProgressArgs(a, 3)))); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.Is(a => VerifyProgressArgs(a, 4)))); + mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Informational, "Attachments processing was cancelled.")); mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); @@ -454,7 +454,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOperationCancelled() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachments_IfOperationCancelled() { // arrange List inputAttachments = new List @@ -497,8 +497,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe }); // act - var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); - Console.WriteLine("Finalization done"); + var result = await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); + Console.WriteLine("Attachments processing done"); await innerTaskCompletionSource.Task; // assert @@ -514,7 +514,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe } [TestMethod] - public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEvents_IfHandlersPropagesEvents() + public async Task ProcessTestRunAttachmentsAsync_ShouldReturnProperlySendProgressEvents_IfHandlersPropagesEvents() { // arrange List inputAttachments = new List @@ -536,7 +536,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven var innerTaskCompletionSource = new TaskCompletionSource(); int counter = 0; - mockEventsHandler.Setup(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny())).Callback(() => + mockEventsHandler.Setup(h => h.HandleTestRunAttachmentsProcessingProgress(It.IsAny())).Callback(() => { counter++; if(counter == 6) @@ -564,18 +564,18 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven }); // act - await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, CancellationToken.None); + await manager.ProcessTestRunAttachmentsAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, CancellationToken.None); // assert await innerTaskCompletionSource.Task; VerifyCompleteEvent(false, false, outputAttachments1.First(), outputAttachments2.First()); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Exactly(6)); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 25, uri1)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 50, uri1)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 75, uri1)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 100, uri1)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 50, uri2)))); - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 100, uri2)))); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.IsAny()), Times.Exactly(6)); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 25, uri1)))); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 50, uri1)))); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 75, uri1)))); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 100, uri1)))); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 50, uri2)))); + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 100, uri2)))); mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), CancellationToken.None)); @@ -589,23 +589,23 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven private void VerifyMetrics(int inputCount, int outputCount, string status = "Completed") { - mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(inputCount)); - mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(outputCount)); + mockEventSource.Verify(s => s.TestRunAttachmentsProcessingStart(inputCount)); + mockEventSource.Verify(s => s.TestRunAttachmentsProcessingStop(outputCount)); - mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.NumberOfAttachmentsSentForFinalization, inputCount)); - mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.NumberOfAttachmentsAfterFinalization, outputCount)); - mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.FinalizationState, status)); - mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.TimeTakenInSecForFinalization, It.IsAny())); + mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.NumberOfAttachmentsSentForProcessing, inputCount)); + mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.NumberOfAttachmentsAfterProcessing, outputCount)); + mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.AttachmentsProcessingState, status)); + mockMetricsCollection.Verify(m => m.Add(TelemetryDataConstants.TimeTakenInSecForAttachmentsProcessing, It.IsAny())); } private void VerifyCompleteEvent(bool isCanceled, bool containsError, params AttachmentSet[] expectedSets) { - mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationComplete( - It.Is(a => a.IsCanceled == isCanceled && (a.Error != null) == containsError), + mockEventsHandler.Verify(h => h.HandleTestRunAttachmentsProcessingComplete( + It.Is(a => a.IsCanceled == isCanceled && (a.Error != null) == containsError), It.Is>(c => c.Count == expectedSets.Length && expectedSets.All(e => c.Contains(e))))); } - private bool VerifyProgressArgs(MultiTestRunFinalizationProgressEventArgs args, int progress) + private bool VerifyProgressArgs(TestRunAttachmentsProcessingProgressEventArgs args, int progress) { Assert.AreEqual(1, args.CurrentAttachmentProcessorIndex); Assert.AreEqual(2, args.AttachmentProcessorsCount); @@ -614,7 +614,7 @@ private bool VerifyProgressArgs(MultiTestRunFinalizationProgressEventArgs args, return progress == args.CurrentAttachmentProcessorProgress; } - private bool VerifyProgressArgsForTwoHandlers(MultiTestRunFinalizationProgressEventArgs args, long handlerIndex, long progress, string uri) + private bool VerifyProgressArgsForTwoHandlers(TestRunAttachmentsProcessingProgressEventArgs args, long handlerIndex, long progress, string uri) { return progress == args.CurrentAttachmentProcessorProgress && args.CurrentAttachmentProcessorIndex == handlerIndex && diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs index e341bb5c74..6823e8efc1 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs @@ -27,7 +27,7 @@ public class ParallelDataCollectionEventsHandlerTests private readonly Mock mockProxyExecutionManager; private readonly Mock mockTestRunEventsHandler; private readonly Mock mockParallelProxyExecutionManager; - private readonly Mock mockMultiTestRunFinalizationManager; + private readonly Mock mockTestRunAttachmentsProcessingManager; private readonly CancellationTokenSource cancellationTokenSource; private readonly ParallelDataCollectionEventsHandler parallelDataCollectionEventsHandler; @@ -37,16 +37,16 @@ public ParallelDataCollectionEventsHandlerTests() mockProxyExecutionManager = new Mock(); mockTestRunEventsHandler = new Mock(); mockParallelProxyExecutionManager = new Mock(); - mockMultiTestRunFinalizationManager = new Mock(); + mockTestRunAttachmentsProcessingManager = new Mock(); cancellationTokenSource = new CancellationTokenSource(); parallelDataCollectionEventsHandler = new ParallelDataCollectionEventsHandler(mockRequestData.Object, mockProxyExecutionManager.Object, mockTestRunEventsHandler.Object, - mockParallelProxyExecutionManager.Object, new ParallelRunDataAggregator(), mockMultiTestRunFinalizationManager.Object, cancellationTokenSource.Token); + mockParallelProxyExecutionManager.Object, new ParallelRunDataAggregator(), mockTestRunAttachmentsProcessingManager.Object, cancellationTokenSource.Token); mockParallelProxyExecutionManager.Setup(m => m.HandlePartialRunComplete(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>())).Returns(true); } [TestMethod] - public void HandleTestRunComplete_ShouldCallFinalizerWithAttachmentsAndUseResults() + public void HandleTestRunComplete_ShouldCallProcessTestRunAttachmentsAsyncWithAttachmentsAndUseResults() { // arrange List inputAttachments = new List @@ -61,18 +61,18 @@ public void HandleTestRunComplete_ShouldCallFinalizerWithAttachmentsAndUseResult new AttachmentSet(new Uri(uri1), "uri1_input1") }; - mockMultiTestRunFinalizationManager.Setup(f => f.FinalizeMultiTestRunAsync(mockRequestData.Object, It.IsAny>(), It.IsAny())).Returns(Task.FromResult(outputAttachments)); + mockTestRunAttachmentsProcessingManager.Setup(f => f.ProcessTestRunAttachmentsAsync(mockRequestData.Object, It.IsAny>(), It.IsAny())).Returns(Task.FromResult(outputAttachments)); // act parallelDataCollectionEventsHandler.HandleTestRunComplete(new TestRunCompleteEventArgs(null, false, false, null, null, TimeSpan.FromSeconds(1)), null, inputAttachments, null); // assert mockTestRunEventsHandler.Verify(h => h.HandleTestRunComplete(It.IsAny(), It.IsAny(), It.Is>(c => c.Count == 1 && c.Contains(outputAttachments[0])), It.IsAny>())); - mockMultiTestRunFinalizationManager.Verify(f => f.FinalizeMultiTestRunAsync(mockRequestData.Object, It.Is>(a => a.Count == 3), cancellationTokenSource.Token)); + mockTestRunAttachmentsProcessingManager.Verify(f => f.ProcessTestRunAttachmentsAsync(mockRequestData.Object, It.Is>(a => a.Count == 3), cancellationTokenSource.Token)); } [TestMethod] - public void HandleTestRunComplete_ShouldCallFinalizerWithAttachmentsAndNotUserResults_IfFinalizerReturnsNull() + public void HandleTestRunComplete_ShouldCallProcessTestRunAttachmentsAsyncWithAttachmentsAndNotUserResults_IfManagerReturnsNull() { // arrange List inputAttachments = new List @@ -82,14 +82,14 @@ public void HandleTestRunComplete_ShouldCallFinalizerWithAttachmentsAndNotUserRe new AttachmentSet(new Uri(uri3), "uri3_input1") }; - mockMultiTestRunFinalizationManager.Setup(f => f.FinalizeMultiTestRunAsync(mockRequestData.Object, It.IsAny>(), It.IsAny())).Returns(Task.FromResult((Collection)null)); + mockTestRunAttachmentsProcessingManager.Setup(f => f.ProcessTestRunAttachmentsAsync(mockRequestData.Object, It.IsAny>(), It.IsAny())).Returns(Task.FromResult((Collection)null)); // act parallelDataCollectionEventsHandler.HandleTestRunComplete(new TestRunCompleteEventArgs(null, false, false, null, null, TimeSpan.FromSeconds(1)), null, inputAttachments, null); // assert mockTestRunEventsHandler.Verify(h => h.HandleTestRunComplete(It.IsAny(), It.IsAny(), It.Is>(c => c.Count == 3), It.IsAny>())); - mockMultiTestRunFinalizationManager.Verify(f => f.FinalizeMultiTestRunAsync(mockRequestData.Object, It.Is>(a => a.Count == 3), cancellationTokenSource.Token)); + mockTestRunAttachmentsProcessingManager.Verify(f => f.ProcessTestRunAttachmentsAsync(mockRequestData.Object, It.Is>(a => a.Count == 3), cancellationTokenSource.Token)); } } } diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs index b90aabfbc8..add71d422e 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs @@ -1893,79 +1893,79 @@ public async Task StartTestRunAsyncShouldLogErrorOnProcessExited() #endregion - #region Finalization Tests + #region Attachments Processing Tests [TestMethod] - public async Task FinalizeTestsShouldCompleteWithZeroAttachments() + public async Task ProcessTestRunAttachmentsAsyncShouldCompleteWithZeroAttachments() { await this.InitializeCommunicationAsync(); - var mockHandler = new Mock(); + var mockHandler = new Mock(); - var payload = new MultiTestRunFinalizationCompletePayload() + var payload = new TestRunAttachmentsProcessingCompletePayload() { - FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(false, null), + AttachmentsProcessingCompleteEventArgs = new TestRunAttachmentsProcessingCompleteEventArgs(false, null), Attachments = new AttachmentSet[0] }; - var finalizationComplete = new Message() + var attachmentsProcessingComplete = new Message() { - MessageType = MessageType.MultiTestRunFinalizationComplete, + MessageType = MessageType.TestRunAttachmentsProcessingComplete, Payload = JToken.FromObject(payload) }; - this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete)); + this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(attachmentsProcessingComplete)); - await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, true, mockHandler.Object, CancellationToken.None); + await this.requestSender.ProcessTestRunAttachmentsAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, true, mockHandler.Object, CancellationToken.None); - mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); - mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is(a => !a.IsCanceled && a.Error == null), It.Is>(a => a.Count == 0)), Times.Once, "Finalization Complete must be called"); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.TestRunAttachmentsProcessingStart, It.IsAny())); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.TestRunAttachmentsProcessingCancel), Times.Never); + mockHandler.Verify(mh => mh.HandleTestRunAttachmentsProcessingComplete(It.Is(a => !a.IsCanceled && a.Error == null), It.Is>(a => a.Count == 0)), Times.Once, "Attachments Processing Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never, "TestMessage event must not be called"); } [TestMethod] - public async Task FinalizeTestsShouldCompleteWithOneAttachment() + public async Task ProcessTestRunAttachmentsAsyncShouldCompleteWithOneAttachment() { await this.InitializeCommunicationAsync(); - var mockHandler = new Mock(); + var mockHandler = new Mock(); - var payload = new MultiTestRunFinalizationCompletePayload() + var payload = new TestRunAttachmentsProcessingCompletePayload() { - FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(true, new Exception("msg")), + AttachmentsProcessingCompleteEventArgs = new TestRunAttachmentsProcessingCompleteEventArgs(true, new Exception("msg")), Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } }; - var finalizationComplete = new Message() + var attachmentsProcessingComplete = new Message() { - MessageType = MessageType.MultiTestRunFinalizationComplete, + MessageType = MessageType.TestRunAttachmentsProcessingComplete, Payload = JToken.FromObject(payload) }; - this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete)); + this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(attachmentsProcessingComplete)); - await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, true, mockHandler.Object, CancellationToken.None); + await this.requestSender.ProcessTestRunAttachmentsAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, true, mockHandler.Object, CancellationToken.None); - mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); - mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is(a => a.IsCanceled && a.Error != null), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.TestRunAttachmentsProcessingStart, It.IsAny())); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.TestRunAttachmentsProcessingCancel), Times.Never); + mockHandler.Verify(mh => mh.HandleTestRunAttachmentsProcessingComplete(It.Is(a => a.IsCanceled && a.Error != null), It.Is>(a => a.Count == 1)), Times.Once, "Attachments Processing Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never, "TestMessage event must not be called"); } [TestMethod] - public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndTestMessage() + public async Task ProcessTestRunAttachmentsAsyncShouldCompleteWithOneAttachmentAndTestMessage() { await this.InitializeCommunicationAsync(); - var mockHandler = new Mock(); + var mockHandler = new Mock(); - var payload = new MultiTestRunFinalizationCompletePayload() + var payload = new TestRunAttachmentsProcessingCompletePayload() { - FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(false, null), + AttachmentsProcessingCompleteEventArgs = new TestRunAttachmentsProcessingCompleteEventArgs(false, null), Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } }; - var finalizationComplete = new Message() + var attachmentsProcessingComplete = new Message() { - MessageType = MessageType.MultiTestRunFinalizationComplete, + MessageType = MessageType.TestRunAttachmentsProcessingComplete, Payload = JToken.FromObject(payload) }; @@ -1974,75 +1974,75 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndTestMessage() this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(message)); mockHandler.Setup(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny())).Callback( - () => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete))); + () => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(attachmentsProcessingComplete))); - await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, false, mockHandler.Object, CancellationToken.None); + await this.requestSender.ProcessTestRunAttachmentsAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, false, mockHandler.Object, CancellationToken.None); - mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); - mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.TestRunAttachmentsProcessingStart, It.IsAny())); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.TestRunAttachmentsProcessingCancel), Times.Never); + mockHandler.Verify(mh => mh.HandleTestRunAttachmentsProcessingComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Attachments Processing Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Once, "TestMessage event must be called"); } [TestMethod] - public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndProgressMessage() + public async Task ProcessTestRunAttachmentsAsyncShouldCompleteWithOneAttachmentAndProgressMessage() { await this.InitializeCommunicationAsync(); - var mockHandler = new Mock(); + var mockHandler = new Mock(); - var completePayload = new MultiTestRunFinalizationCompletePayload() + var completePayload = new TestRunAttachmentsProcessingCompletePayload() { - FinalizationCompleteEventArgs = new MultiTestRunFinalizationCompleteEventArgs(false, null), + AttachmentsProcessingCompleteEventArgs = new TestRunAttachmentsProcessingCompleteEventArgs(false, null), Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } }; - var finalizationComplete = new Message() + var attachmentsProcessingComplete = new Message() { - MessageType = MessageType.MultiTestRunFinalizationComplete, + MessageType = MessageType.TestRunAttachmentsProcessingComplete, Payload = JToken.FromObject(completePayload) }; - var progressPayload = new MultiTestRunFinalizationProgressPayload() + var progressPayload = new TestRunAttachmentsProcessingProgressPayload() { - FinalizationProgressEventArgs = new MultiTestRunFinalizationProgressEventArgs(1, new[] { new Uri("http://www.bing.com/") }, 50, 2) + AttachmentsProcessingProgressEventArgs = new TestRunAttachmentsProcessingProgressEventArgs(1, new[] { new Uri("http://www.bing.com/") }, 50, 2) }; - var finalizationProgress = new Message() + var attachmentsProcessingProgress = new Message() { - MessageType = MessageType.MultiTestRunFinalizationProgress, + MessageType = MessageType.TestRunAttachmentsProcessingProgress, Payload = JToken.FromObject(progressPayload) }; - this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationProgress)); + this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(attachmentsProcessingProgress)); - mockHandler.Setup(mh => mh.HandleMultiTestRunFinalizationProgress(It.IsAny())).Callback( - () => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete))); + mockHandler.Setup(mh => mh.HandleTestRunAttachmentsProcessingProgress(It.IsAny())).Callback( + () => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(attachmentsProcessingComplete))); - await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, false, mockHandler.Object, CancellationToken.None); + await this.requestSender.ProcessTestRunAttachmentsAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, false, mockHandler.Object, CancellationToken.None); - mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); - mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationProgress(It.Is(a => a.CurrentAttachmentProcessorIndex == 1 && a.CurrentAttachmentProcessorUris.First() == new Uri("http://www.bing.com/") && a.CurrentAttachmentProcessorProgress == 50 && a.AttachmentProcessorsCount == 2)), Times.Once, "Finalization Progress must be called"); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.TestRunAttachmentsProcessingStart, It.IsAny())); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.TestRunAttachmentsProcessingCancel), Times.Never); + mockHandler.Verify(mh => mh.HandleTestRunAttachmentsProcessingComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Attachments Processing Complete must be called"); + mockHandler.Verify(mh => mh.HandleTestRunAttachmentsProcessingProgress(It.Is(a => a.CurrentAttachmentProcessorIndex == 1 && a.CurrentAttachmentProcessorUris.First() == new Uri("http://www.bing.com/") && a.CurrentAttachmentProcessorProgress == 50 && a.AttachmentProcessorsCount == 2)), Times.Once, "Attachments processing Progress must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Never); } [TestMethod] - public async Task FinalizeTestsShouldSendCancelMessageIfCancellationTokenCancelled() + public async Task ProcessTestRunAttachmentsAsyncShouldSendCancelMessageIfCancellationTokenCancelled() { await this.InitializeCommunicationAsync(); var cts = new CancellationTokenSource(); - var mockHandler = new Mock(); + var mockHandler = new Mock(); - var payload = new MultiTestRunFinalizationCompletePayload() + var payload = new TestRunAttachmentsProcessingCompletePayload() { Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } }; - var finalizationComplete = new Message() + var attachmentsProcessingComplete = new Message() { - MessageType = MessageType.MultiTestRunFinalizationComplete, + MessageType = MessageType.TestRunAttachmentsProcessingComplete, Payload = JToken.FromObject(payload) }; @@ -2053,56 +2053,56 @@ public async Task FinalizeTestsShouldSendCancelMessageIfCancellationTokenCancell mockHandler.Setup(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny())).Callback(() => { cts.Cancel(); - this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete)); + this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(attachmentsProcessingComplete)); }); - await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, false, mockHandler.Object, cts.Token); + await this.requestSender.ProcessTestRunAttachmentsAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, false, mockHandler.Object, cts.Token); - mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); - mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel)); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.TestRunAttachmentsProcessingStart, It.IsAny())); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.TestRunAttachmentsProcessingCancel)); + mockHandler.Verify(mh => mh.HandleTestRunAttachmentsProcessingComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Attachments Processing Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Once, "TestMessage event must be called"); } [TestMethod] - public async Task FinalizeTestsShouldSendCancelMessageIfCancellationTokenCancelledAtTheBeginning() + public async Task ProcessTestRunAttachmentsAsyncShouldSendCancelMessageIfCancellationTokenCancelledAtTheBeginning() { await this.InitializeCommunicationAsync(); var cts = new CancellationTokenSource(); cts.Cancel(); - var mockHandler = new Mock(); + var mockHandler = new Mock(); - var payload = new MultiTestRunFinalizationCompletePayload() + var payload = new TestRunAttachmentsProcessingCompletePayload() { Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") } }; - var finalizationComplete = new Message() + var attachmentsProcessingComplete = new Message() { - MessageType = MessageType.MultiTestRunFinalizationComplete, + MessageType = MessageType.TestRunAttachmentsProcessingComplete, Payload = JToken.FromObject(payload) }; - this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(finalizationComplete)); + this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(attachmentsProcessingComplete)); - await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, true, mockHandler.Object, cts.Token); + await this.requestSender.ProcessTestRunAttachmentsAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "a") }, true, mockHandler.Object, cts.Token); - mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); - mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel)); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Finalizationomplete must be called"); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.TestRunAttachmentsProcessingStart, It.IsAny())); + mockCommunicationManager.Verify(c => c.SendMessage(MessageType.TestRunAttachmentsProcessingCancel)); + mockHandler.Verify(mh => mh.HandleTestRunAttachmentsProcessingComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Attachments Processing Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Never, "TestMessage event must be called"); } [TestMethod] - public async Task FinalizeTestsShouldAbortOnExceptionInSendMessage() + public async Task ProcessTestRunAttachmentsAsyncShouldAbortOnExceptionInSendMessage() { - var mockHandler = new Mock(); - this.mockCommunicationManager.Setup(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())).Throws(new IOException()); + var mockHandler = new Mock(); + this.mockCommunicationManager.Setup(cm => cm.SendMessage(MessageType.TestRunAttachmentsProcessingStart, It.IsAny())).Throws(new IOException()); - await this.requestSender.FinalizeMultiTestRunAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, false, mockHandler.Object, CancellationToken.None); + await this.requestSender.ProcessTestRunAttachmentsAsync(new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, false, mockHandler.Object, CancellationToken.None); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.Is(a => !a.IsCanceled && a.Error is IOException), null), Times.Once, "Finalization Complete must be called"); + mockHandler.Verify(mh => mh.HandleTestRunAttachmentsProcessingComplete(It.Is(a => !a.IsCanceled && a.Error is IOException), null), Times.Once, "Attachments Processing Complete must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Error, It.IsAny()), Times.Once, "TestMessage event must be called"); this.mockCommunicationManager.Verify(cm => cm.StopServer(), Times.Never); } diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs index 302302f9d5..8efdaabdd9 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs @@ -310,19 +310,19 @@ await this.consoleWrapper.RunTestsWithCustomTestHostAsync( } [TestMethod] - public async Task FinalizeMultiTestRunAsyncShouldSucceed() + public async Task ProcessTestRunAttachmentsAsyncShouldSucceed() { var attachments = new Collection(); var cancellationToken = new CancellationToken(); - await this.consoleWrapper.FinalizeMultiTestRunAsync( + await this.consoleWrapper.ProcessTestRunAttachmentsAsync( attachments, true, true, - new Mock().Object, + new Mock().Object, cancellationToken); - this.mockRequestSender.Verify(rs => rs.FinalizeMultiTestRunAsync(attachments, true, It.IsAny(), cancellationToken)); + this.mockRequestSender.Verify(rs => rs.ProcessTestRunAttachmentsAsync(attachments, true, It.IsAny(), cancellationToken)); } [TestMethod] diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs index 5f3f099a76..94e451c43e 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs @@ -308,19 +308,19 @@ public void RunTestsWithSelectedTestsAndOptionsUsingACustomHostShouldPassOnOptio } [TestMethod] - public async Task FinalizeMultiTestRunAsyncShouldSucceed() + public async Task ProcessTestRunAttachmentsAsyncShouldSucceed() { var attachments = new Collection(); var cancellationToken = new CancellationToken(); - await this.consoleWrapper.FinalizeMultiTestRunAsync( + await this.consoleWrapper.ProcessTestRunAttachmentsAsync( attachments, true, true, - new Mock().Object, + new Mock().Object, cancellationToken); - this.mockRequestSender.Verify(rs => rs.FinalizeMultiTestRunAsync(attachments, true, It.IsAny(), cancellationToken)); + this.mockRequestSender.Verify(rs => rs.ProcessTestRunAttachmentsAsync(attachments, true, It.IsAny(), cancellationToken)); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs index 1c7cdef211..4a12456ce3 100644 --- a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs @@ -45,7 +45,7 @@ public class ListFullyQualifiedTestsArgumentProcessorTests private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; - private Mock mockFinalizationManager; + private Mock mockAttachmentsProcessingManager; private static ListFullyQualifiedTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestManager, IOutput output) { @@ -80,7 +80,7 @@ public ListFullyQualifiedTestsArgumentProcessorTests() this.mockAssemblyMetadataProvider.Setup(x => x.GetFrameWork(It.IsAny())).Returns(new FrameworkName(Constants.DotNetFramework40)); this.inferHelper = new InferHelper(this.mockAssemblyMetadataProvider.Object); this.mockProcessHelper = new Mock(); - this.mockFinalizationManager = new Mock(); + this.mockAttachmentsProcessingManager = new Mock(); } /// @@ -127,7 +127,7 @@ public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() { CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object; CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, this.mockFileHelper.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager, null); executor.Initialize(this.dummyTestFilePath); @@ -139,7 +139,7 @@ public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() public void ExecutorExecuteForNoSourcesShouldReturnFail() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => executor.Execute()); @@ -156,7 +156,7 @@ public void ExecutorExecuteShouldThrowTestPlatformException() this.ResetAndAddSourceToCommandLineOptions(true); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager, null); @@ -173,7 +173,7 @@ public void ExecutorExecuteShouldThrowSettingsException() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(true); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); @@ -192,7 +192,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationException() this.ResetAndAddSourceToCommandLineOptions(true); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); @@ -210,7 +210,7 @@ public void ExecutorExecuteShouldThrowOtherExceptions() this.ResetAndAddSourceToCommandLineOptions(true); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager, null); @@ -302,7 +302,7 @@ private void RunListFullyQualifiedTestArgumentProcessorWithTraits(Mock mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; - private Mock mockFinalizationManager; + private Mock mockAttachmentsProcessingManager; private static ListTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestManager, IOutput output) { @@ -78,7 +78,7 @@ public ListTestsArgumentProcessorTests() this.mockAssemblyMetadataProvider.Setup(x => x.GetFrameWork(It.IsAny())).Returns(new FrameworkName(Constants.DotNetFramework40)); this.inferHelper = new InferHelper(this.mockAssemblyMetadataProvider.Object); this.mockProcessHelper = new Mock(); - this.mockFinalizationManager = new Mock(); + this.mockAttachmentsProcessingManager = new Mock(); } /// @@ -128,7 +128,7 @@ public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() { CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object; CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, this.mockFileHelper.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager, null); executor.Initialize(this.dummyTestFilePath); @@ -141,7 +141,7 @@ public void ExecutorExecuteForNoSourcesShouldReturnFail() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => executor.Execute()); @@ -158,7 +158,7 @@ public void ExecutorExecuteShouldThrowTestPlatformException() this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => executor.Execute()); @@ -175,7 +175,7 @@ public void ExecutorExecuteShouldThrowSettingsException() this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => listTestsArgumentExecutor.Execute()); @@ -192,7 +192,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationException() this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => listTestsArgumentExecutor.Execute()); @@ -209,7 +209,7 @@ public void ExecutorExecuteShouldThrowOtherExceptions() this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => executor.Execute()); @@ -266,7 +266,7 @@ private void RunListTestArgumentProcessorExecuteWithMockSetup(Mock mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; - private Mock mockFinalizationManager; + private Mock mockAttachmentsProcessingManager; private RunSpecificTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestManager) { @@ -69,7 +69,7 @@ public RunSpecificTestsArgumentProcessorTests() this.mockProcessHelper = new Mock(); this.mockProcessHelper.Setup(x => x.GetCurrentProcessId()).Returns(1234); this.mockProcessHelper.Setup(x => x.GetProcessName(It.IsAny())).Returns("dotnet.exe"); - this.mockFinalizationManager = new Mock(); + this.mockAttachmentsProcessingManager = new Mock(); } [TestMethod] @@ -114,7 +114,7 @@ public void InitializeShouldThrowIfArgumentIsNull() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => { executor.Initialize(null); }); @@ -125,7 +125,7 @@ public void InitializeShouldThrowIfArgumentIsEmpty() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => { executor.Initialize(String.Empty); }); @@ -136,7 +136,7 @@ public void InitializeShouldThrowIfArgumentIsWhiteSpace() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => { executor.Initialize(" "); }); @@ -147,7 +147,7 @@ public void InitializeShouldThrowIfArgumentsAreEmpty() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => { executor.Initialize(" , "); }); @@ -158,7 +158,7 @@ public void ExecutorShouldSplitTestsSeparatedByComma() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -169,7 +169,7 @@ public void ExecutorExecuteForNoSourcesShouldThrowCommandLineException() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -192,7 +192,7 @@ public void ExecutorExecuteForValidSourceWithTestCaseFilterShouldRunTests() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); CommandLineOptions.Instance.TestCaseFilterValue = "Filter"; @@ -217,7 +217,7 @@ public void ExecutorExecuteShouldThrowTestPlatformExceptionThrownDuringDiscovery mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -235,7 +235,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationExceptionThrownDuringDisco mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -253,7 +253,7 @@ public void ExecutorExecuteShouldThrowSettingsExceptionThrownDuringDiscovery() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -276,7 +276,7 @@ public void ExecutorExecuteShouldThrowTestPlatformExceptionThrownDuringExecution mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -301,7 +301,7 @@ public void ExecutorExecuteShouldThrowSettingsExceptionThrownDuringExecution() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -327,7 +327,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationExceptionThrownDuringExecu this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -348,7 +348,7 @@ public void ExecutorExecuteShouldForValidSourcesAndNoTestsDiscoveredShouldLogWar mockDiscoveryRequest.Setup(dr => dr.DiscoverAsync()).Raises(dr => dr.OnDiscoveredTests += null, new DiscoveredTestsEventArgs(new List())); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -369,7 +369,7 @@ public void ExecutorExecuteShouldForValidSourcesAndNoTestsDiscoveredShouldLogApp mockDiscoveryRequest.Setup(dr => dr.DiscoverAsync()).Raises(dr => dr.OnDiscoveredTests += null, new DiscoveredTestsEventArgs(new List())); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -396,7 +396,7 @@ public void ExecutorExecuteShouldForValidSourcesAndValidSelectedTestsRunsTestsAn mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -422,7 +422,7 @@ public void ExecutorShouldRunTestsWhenTestsAreCommaSeparated() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1, Test2"); @@ -449,7 +449,7 @@ public void ExecutorShouldRunTestsWhenTestsAreFiltered() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -475,7 +475,7 @@ public void ExecutorShouldWarnWhenTestsAreNotAvailable() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1, Test2"); @@ -502,7 +502,7 @@ public void ExecutorShouldRunTestsWhenTestsAreCommaSeparatedWithEscape() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1(a\\,b), Test2(c\\,d)"); @@ -532,7 +532,7 @@ public void ExecutorShouldDisplayWarningIfNoTestsAreExecuted() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -561,7 +561,7 @@ public void ExecutorShouldNotDisplayWarningIfTestsAreExecuted() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object);; + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object);; var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); diff --git a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs index ac7d49b522..d3b3814117 100644 --- a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs @@ -48,7 +48,7 @@ public class RunTestsArgumentProcessorTests private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; - private Mock mockFinalizationManager; + private Mock mockAttachmentsProcessingManager; public RunTestsArgumentProcessorTests() { @@ -66,7 +66,7 @@ public RunTestsArgumentProcessorTests() .Returns(Architecture.X86); this.mockAssemblyMetadataProvider.Setup(x => x.GetFrameWork(It.IsAny())).Returns(new FrameworkName(Constants.DotNetFramework40)); this.mockProcessHelper = new Mock(); - this.mockFinalizationManager = new Mock(); + this.mockAttachmentsProcessingManager = new Mock(); } [TestMethod] @@ -112,7 +112,7 @@ public void ExecutorExecuteShouldReturnSuccessWithoutExecutionInDesignMode() CommandLineOptions.Instance.Reset(); CommandLineOptions.Instance.IsDesignMode = true; - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = new RunTestsArgumentExecutor(CommandLineOptions.Instance, runSettingsProvider, testRequestManager, this.mockOutput.Object); Assert.AreEqual(ArgumentProcessorResult.Success, executor.Execute()); @@ -122,7 +122,7 @@ public void ExecutorExecuteShouldReturnSuccessWithoutExecutionInDesignMode() public void ExecutorExecuteForNoSourcesShouldThrowCommandLineException() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -151,7 +151,7 @@ public void ExecutorExecuteShouldThrowTestPlatformException() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -167,7 +167,7 @@ public void ExecutorExecuteShouldThrowSettingsException() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -183,7 +183,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationException() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -199,7 +199,7 @@ public void ExecutorExecuteShouldThrowOtherExceptions() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -254,7 +254,7 @@ private ArgumentProcessorResult RunRunArgumentProcessorExecuteWithMockSetup(ITes this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockFinalizationManager.Object); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, this.mockAttachmentsProcessingManager.Object); var executor = GetExecutor(testRequestManager); return executor.Execute(); diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index 768263b8a1..e8f7ba2a30 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -52,7 +52,7 @@ public class TestRequestManagerTests private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; private Mock mockProcessHelper; - private Mock mockFinalizationManager; + private Mock mockAttachmentsProcessingManager; private const string DefaultRunsettings = @" @@ -77,7 +77,7 @@ public TestRequestManagerTests() this.mockMetricsPublisher = new Mock(); this.mockMetricsPublisherTask = Task.FromResult(this.mockMetricsPublisher.Object); - this.mockFinalizationManager = new Mock(); + this.mockAttachmentsProcessingManager = new Mock(); this.testRequestManager = new TestRequestManager( this.commandLineOptions, this.mockTestPlatform.Object, @@ -86,7 +86,7 @@ public TestRequestManagerTests() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); this.mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(this.mockDiscoveryRequest.Object); this.mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())) @@ -120,7 +120,7 @@ public void TestRequestManagerShouldNotInitializeConsoleLoggerIfDesignModeIsSet( this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); Assert.IsFalse(this.mockLoggerEvents.EventsSubscribed()); } @@ -203,7 +203,7 @@ public void DiscoverTestsShouldCallTestPlatformAndSucceed() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); this.testRequestManager.DiscoverTests(payload, mockDiscoveryRegistrar.Object, this.protocolConfig); @@ -253,7 +253,7 @@ public void DiscoverTestsShouldPassSameProtocolConfigInRequestData() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); // Act this.testRequestManager.DiscoverTests(payload, mockDiscoveryRegistrar.Object, mockProtocolConfig); @@ -301,7 +301,7 @@ public void DiscoverTestsShouldCollectMetrics() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); // Act @@ -351,7 +351,7 @@ public void DiscoverTestsShouldCollectTargetDeviceLocalMachineIfTargetDeviceStri this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); // Act @@ -395,7 +395,7 @@ public void DiscoverTestsShouldCollectTargetDeviceIfTargetDeviceIsDevice() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); // Act @@ -439,7 +439,7 @@ public void DiscoverTestsShouldCollectTargetDeviceIfTargetDeviceIsEmulator() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); // Act @@ -483,7 +483,7 @@ public void DiscoverTestsShouldCollectCommands() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); CommandLineOptions.Instance.Parallel = true; CommandLineOptions.Instance.EnableCodeCoverage = true; @@ -539,7 +539,7 @@ public void DiscoverTestsShouldCollectTestSettings() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); CommandLineOptions.Instance.SettingsFile = @"c://temp/.testsettings"; @@ -587,7 +587,7 @@ public void DiscoverTestsShouldCollectVsmdiFile() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); CommandLineOptions.Instance.SettingsFile = @"c://temp/.vsmdi"; @@ -635,7 +635,7 @@ public void DiscoverTestsShouldCollectTestRunConfigFile() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); CommandLineOptions.Instance.SettingsFile = @"c://temp/.testrunConfig"; @@ -958,7 +958,7 @@ public void RunTestsShouldCollectCommands() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); CommandLineOptions.Instance.Parallel = true; CommandLineOptions.Instance.EnableCodeCoverage = true; @@ -1026,7 +1026,7 @@ public void RunTestsShouldCollectTelemetryForLegacySettings() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); // Act. this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, mockProtocolConfig); @@ -1076,7 +1076,7 @@ public void RunTestsShouldCollectTelemetryForTestSettingsEmbeddedInsideRunSettin this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); // Act. this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, mockProtocolConfig); @@ -1124,7 +1124,7 @@ public void RunTestsShouldCollectMetrics() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); // Act. this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, mockProtocolConfig); @@ -1172,7 +1172,7 @@ public void RunTestsWithSourcesShouldCallTestPlatformAndSucceed() this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object, - this.mockFinalizationManager.Object); + this.mockAttachmentsProcessingManager.Object); this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig); @@ -2178,63 +2178,63 @@ public void DiscoverTestsShouldOverrideOnlyAssemblyNameIfConsoleLoggerAlreadyPre } [TestMethod] - public void FinalizeMultiTestRunShouldSucceedWithTelemetryEnabled() + public void ProcessTestRunAttachmentsShouldSucceedWithTelemetryEnabled() { - var mockEventsHandler = new Mock(); - mockFinalizationManager - .Setup(m => m.FinalizeMultiTestRunAsync(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())) - .Returns((IRequestData r, ICollection a, IMultiTestRunFinalizationEventsHandler h, CancellationToken token) => Task.Run(() => + var mockEventsHandler = new Mock(); + mockAttachmentsProcessingManager + .Setup(m => m.ProcessTestRunAttachmentsAsync(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())) + .Returns((IRequestData r, ICollection a, ITestRunAttachmentsProcessingEventsHandler h, CancellationToken token) => Task.Run(() => { - r.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsSentForFinalization, 5); - r.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsAfterFinalization, 1); + r.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsSentForProcessing, 5); + r.MetricsCollection.Add(TelemetryDataConstants.NumberOfAttachmentsAfterProcessing, 1); })); - var payload = new MultiTestRunFinalizationPayload() + var payload = new TestRunAttachmentsProcessingPayload() { Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, CollectMetrics = true }; - testRequestManager.FinalizeMultiTestRun(payload, mockEventsHandler.Object, this.protocolConfig); + testRequestManager.ProcessTestRunAttachments(payload, mockEventsHandler.Object, this.protocolConfig); - mockFinalizationManager.Verify(m => m.FinalizeMultiTestRunAsync(It.Is(r => r.IsTelemetryOptedIn), payload.Attachments, mockEventsHandler.Object, It.IsAny())); - mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStart()); - mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStop()); + mockAttachmentsProcessingManager.Verify(m => m.ProcessTestRunAttachmentsAsync(It.Is(r => r.IsTelemetryOptedIn), payload.Attachments, mockEventsHandler.Object, It.IsAny())); + mockTestPlatformEventSource.Verify(es => es.TestRunAttachmentsProcessingRequestStart()); + mockTestPlatformEventSource.Verify(es => es.TestRunAttachmentsProcessingRequestStop()); - mockMetricsPublisher.Verify(p => p.PublishMetrics(TelemetryDataConstants.TestFinalizationCompleteEvent, + mockMetricsPublisher.Verify(p => p.PublishMetrics(TelemetryDataConstants.TestAttachmentsProcessingCompleteEvent, It.Is>(m => m.Count == 2 && - m.ContainsKey(TelemetryDataConstants.NumberOfAttachmentsSentForFinalization) && (int)m[TelemetryDataConstants.NumberOfAttachmentsSentForFinalization] == 5 && - m.ContainsKey(TelemetryDataConstants.NumberOfAttachmentsAfterFinalization) && (int)m[TelemetryDataConstants.NumberOfAttachmentsAfterFinalization] == 1))); + m.ContainsKey(TelemetryDataConstants.NumberOfAttachmentsSentForProcessing) && (int)m[TelemetryDataConstants.NumberOfAttachmentsSentForProcessing] == 5 && + m.ContainsKey(TelemetryDataConstants.NumberOfAttachmentsAfterProcessing) && (int)m[TelemetryDataConstants.NumberOfAttachmentsAfterProcessing] == 1))); } [TestMethod] - public void FinalizeMultiTestRunShouldSucceedWithTelemetryDisabled() + public void ProcessTestRunAttachmentsShouldSucceedWithTelemetryDisabled() { - var mockEventsHandler = new Mock(); - mockFinalizationManager - .Setup(m => m.FinalizeMultiTestRunAsync(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())) + var mockEventsHandler = new Mock(); + mockAttachmentsProcessingManager + .Setup(m => m.ProcessTestRunAttachmentsAsync(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())) .Returns(Task.FromResult(true)); - var payload = new MultiTestRunFinalizationPayload() + var payload = new TestRunAttachmentsProcessingPayload() { Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, CollectMetrics = false }; - testRequestManager.FinalizeMultiTestRun(payload, mockEventsHandler.Object, this.protocolConfig); + testRequestManager.ProcessTestRunAttachments(payload, mockEventsHandler.Object, this.protocolConfig); - mockFinalizationManager.Verify(m => m.FinalizeMultiTestRunAsync(It.Is(r => !r.IsTelemetryOptedIn), payload.Attachments, mockEventsHandler.Object, It.IsAny())); - mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStart()); - mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStop()); + mockAttachmentsProcessingManager.Verify(m => m.ProcessTestRunAttachmentsAsync(It.Is(r => !r.IsTelemetryOptedIn), payload.Attachments, mockEventsHandler.Object, It.IsAny())); + mockTestPlatformEventSource.Verify(es => es.TestRunAttachmentsProcessingRequestStart()); + mockTestPlatformEventSource.Verify(es => es.TestRunAttachmentsProcessingRequestStop()); } [TestMethod] - public async Task CancelMultiTestRunFinalizationShouldSucceedIfRequestInProgress() + public async Task CancelTestRunAttachmentsProcessingShouldSucceedIfRequestInProgress() { - var mockEventsHandler = new Mock(); - mockFinalizationManager - .Setup(m => m.FinalizeMultiTestRunAsync(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())) - .Returns((IRequestData r, ICollection a, IMultiTestRunFinalizationEventsHandler h, CancellationToken token) => Task.Run(() => + var mockEventsHandler = new Mock(); + mockAttachmentsProcessingManager + .Setup(m => m.ProcessTestRunAttachmentsAsync(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())) + .Returns((IRequestData r, ICollection a, ITestRunAttachmentsProcessingEventsHandler h, CancellationToken token) => Task.Run(() => { int i = 0; while (!token.IsCancellationRequested) @@ -2244,33 +2244,33 @@ public async Task CancelMultiTestRunFinalizationShouldSucceedIfRequestInProgress Task.Delay(5).Wait(); } - r.MetricsCollection.Add(TelemetryDataConstants.FinalizationState, "Canceled"); + r.MetricsCollection.Add(TelemetryDataConstants.AttachmentsProcessingState, "Canceled"); })); - var payload = new MultiTestRunFinalizationPayload() + var payload = new TestRunAttachmentsProcessingPayload() { Attachments = new List { new AttachmentSet(new Uri("http://www.bing.com"), "out") }, CollectMetrics = true }; - Task task = Task.Run(() => testRequestManager.FinalizeMultiTestRun(payload, mockEventsHandler.Object, this.protocolConfig)); + Task task = Task.Run(() => testRequestManager.ProcessTestRunAttachments(payload, mockEventsHandler.Object, this.protocolConfig)); await Task.Delay(50); - testRequestManager.CancelMultiTestRunFinalization(); + testRequestManager.CancelTestRunAttachmentsProcessing(); await task; - mockFinalizationManager.Verify(m => m.FinalizeMultiTestRunAsync(It.IsAny(), payload.Attachments, mockEventsHandler.Object, It.IsAny())); - mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStart()); - mockTestPlatformEventSource.Verify(es => es.MultiTestRunFinalizationRequestStop()); + mockAttachmentsProcessingManager.Verify(m => m.ProcessTestRunAttachmentsAsync(It.IsAny(), payload.Attachments, mockEventsHandler.Object, It.IsAny())); + mockTestPlatformEventSource.Verify(es => es.TestRunAttachmentsProcessingRequestStart()); + mockTestPlatformEventSource.Verify(es => es.TestRunAttachmentsProcessingRequestStop()); - mockMetricsPublisher.Verify(p => p.PublishMetrics(TelemetryDataConstants.TestFinalizationCompleteEvent, - It.Is>(m => m.Count == 1 && m.ContainsKey(TelemetryDataConstants.FinalizationState) && (string)m[TelemetryDataConstants.FinalizationState] == "Canceled"))); + mockMetricsPublisher.Verify(p => p.PublishMetrics(TelemetryDataConstants.TestAttachmentsProcessingCompleteEvent, + It.Is>(m => m.Count == 1 && m.ContainsKey(TelemetryDataConstants.AttachmentsProcessingState) && (string)m[TelemetryDataConstants.AttachmentsProcessingState] == "Canceled"))); } [TestMethod] - public void CancelMultiTestRunFinalizationShouldSucceedIfNoRequest() + public void CancelTestRunAttachmentsProcessingShouldSucceedIfNoRequest() { - testRequestManager.CancelMultiTestRunFinalization(); + testRequestManager.CancelTestRunAttachmentsProcessing(); } private static DiscoveryRequestPayload CreateDiscoveryPayload(string runsettings) From 1aee79f629dbc3347e1146f280c7ee43b8c7ad72 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Wed, 1 Jul 2020 12:45:58 +0200 Subject: [PATCH 56/58] Added processingSettings --- .../Interfaces/IVsTestConsoleWrapperAsync.cs | 5 +-- .../VsTestConsoleWrapper.cs | 4 +-- .../CodeCoverageTests.cs | 10 +++--- ...estRunAttachmentsProcessingManagerTests.cs | 32 +++++++++---------- .../VsTestConsoleWrapperAsyncTests.cs | 1 + .../VsTestConsoleWrapperTests.cs | 1 + 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs index 9c5af36304..452de38cb6 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs @@ -96,11 +96,12 @@ public interface IVsTestConsoleWrapperAsync /// Provides back all attachments to TestPlatform for additional processing (for example merging) /// /// Collection of attachments - /// Indicates that all test executions are done and all data is provided + /// XML processing settings + /// Indicates that all test executions are done and all data is provided /// Enables metrics collection (used for telemetry) /// EventHandler to receive session complete event /// Cancellation token - Task ProcessTestRunAttachmentsAsync(IEnumerable attachments, bool multiTestRunCompleted, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler eventsHandler, CancellationToken cancellationToken); + Task ProcessTestRunAttachmentsAsync(IEnumerable attachments, string processingSettings, bool isLastBatch, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler eventsHandler, CancellationToken cancellationToken); /// /// See . diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index c92a85f9db..eb8780bdf6 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -276,7 +276,7 @@ public void EndSession() #endregion - #region IVsTestConsoleWrapper + #region IVsTestConsoleWrapperAsync /// public async Task StartSessionAsync() @@ -407,7 +407,7 @@ public async Task RunTestsWithCustomTestHostAsync(IEnumerable testCase } /// - public async Task ProcessTestRunAttachmentsAsync(IEnumerable attachments, bool multiTestRunCompleted, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) + public async Task ProcessTestRunAttachmentsAsync(IEnumerable attachments, string processingSettings, bool isLastBatch, bool collectMetrics, ITestRunAttachmentsProcessingEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) { this.testPlatformEventSource.TranslationLayerTestRunAttachmentsProcessingStart(); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs index 964a22cf1e..81c1fe51ae 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -104,7 +104,7 @@ public async Task TestRunWithCodeCoverageAndAttachmentsProcessing(RunnerInfo run Assert.AreEqual(2, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(runEventHandler.Attachments, true, true, testRunAttachmentsProcessingEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(runEventHandler.Attachments, null, true, true, testRunAttachmentsProcessingEventHandler, CancellationToken.None); // Assert testRunAttachmentsProcessingEventHandler.EnsureSuccess(); @@ -153,7 +153,7 @@ public async Task TestRunWithCodeCoverageAndAttachmentsProcessingNoMetrics(Runne Assert.AreEqual(2, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(runEventHandler.Attachments, true, false, testRunAttachmentsProcessingEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(runEventHandler.Attachments, null, true, false, testRunAttachmentsProcessingEventHandler, CancellationToken.None); // Assert testRunAttachmentsProcessingEventHandler.EnsureSuccess(); @@ -200,7 +200,7 @@ public async Task TestRunWithCodeCoverageAndAttachmentsProcessingModuleDuplicate Assert.AreEqual(3, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(runEventHandler.Attachments, true, true, testRunAttachmentsProcessingEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(runEventHandler.Attachments, null, true, true, testRunAttachmentsProcessingEventHandler, CancellationToken.None); // Assert testRunAttachmentsProcessingEventHandler.EnsureSuccess(); @@ -252,7 +252,7 @@ public async Task TestRunWithCodeCoverageAndAttachmentsProcessingCancelled(Runne CancellationTokenSource cts = new CancellationTokenSource(); - Task attachmentsProcessing = this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(attachments, true, true, testRunAttachmentsProcessingEventHandler, cts.Token); + Task attachmentsProcessing = this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(attachments, null, true, true, testRunAttachmentsProcessingEventHandler, cts.Token); while (true) { @@ -318,7 +318,7 @@ public async Task EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runn Assert.AreEqual(6, this.runEventHandler.TestResults.Count); Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - await this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(runEventHandler.Attachments, true, true, testRunAttachmentsProcessingEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.ProcessTestRunAttachmentsAsync(runEventHandler.Attachments, null, true, true, testRunAttachmentsProcessingEventHandler, CancellationToken.None); // act this.vstestConsoleWrapper?.EndSession(); diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/AttachmentsProcessing/TestRunAttachmentsProcessingManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/AttachmentsProcessing/TestRunAttachmentsProcessingManagerTests.cs index 9569bde562..a51adcc7d6 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/AttachmentsProcessing/TestRunAttachmentsProcessingManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/AttachmentsProcessing/TestRunAttachmentsProcessingManagerTests.cs @@ -74,7 +74,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachmentsT mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - VerifyMetrics(0, 0); + VerifyMetrics(inputCount: 0, outputCount: 0); } [TestMethod] @@ -93,7 +93,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturnNoAttachments_IfNoA mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - VerifyMetrics(0, 0); + VerifyMetrics(inputCount: 0, outputCount: 0); } [TestMethod] @@ -117,7 +117,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturn1NotProcessedAttach mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - VerifyMetrics(1, 1); + VerifyMetrics(inputCount: 1, outputCount: 1); } [TestMethod] @@ -140,7 +140,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturn1NotProcessedAttach mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - VerifyMetrics(1, 1); + VerifyMetrics(inputCount: 1, outputCount: 1); } [TestMethod] @@ -171,7 +171,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturn1ProcessedAttachmen mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - VerifyMetrics(1, 1); + VerifyMetrics(inputCount: 1, outputCount: 1); } [TestMethod] @@ -203,7 +203,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturn1ProcessedAttachmen mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - VerifyMetrics(1, 1); + VerifyMetrics(inputCount: 1, outputCount: 1); } [TestMethod] @@ -229,7 +229,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachmentsT mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - VerifyMetrics(1, 1, "Failed"); + VerifyMetrics(inputCount: 1, outputCount: 1, status: "Failed"); } [TestMethod] @@ -254,7 +254,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachments_ mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - VerifyMetrics(1, 1, "Failed"); + VerifyMetrics(inputCount: 1, outputCount: 1, status: "Failed"); } [TestMethod] @@ -277,8 +277,8 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachmentsT mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - - VerifyMetrics(1, 1, "Canceled"); + + VerifyMetrics(inputCount: 1, outputCount: 1, status: "Canceled"); } [TestMethod] @@ -302,7 +302,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachments_ mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - VerifyMetrics(1, 1, "Canceled"); + VerifyMetrics(inputCount: 1, outputCount: 1, status: "Canceled"); } [TestMethod] @@ -343,7 +343,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturnProcessedAttachment mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - VerifyMetrics(5, 3); + VerifyMetrics(inputCount: 5, outputCount: 3); } [TestMethod] @@ -385,7 +385,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturnProcessedAttachment mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - VerifyMetrics(5, 3); + VerifyMetrics(inputCount: 5, outputCount: 3); } [TestMethod] @@ -450,7 +450,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachmentsT mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - VerifyMetrics(1, 1, "Canceled"); + VerifyMetrics(inputCount: 1, outputCount: 1, status: "Canceled"); } [TestMethod] @@ -510,7 +510,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturnInitialAttachments_ mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - VerifyMetrics(1, 1, "Canceled"); + VerifyMetrics(inputCount: 1, outputCount: 1, status: "Canceled"); } [TestMethod] @@ -584,7 +584,7 @@ public async Task ProcessTestRunAttachmentsAsync_ShouldReturnProperlySendProgres mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Informational, "info")); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "error")); - VerifyMetrics(2, 2, "Completed"); + VerifyMetrics(inputCount: 2, outputCount: 2); } private void VerifyMetrics(int inputCount, int outputCount, string status = "Completed") diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs index 8efdaabdd9..fed30c3eb9 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs @@ -317,6 +317,7 @@ public async Task ProcessTestRunAttachmentsAsyncShouldSucceed() await this.consoleWrapper.ProcessTestRunAttachmentsAsync( attachments, + null, true, true, new Mock().Object, diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs index 94e451c43e..ee9c0f6a23 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs @@ -315,6 +315,7 @@ public async Task ProcessTestRunAttachmentsAsyncShouldSucceed() await this.consoleWrapper.ProcessTestRunAttachmentsAsync( attachments, + null, true, true, new Mock().Object, From 74cb25e3a9ed407a7068a6fba68e9600ef62fdd1 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 2 Jul 2020 00:44:41 +0200 Subject: [PATCH 57/58] Fix naming --- .../TestRunAttachmentsProcessingEventsHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/AttachmentsProcessing/TestRunAttachmentsProcessingEventsHandler.cs b/src/Microsoft.TestPlatform.Client/AttachmentsProcessing/TestRunAttachmentsProcessingEventsHandler.cs index 3a5674db16..6bceff7f24 100644 --- a/src/Microsoft.TestPlatform.Client/AttachmentsProcessing/TestRunAttachmentsProcessingEventsHandler.cs +++ b/src/Microsoft.TestPlatform.Client/AttachmentsProcessing/TestRunAttachmentsProcessingEventsHandler.cs @@ -45,11 +45,11 @@ public void HandleTestRunAttachmentsProcessingComplete(TestRunAttachmentsProcess } /// - public void HandleTestRunAttachmentsProcessingProgress(TestRunAttachmentsProcessingProgressEventArgs AttachmentsProcessingProgressEventArgs) + public void HandleTestRunAttachmentsProcessingProgress(TestRunAttachmentsProcessingProgressEventArgs attachmentsProcessingProgressEventArgs) { var payload = new TestRunAttachmentsProcessingProgressPayload() { - AttachmentsProcessingProgressEventArgs = AttachmentsProcessingProgressEventArgs, + AttachmentsProcessingProgressEventArgs = attachmentsProcessingProgressEventArgs, }; this.communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingProgress, payload); From 8468ec089570f44b0f6e907b84d88e6fa2643884 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 2 Jul 2020 11:24:57 +0200 Subject: [PATCH 58/58] Move explanation to --- .../DataCollector/IDataCollectorAttachmentProcessor.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs index 4b0581973b..dfdc77c9fe 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs @@ -22,8 +22,10 @@ public interface IDataCollectorAttachmentProcessor /// /// Indicates whether attachment processor is supporting incremental processing of attachments - /// + /// + /// /// `SupportsIncrementalProcessing` should indicate if attachment processor is supporting incremental processing of attachments. It means that `ProcessAttachmentSetsAsync` should be [associative](https://en.wikipedia.org/wiki/Associative_property). + /// By default `SupportsIncrementalProcessing` should be `False`, unless processing can take longer time and it's beneficial to start the process as soon as possible. /// /// If `SupportsIncrementalProcessing` is `True` Test Platform may try to speed up whole process by reprocessing data collector attachments as soon as possible when any two test executions are done.For example let's assume we have 5 test executions which are generating 5 data collector attachments: `a1`, `a2`, `a3`, `a4` and `a5`. Test platform could perform invocations: /// * `var result1 = await ProcessAttachmentSetsAsync([a1, a2, a3], ...);` when first 3 executions are done @@ -32,9 +34,7 @@ public interface IDataCollectorAttachmentProcessor /// /// If `SupportsIncrementalProcessing` is `False` then Test Platform will wait for all test executions to finish and call `ProcessAttachmentSetsAsync` only once: /// * `var finalResult = await ProcessAttachmentSetsAsync([a1, a2, a3, a4, a5], ...);` - /// - /// By default `SupportsIncrementalProcessing` should be `False`, unless processing can take longer time and it's beneficial to start the process as soon as possible. - /// + /// bool SupportsIncrementalProcessing { get; } ///