Skip to content

Commit

Permalink
Resolving more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubch1 committed Jun 11, 2020
1 parent 39f3f84 commit d56baf6
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/// <summary>
/// Initializes a new instance of the <see cref="MultiTestRunFinalizationEventsHandler"/> class.
Expand All @@ -41,26 +39,18 @@ public void HandleLogMessage(TestMessageLevel level, string message)

public void HandleMultiTestRunFinalizationComplete(ICollection<AttachmentSet> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,12 @@ public interface ITestPlatformEventSource
void MultiTestRunFinalizationRequestStop();

/// <summary>
/// The adapter multi test run finalization start.
/// </summary>
/// <param name="numberOfAttachements">
/// The number of attachements.
/// </param>
void AdapterMultiTestRunFinalizationStart(long numberOfAttachements);

/// <summary>
/// The adapter multi test run finalization stop.
/// The multi test run finalization start.
/// </summary>
/// <param name="numberOfAttachements">
/// The number of attachements.
/// </param>
void AdapterMultiTestRunFinalizationStop(long numberOfAttachements);

/// <summary>
/// The multi test run finalization start.
/// </summary>
void MultiTestRunFinalizationStart();
void MultiTestRunFinalizationStart(long numberOfAttachements);

/// <summary>
/// The multi test run finalization stop.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,25 +252,11 @@ public void MultiTestRunFinalizationRequestStop()
this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationRequestStopEventId);
}

/// <inheritdoc/>
[Event(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStartEventId)]
public void AdapterMultiTestRunFinalizationStart(long numberOfAttachements)
{
this.WriteEvent(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStartEventId, numberOfAttachements);
}

/// <inheritdoc/>
[Event(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStopEventId)]
public void AdapterMultiTestRunFinalizationStop(long numberOfAttachements)
{
this.WriteEvent(TestPlatformInstrumentationEvents.AdapterMultiTestRunFinalizationStopEventId, numberOfAttachements);
}

/// <inheritdoc/>
[Event(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId)]
public void MultiTestRunFinalizationStart()
public void MultiTestRunFinalizationStart(long numberOfAttachements)
{
this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId);
this.WriteEvent(TestPlatformInstrumentationEvents.MultiTestRunFinalizationStartEventId, numberOfAttachements);
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,14 @@ internal class TestPlatformInstrumentationEvents
/// </summary>
public const int MultiTestRunFinalizationRequestStopEventId = 0x43;

/// <summary>
/// The adapter session finalization start event id.
/// </summary>
public const int AdapterMultiTestRunFinalizationStartEventId = 0x44;

/// <summary>
/// The adapter session finalization stop event id.
/// </summary>
public const int AdapterMultiTestRunFinalizationStopEventId = 0x45;

/// <summary>
/// Events fired on session finalization start of translation layer.
/// </summary>
public const int TranslationLayerMultiTestRunFinalizationStartEventId = 0x46;
public const int TranslationLayerMultiTestRunFinalizationStartEventId = 0x44;

/// <summary>
/// Events fired on session finalization complete in translation layer.
/// </summary>
public const int TranslationLayerMultiTestRunFinalizationStopEventId = 0x47;
public const int TranslationLayerMultiTestRunFinalizationStopEventId = 0x45;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public void HandleAttachements(ICollection<AttachmentSet> 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<AttachmentSet> mergedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection<AttachmentSet>(coverageAttachments), cancellationToken);
foreach (var attachment in mergedAttachments)
ICollection<AttachmentSet> processedAttachements = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection<AttachmentSet>(attachmentsToBeProcessed), cancellationToken);
foreach (var attachment in processedAttachements)
{
attachments.Add(attachment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,13 +19,15 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinali
public class MultiTestRunFinalizationManager : IMultiTestRunFinalizationManager
{
private readonly DataCollectorAttachmentsHandler attachmentsHandler;
private readonly ITestPlatformEventSource testPlatformEventSource;

/// <summary>
/// Initializes a new instance of the <see cref="MultiTestRunFinalizationManager"/> class.
/// </summary>
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));
}

/// <summary>
Expand All @@ -39,6 +42,8 @@ public async Task FinalizeMultiTestRunAsync(ICollection<AttachmentSet> attachmen
{
cancellationToken.ThrowIfCancellationRequested();

testPlatformEventSource.MultiTestRunFinalizationStart(attachments.Count);

var taskCompletionSource = new TaskCompletionSource<object>();
cancellationToken.Register(() =>
{
Expand All @@ -47,15 +52,20 @@ public async Task FinalizeMultiTestRunAsync(ICollection<AttachmentSet> 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)
Expand All @@ -64,6 +74,7 @@ public async Task FinalizeMultiTestRunAsync(ICollection<AttachmentSet> attachmen

eventHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message);
eventHandler.HandleMultiTestRunFinalizationComplete(null);
testPlatformEventSource.MultiTestRunFinalizationStop(0);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public void EndSession()
/// <inheritdoc/>
public void FinalizeMultiTestRun(ICollection<AttachmentSet> attachments, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler)
{
this.SendMessageAndListenAndReportAttachements(attachments, testSessionEventsHandler);
this.SendMessageAndListenAndReportAttachments(attachments, testSessionEventsHandler);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -741,7 +741,7 @@ private async Task SendMessageAndListenAndReportTestResultsAsync(string messageT
this.testPlatformEventSource.TranslationLayerExecutionStop();
}

private void SendMessageAndListenAndReportAttachements(ICollection<AttachmentSet> attachments, IMultiTestRunFinalizationEventsHandler eventHandler)
private void SendMessageAndListenAndReportAttachments(ICollection<AttachmentSet> attachments, IMultiTestRunFinalizationEventsHandler eventHandler)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
}

Expand Down

0 comments on commit d56baf6

Please sign in to comment.