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);