Skip to content

Commit

Permalink
Compiling OK, tests OK
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubch1 committed Jun 12, 2020
1 parent 5ae0b3a commit a9eee9c
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine
/// <summary>
/// Orchestrates multi test run finalization operations.
/// </summary>
public interface IMultiTestRunFinalizationManager
internal interface IMultiTestRunFinalizationManager
{
/// <summary>
/// Finalizes multi test run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,15 @@ private ParallelRunEventsHandler GetEventsHandler(IProxyExecutionManager concurr
{
if (concurrentManager is ProxyExecutionManagerWithDataCollection)
{
var concurrentManagerWithDataCollection = concurrentManager as ProxyExecutionManagerWithDataCollection;

return new ParallelDataCollectionEventsHandler(
this.requestData,
concurrentManager,
concurrentManagerWithDataCollection,
this.currentRunEventsHandler,
this,
this.currentRunDataAggregator);
this.currentRunDataAggregator,
concurrentManagerWithDataCollection.CancellationToken);
}

return new ParallelRunEventsHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client
{
using System;
using System.Collections.Generic;

using System.Threading;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces;
Expand Down Expand Up @@ -70,6 +70,11 @@ internal IProxyDataCollectionManager ProxyDataCollectionManager
get; private set;
}

/// <summary>
/// Gets the cancellation token for execution.
/// </summary>
internal CancellationToken CancellationToken => CancellationTokenSource.Token;

/// <summary>
/// Ensure that the Execution component of engine is ready for execution usually by loading extensions.
/// <param name="skipDefaultAdapters">Skip default adapters flag.</param>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection
using System.Threading;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;
Expand All @@ -16,17 +18,20 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection
internal class ParallelDataCollectionEventsHandler : ParallelRunEventsHandler
{
private readonly ParallelRunDataAggregator runDataAggregator;
private readonly DataCollectorAttachmentsHandler attachmentsHandler;
private readonly IMultiTestRunFinalizationManager finalizationManager;
private readonly CancellationToken cancellationToken;

public ParallelDataCollectionEventsHandler(IRequestData requestData,
IProxyExecutionManager proxyExecutionManager,
ITestRunEventsHandler actualRunEventsHandler,
IParallelProxyExecutionManager parallelProxyExecutionManager,
ParallelRunDataAggregator runDataAggregator) :
ParallelRunDataAggregator runDataAggregator,
CancellationToken cancellationToken) :
this(requestData, proxyExecutionManager, actualRunEventsHandler, parallelProxyExecutionManager, runDataAggregator, JsonDataSerializer.Instance)
{
// TODO : use TestPluginCache to iterate over all IDataCollectorAttachments
attachmentsHandler = new DataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler());
this.finalizationManager = new MultiTestRunFinalizationManager(TestPlatformEventSource.Instance, new CodeCoverageDataAttachmentsHandler());
this.cancellationToken = cancellationToken;
}

