diff --git a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs index e2c59074db..78cc89e1be 100644 --- a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs @@ -16,8 +16,6 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization public class MultiTestRunFinalizationEventsHandler : IMultiTestRunFinalizationEventsHandler { private readonly ICommunicationManager communicationManager; - private bool finalizationCompleteSent; - private readonly object syncObject = new object(); /// /// Initializes a new instance of the class. @@ -41,26 +39,18 @@ public void HandleLogMessage(TestMessageLevel level, string message) public void HandleMultiTestRunFinalizationComplete(ICollection attachments) { - lock(this.syncObject) + if (EqtTrace.IsInfoEnabled) { - if(!finalizationCompleteSent) - { - if (EqtTrace.IsInfoEnabled) - { - EqtTrace.Info("Multi test run finalization completed."); - } - - var payload = new MultiTestRunFinalizationCompletePayload() - { - Attachments = attachments - }; + EqtTrace.Info("Multi test run finalization completed."); + } - // Send run complete to translation layer - this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationComplete, payload); + var payload = new MultiTestRunFinalizationCompletePayload() + { + Attachments = attachments + }; - finalizationCompleteSent = true; - } - } + // Send run complete to translation layer + this.communicationManager.SendMessage(MessageType.MultiTestRunFinalizationComplete, payload); } public void HandleRawMessage(string rawMessage) diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs index 41a0d7b7ce..a287b0cf6d 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs @@ -194,25 +194,12 @@ public interface ITestPlatformEventSource void MultiTestRunFinalizationRequestStop(); /// - /// The adapter multi test run finalization start. - /// - /// - /// The number of attachements. - /// - void AdapterMultiTestRunFinalizationStart(long numberOfAttachements); - - /// - /// The adapter multi test run finalization stop. + /// The multi test run finalization start. /// /// /// The number of attachements. /// - void AdapterMultiTestRunFinalizationStop(long numberOfAttachements); - - /// - /// The multi test run finalization start. - /// - void MultiTestRunFinalizationStart(); + void MultiTestRunFinalizationStart(long numberOfAttachements); /// /// The multi test run finalization stop. diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs index 7a615cf53e..7cda495578 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs @@ -252,25 +252,11 @@ public void MultiTestRunFinalizationRequestStop() this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationRequestStopEventId); } - /// - [Event(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStartEventId)] - public void AdapterMultiTestRunFinalizationStart(long numberOfAttachements) - { - this.WriteEvent(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStartEventId, numberOfAttachements); - } - - /// - [Event(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStopEventId)] - public void AdapterMultiTestRunFinalizationStop(long numberOfAttachements) - { - this.WriteEvent(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStopEventId, numberOfAttachements); - } - /// [Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId)] - public void MultiTestRunFinalizationStart() + public void MultiTestRunFinalizationStart(long numberOfAttachements) { - this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId); + this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId, numberOfAttachements); } /// diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs index 498eb86b25..2fa7f1e87a 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformInstrumentationEvents.cs @@ -178,24 +178,14 @@ internal class TestPlatformInstrumentationEvents /// public const int MultiTestRunFinalizationRequestStopEventId = 0x43; - /// - /// The adapter session finalization start event id. - /// - public const int AdapterMultiTestRunFinalizationStartEventId = 0x44; - - /// - /// The adapter session finalization stop event id. - /// - public const int AdapterMultiTestRunFinalizationStopEventId = 0x45; - /// /// Events fired on session finalization start of translation layer. /// - public const int TranslationLayerMultiTestRunFinalizationStartEventId = 0x46; + public const int TranslationLayerMultiTestRunFinalizationStartEventId = 0x44; /// /// Events fired on session finalization complete in translation layer. /// - public const int TranslationLayerMultiTestRunFinalizationStopEventId = 0x47; + public const int TranslationLayerMultiTestRunFinalizationStopEventId = 0x45; } } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs index 40037744b1..639bd48ef9 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectorAttachmentsHandler.cs @@ -27,15 +27,15 @@ public void HandleAttachements(ICollection attachments, Cancellat Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); if (attachementUri != null) { - var coverageAttachments = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); + var attachmentsToBeProcessed = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); - foreach (var coverageAttachment in coverageAttachments) + foreach (var attachment in attachmentsToBeProcessed) { - attachments.Remove(coverageAttachment); + attachments.Remove(attachment); } - ICollection mergedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(coverageAttachments), cancellationToken); - foreach (var attachment in mergedAttachments) + ICollection processedAttachements = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), cancellationToken); + foreach (var attachment in processedAttachements) { attachments.Add(attachment); } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index 398ef08071..baf4626add 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; @@ -18,13 +19,15 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinali public class MultiTestRunFinalizationManager : IMultiTestRunFinalizationManager { private readonly DataCollectorAttachmentsHandler attachmentsHandler; + private readonly ITestPlatformEventSource testPlatformEventSource; /// /// Initializes a new instance of the class. /// - public MultiTestRunFinalizationManager(DataCollectorAttachmentsHandler attachmentsHandler) + public MultiTestRunFinalizationManager(DataCollectorAttachmentsHandler attachmentsHandler, ITestPlatformEventSource testPlatformEventSource) { - this.attachmentsHandler = attachmentsHandler; + this.attachmentsHandler = attachmentsHandler ?? throw new ArgumentNullException(nameof(attachmentsHandler)); + this.testPlatformEventSource = testPlatformEventSource ?? throw new ArgumentNullException(nameof(testPlatformEventSource)); } /// @@ -39,6 +42,8 @@ public async Task FinalizeMultiTestRunAsync(ICollection attachmen { cancellationToken.ThrowIfCancellationRequested(); + testPlatformEventSource.MultiTestRunFinalizationStart(attachments.Count); + var taskCompletionSource = new TaskCompletionSource(); cancellationToken.Register(() => { @@ -47,15 +52,20 @@ public async Task FinalizeMultiTestRunAsync(ICollection attachmen Task task = Task.Run(() => { - attachmentsHandler.HandleAttachements(attachments, cancellationToken); - eventHandler.HandleMultiTestRunFinalizationComplete(attachments); + attachmentsHandler.HandleAttachements(attachments, cancellationToken); }); var completedTask = await Task.WhenAny(task, taskCompletionSource.Task); - if (completedTask != task) + if (completedTask == task) + { + eventHandler.HandleMultiTestRunFinalizationComplete(attachments); + testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count); + } + else { eventHandler.HandleMultiTestRunFinalizationComplete(null); + testPlatformEventSource.MultiTestRunFinalizationStop(0); } } catch (Exception e) @@ -64,6 +74,7 @@ public async Task FinalizeMultiTestRunAsync(ICollection attachmen eventHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); eventHandler.HandleMultiTestRunFinalizationComplete(null); + testPlatformEventSource.MultiTestRunFinalizationStop(0); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index e4532e2191..beb8efce4e 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -386,7 +386,7 @@ public void EndSession() /// public void FinalizeMultiTestRun(ICollection attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler) { - this.SendMessageAndListenAndReportAttachements(attachments, testSessionEventsHandler); + this.SendMessageAndListenAndReportAttachments(attachments, testSessionEventsHandler); } /// @@ -741,7 +741,7 @@ private async Task SendMessageAndListenAndReportTestResultsAsync(string messageT this.testPlatformEventSource.TranslationLayerExecutionStop(); } - private void SendMessageAndListenAndReportAttachements(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler) + private void SendMessageAndListenAndReportAttachments(ICollection attachments, IMultiTestRunFinalizationEventsHandler eventHandler) { try { diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 0bcd0337d6..5f57eeb7ca 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -84,7 +84,7 @@ public TestRequestManager() new InferHelper(AssemblyMetadataProvider.Instance), MetricsPublisherFactory.GetMetricsPublisher(IsTelemetryOptedIn(), CommandLineOptions.Instance.IsDesignMode), new ProcessHelper(), - new MultiTestRunFinalizationManager(new CrossPlatEngine.DataCollection.DataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()))) + new MultiTestRunFinalizationManager(new CrossPlatEngine.DataCollection.DataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()), TestPlatformEventSource.Instance)) { }