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