Skip to content

Commit

Permalink
More changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubch1 committed May 21, 2020
1 parent 91c8785 commit d799be6
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using System.Collections.Generic;

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol
{
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using System.Collections.Generic;

namespace Microsoft.VisualStudio.TestPlatform.Common.Interfaces.Engine.TesthostProtocol
/// <summary>
/// Orchestrates multi test runs finalization operations for the engine communicating with the test host process.
/// </summary>
public interface IMultiTestRunsFinalizationManager
{
/// <summary>
/// Orchestrates multi test runs finalization operations for the engine communicating with the test host process.
/// Finalizes multi test runs
/// </summary>
public interface IMultiTestRunsFinalizationManager
{
/// <summary>
/// Discovers tests
/// </summary>
/// <param name="discoveryCriteria">Settings, parameters for the discovery request</param>
/// <param name="eventHandler">EventHandler for handling discovery events from Engine</param>
void FinalizeMultiTestRuns(IEnumerable<AttachmentSet> attachments, IMultiTestRunsFinalizationEventsHandler eventHandler);
}
/// <param name="attachments">Attachments</param>
/// <param name="eventHandler">EventHandler for handling multi test runs finalization events from Engine</param>
void FinalizeMultiTestRuns(ICollection<AttachmentSet> attachments, IMultiTestRunsFinalizationEventsHandler eventHandler);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 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
{
using System.Collections.Generic;

using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

/// <summary>
/// The multi test finalization event handler.
/// </summary>
public class MultiTestRunsFinalizationEventsHandler : IMultiTestRunsFinalizationEventsHandler
{
private ITestRequestHandler requestHandler;

/// <summary>
/// Initializes a new instance of the <see cref="MultiTestRunsFinalizationEventsHandler"/> class.
/// </summary>
/// <param name="requestHandler"> The Request Handler. </param>
public MultiTestRunsFinalizationEventsHandler(ITestRequestHandler requestHandler)
{
this.requestHandler = requestHandler;
}

/// <summary>
/// The handle discovery message.
/// </summary>
/// <param name="level"> Logging level. </param>
/// <param name="message"> Logging message. </param>
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);
}

public void HandleMultiTestRunsFinalizationComplete(ICollection<AttachmentSet> attachments)
{
if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("Multi test runs finalization completed.");
}

this.requestHandler.MultiTestRunsFinalizationComplete(attachments);
}

public void HandleRawMessage(string rawMessage)
{
// No-Op
// TestHost at this point has no functionality where it requires rawmessage
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public interface ITestRequestHandler : IDisposable
/// <param name="lastChunk"> The last Chunk. </param>
void DiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable<TestCase> lastChunk);

/// <summary>
/// The multi test runs finalization complete handler
/// </summary>
/// <param name="attachments">Attachments</param>
void MultiTestRunsFinalizationComplete(ICollection<AttachmentSet> attachments);

/// <summary>
/// Launches a process with a given process info under debugger
/// Adapter get to call into this to launch any additional processes under debugger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static class MessageType
/// <summary>
/// Multi test runs finalization callback
/// </summary>
public const string MultiTestRunsFinalizationCallback = "TestExecution.MultiTestRunsFinalizationCallback";
public const string MultiTestRunsFinalizationComplete = "TestExecution.MultiTestRunsFinalizationComplete";

/// <summary>
/// Extensions Initialization
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection
{
public class MultiTestRunsDataCollectorAttachmentsHandler
{
private readonly IDataCollectorAttachments dataCollectorAttachmentsHandler;

public MultiTestRunsDataCollectorAttachmentsHandler(IDataCollectorAttachments dataCollectorAttachmentsHandler)
{
this.dataCollectorAttachmentsHandler = dataCollectorAttachmentsHandler;
}

public void HandleAttachements(ICollection<AttachmentSet> attachments)
{
Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri();
if (attachementUri != null)
{
var coverageAttachments = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray();

foreach (var coverageAttachment in coverageAttachments)
{
attachments.Remove(coverageAttachment);
}

ICollection<AttachmentSet> mergedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection<AttachmentSet>(coverageAttachments));
foreach (var attachment in mergedAttachments)
{
attachments.Add(attachment);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
Expand All @@ -19,6 +16,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection
internal class ParallelDataCollectionEventsHandler : ParallelRunEventsHandler
{
private readonly ParallelRunDataAggregator runDataAggregator;
private readonly MultiTestRunsDataCollectorAttachmentsHandler attachmentsHandler;

public ParallelDataCollectionEventsHandler(IRequestData requestData,
IProxyExecutionManager proxyExecutionManager,
Expand All @@ -27,6 +25,8 @@ public ParallelDataCollectionEventsHandler(IRequestData requestData,
ParallelRunDataAggregator runDataAggregator) :
this(requestData, proxyExecutionManager, actualRunEventsHandler, parallelProxyExecutionManager, runDataAggregator, JsonDataSerializer.Instance)
{
// TODO : use TestPluginCache to iterate over all IDataCollectorAttachments
attachmentsHandler = new MultiTestRunsDataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler());
}

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

if (parallelRunComplete)
{
// TODO : use TestPluginCache to iterate over all IDataCollectorAttachments
{
var coverageHandler = new CodeCoverageDataAttachmentsHandler();
Uri attachementUri = coverageHandler.GetExtensionUri();
if (attachementUri != null)
{
var coverageAttachments = runDataAggregator.RunContextAttachments
.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray();

foreach (var coverageAttachment in coverageAttachments)
{
runDataAggregator.RunContextAttachments.Remove(coverageAttachment);
}

ICollection<AttachmentSet> attachments = coverageHandler.HandleDataCollectionAttachmentSets(new Collection<AttachmentSet>(coverageAttachments));
foreach (var attachment in attachments)
{
runDataAggregator.RunContextAttachments.Add(attachment);
}
}
}
attachmentsHandler.HandleAttachements(runDataAggregator.RunContextAttachments);

var completedArgs = new TestRunCompleteEventArgs(this.runDataAggregator.GetAggregatedRunStats(),
this.runDataAggregator.IsCanceled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.EventHandlers;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.EventHandlers;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunsFinalization;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;
Expand Down Expand Up @@ -193,6 +196,19 @@ public void DiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventA
this.SendData(data);
}

/// <inheritdoc />
public void MultiTestRunsFinalizationComplete(ICollection<AttachmentSet> attachments)
{
var data = this.dataSerializer.SerializePayload(
MessageType.MultiTestRunsFinalizationComplete,
new MultiTestRunsFinalizationCompletePayload
{
Attachments = attachments
},
this.protocolVersion);
this.SendData(data);
}

/// <inheritdoc />
public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessStartInfo)
{
Expand Down Expand Up @@ -359,6 +375,24 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec
break;
}

case MessageType.MultiTestRunsFinalization:
{
EqtTrace.Info("Multi test runs finalization started.");
var multiTestRunsFinalizationEventsHandler = new MultiTestRunsFinalizationEventsHandler(this);
var multiTestRunsFinalizationManager = new MultiTestRunsFinalizationManager(new MultiTestRunsDataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler()));
var multiTestRunsFinalizationPayload = this.dataSerializer.DeserializePayload<MultiTestRunsFinalizationPayload>(message);

jobQueue.QueueJob(
() =>
multiTestRunsFinalizationManager
.FinalizeMultiTestRuns(
multiTestRunsFinalizationPayload.Attachments,
multiTestRunsFinalizationEventsHandler),
0);

break;
}

case MessageType.CancelTestRun:
jobQueue.Pause();
this.testHostManagerFactoryReady.Wait();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
using System;
// 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.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol;

namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.MultiTestRunsFinalization
{
class MultiTestRunsFinalizationManager
/// <summary>
/// Orchestrates multi test runs finalization operations for the engine communicating with the test host process.
/// </summary>
public class MultiTestRunsFinalizationManager : IMultiTestRunsFinalizationManager
{
private readonly MultiTestRunsDataCollectorAttachmentsHandler attachmentsHandler;

/// <summary>
/// Initializes a new instance of the <see cref="MultiTestRunsFinalizationManager"/> class.
/// </summary>
public MultiTestRunsFinalizationManager(MultiTestRunsDataCollectorAttachmentsHandler attachmentsHandler)
{
this.attachmentsHandler = attachmentsHandler;
}

/// <summary>
/// Finalizes multi test runs
/// </summary>
/// <param name="attachments">Attachments</param>
/// <param name="eventHandler">EventHandler for handling multi test runs finalization events from Engine</param>
public void FinalizeMultiTestRuns(ICollection<AttachmentSet> attachments, IMultiTestRunsFinalizationEventsHandler eventHandler)
{
attachmentsHandler.HandleAttachements(attachments);
eventHandler.HandleMultiTestRunsFinalizationComplete(attachments);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +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.Collections.Generic;

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client
{
using System.Collections.Generic;

/// <summary>
/// Interface contract for handling multi test runs finalization complete events
/// </summary>
Expand All @@ -14,6 +14,6 @@ public interface IMultiTestRunsFinalizationEventsHandler : ITestMessageEventHand
/// Dispatch MultiTestRunsFinalizationComplete event to listeners.
/// </summary>
/// <param name="attachments">Attachments reprocessed.</param>
void HandleMultiTestRunsFinalizationComplete(IEnumerable<AttachmentSet> attachments);
void HandleMultiTestRunsFinalizationComplete(ICollection<AttachmentSet> attachments);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.Payloads
namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client
{
using System.Collections.Generic;
using System.Runtime.Serialization;
Expand All @@ -15,6 +15,6 @@ public class MultiTestRunsFinalizationPayload
/// Settings used for the discovery request.
/// </summary>
[DataMember]
public IEnumerable<AttachmentSet> Attachments { get; set; }
public ICollection<AttachmentSet> Attachments { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ internal interface ITranslationLayerRequestSender : IDisposable
/// </summary>
/// <param name="attachments">List of attachements</param>
/// <param name="multiTestRunsFinalizationCompleteEventsHandler"></param>
void FinalizeMultiTestRuns(IEnumerable<AttachmentSet> attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler);
void FinalizeMultiTestRuns(ICollection<AttachmentSet> attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public interface IVsTestConsoleWrapper2 : IVsTestConsoleWrapper
/// </summary>
/// <param name="attachments">List of attachements</param>
/// <param name="multiTestRunsFinalizationCompleteEventsHandler">EventHandler to receive session complete event</param>
void FinalizeMultiTestRuns(IEnumerable<AttachmentSet> attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler);
void FinalizeMultiTestRuns(ICollection<AttachmentSet> attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler);
}
}
Loading

0 comments on commit d799be6

Please sign in to comment.