internal ParallelDataCollectionEventsHandler(IRequestData requestData,
Expand All @@ -53,7 +58,7 @@ public override void HandleTestRunComplete(

if (parallelRunComplete)
{
attachmentsHandler.HandleAttachements(runDataAggregator.RunContextAttachments, CancellationToken.None);
finalizationManager.FinalizeMultiTestRunAsync(runDataAggregator.RunContextAttachments, null, cancellationToken).Wait();

var completedArgs = new TestRunCompleteEventArgs(this.runDataAggregator.GetAggregatedRunStats(),
this.runDataAggregator.IsCanceled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;

namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinalization
Expand All @@ -18,16 +20,16 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunFinali
/// </summary>
public class MultiTestRunFinalizationManager : IMultiTestRunFinalizationManager
{
private readonly DataCollectorAttachmentsHandler attachmentsHandler;
private readonly ITestPlatformEventSource testPlatformEventSource;
private readonly IDataCollectorAttachments[] dataCollectorAttachmentsHandlers;

/// <summary>
/// Initializes a new instance of the <see cref="MultiTestRunFinalizationManager"/> class.
/// </summary>
public MultiTestRunFinalizationManager(DataCollectorAttachmentsHandler attachmentsHandler, ITestPlatformEventSource testPlatformEventSource)
public MultiTestRunFinalizationManager(ITestPlatformEventSource testPlatformEventSource, params IDataCollectorAttachments[] dataCollectorAttachmentsHandlers)
{
this.attachmentsHandler = attachmentsHandler ?? throw new ArgumentNullException(nameof(attachmentsHandler));
this.testPlatformEventSource = testPlatformEventSource ?? throw new ArgumentNullException(nameof(testPlatformEventSource));
this.dataCollectorAttachmentsHandlers = dataCollectorAttachmentsHandlers ?? throw new ArgumentNullException(nameof(dataCollectorAttachmentsHandlers));
}

/// <summary>
Expand All @@ -52,31 +54,55 @@ public async Task FinalizeMultiTestRunAsync(ICollection<AttachmentSet> attachmen

Task task = Task.Run(() =>
{
attachmentsHandler.HandleAttachements(attachments, cancellationToken);
HandleAttachements(attachments, cancellationToken);
});

var completedTask = await Task.WhenAny(task, taskCompletionSource.Task);

if (completedTask == task)
{
eventHandler.HandleMultiTestRunFinalizationComplete(attachments);
eventHandler?.HandleMultiTestRunFinalizationComplete(attachments);
testPlatformEventSource.MultiTestRunFinalizationStop(attachments.Count);
}
else
{
eventHandler.HandleMultiTestRunFinalizationComplete(null);
eventHandler?.HandleMultiTestRunFinalizationComplete(null);
testPlatformEventSource.MultiTestRunFinalizationStop(0);
}
}
catch (Exception e)
{
EqtTrace.Error("MultiTestRunFinalizationManager: Exception in FinalizeMultiTestRunAsync: " + e);

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

private void HandleAttachements(ICollection<AttachmentSet> attachments, CancellationToken cancellationToken)
{
foreach (var dataCollectorAttachmentsHandler in dataCollectorAttachmentsHandlers)
{
Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri();
if (attachementUri != null)
{
var attachmentsToBeProcessed = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray();
if (attachmentsToBeProcessed.Any())
{
foreach (var attachment in attachmentsToBeProcessed)
{
attachments.Remove(attachment);
}

ICollection<AttachmentSet> processedAttachements = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection<AttachmentSet>(attachmentsToBeProcessed), cancellationToken);
foreach (var attachment in processedAttachements)
{
attachments.Add(attachment);
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface IDataCollectorAttachments
/// </summary>
/// <returns>Gets the attachment set after Test Run Session</returns>
ICollection<AttachmentSet> HandleDataCollectionAttachmentSets(ICollection<AttachmentSet> dataCollectionAttachments, CancellationToken cancellationToken);
// TODO: add new method

/// <summary>
/// Gets the attachment Uri, which is handled by current Collector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces
{
using System;
using System.Collections.Generic;

using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
Expand Down Expand Up @@ -115,12 +116,8 @@ internal interface ITranslationLayerRequestSender : IDisposable
/// Provides back all attachements to TestPlatform for additional processing (for example merging)
/// </summary>
/// <param name="attachments">List of attachements</param>
/// <param name="multiTestRunFinalizationCompleteEventsHandler"></param>
void FinalizeMultiTestRun(ICollection<AttachmentSet> attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler);

/// <summary>
/// Cancels multi test run finalization
/// </summary>
void CancelMultiTestRunFinalization();
/// <param name="multiTestRunFinalizationCompleteEventsHandler">Events handler</param>
/// <param name="cancellationToken">Cancellation token</param>
Task FinalizeMultiTestRunAsync(ICollection<AttachmentSet> attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
Expand Down Expand Up @@ -76,5 +77,13 @@ internal interface ITranslationLayerRequestSenderAsync : IDisposable
/// See <see cref="ITranslationLayerRequestSender.OnProcessExited"/>.
/// </summary>
void OnProcessExited();

/// <summary>
/// Provides back all attachements to TestPlatform for additional processing (for example merging)
/// </summary>
/// <param name="attachments">List of attachements</param>
/// <param name="multiTestRunFinalizationCompleteEventsHandler">Events handler</param>
/// <param name="cancellationToken">Cancellation token</param>
Task FinalizeMultiTestRunAsync(ICollection<AttachmentSet> attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces
{
using System.Collections.Generic;

using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
Expand Down Expand Up @@ -119,6 +120,14 @@ public interface IVsTestConsoleWrapper
/// <param name="customTestHostLauncher">Custom test host launcher for the run.</param>
void RunTestsWithCustomTestHost(IEnumerable<TestCase> testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher);

/// <summary>
/// Provides back all attachements to TestPlatform for additional processing (for example merging)
/// </summary>
/// <param name="attachments">List of attachements</param>
/// <param name="multiTestRunFinalizationCompleteEventsHandler">EventHandler to receive session complete event</param>
/// <param name="cancellationToken">Cancellation token</param>
Task FinalizeMultiTestRunAsync(ICollection<AttachmentSet> attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken);

/// <summary>
/// Cancel the last test run.
/// </summary>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces
{
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
Expand Down Expand Up @@ -81,6 +82,14 @@ public interface IVsTestConsoleWrapperAsync
/// </summary>
Task RunTestsWithCustomTestHostAsync(IEnumerable<TestCase> testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher);

/// <summary>
/// Provides back all attachements to TestPlatform for additional processing (for example merging)
/// </summary>
/// <param name="attachments">List of attachements</param>
/// <param name="multiTestRunFinalizationCompleteEventsHandler">EventHandler to receive session complete event</param>
/// <param name="cancellationToken">Cancellation token</param>
Task FinalizeMultiTestRunAsync(ICollection<AttachmentSet> attachments, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken);

/// <summary>
/// See <see cref="IVsTestConsoleWrapper.CancelTestRun"/>.
/// </summary>
Expand Down
Loading

0 comments on commit a9eee9c

Please sign in to comment.