Skip to content

Commit

Permalink
Next changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubch1 committed May 22, 2020
1 parent d799be6 commit 872bbcc
Show file tree
Hide file tree
Showing 7 changed files with 388 additions and 2 deletions.
45 changes: 45 additions & 0 deletions src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using CommunicationUtilitiesResources = Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources.Resources;
using CoreUtilitiesConstants = Microsoft.VisualStudio.TestPlatform.CoreUtilities.Constants;
using ObjectModelConstants = Microsoft.VisualStudio.TestPlatform.ObjectModel.Constants;
Expand Down Expand Up @@ -199,6 +201,14 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
break;
}

case MessageType.MultiTestRunsFinalization:
{
var multiTestRunsFinalizationPayload =
this.communicationManager.DeserializePayload<MultiTestRunsFinalizationPayload>(message);
this.FinalizeMultiTestRuns(multiTestRunsFinalizationPayload);
break;
}

case MessageType.CancelDiscovery:
{
testRequestManager.CancelDiscovery();
Expand Down Expand Up @@ -458,6 +468,41 @@ private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITe
});
}

private void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload finalizationPayload)
{
lock(this.lockObject)
{
try
{
var handler = new MultiTestRunsDataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler());
handler.HandleAttachements(finalizationPayload.Attachments);

var payload = new MultiTestRunsFinalizationCompletePayload()
{
Attachments = finalizationPayload.Attachments
};

// Send run complete to translation layer
this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationComplete, payload);
}
catch (Exception ex)
{
EqtTrace.Error("DesignModeClient: Exception in StartDiscovery: " + ex);

var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() };
this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);

var payload = new MultiTestRunsFinalizationCompletePayload()
{
Attachments = null
};

// Send run complete to translation layer
this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationComplete, payload);
}
}
}

#region IDisposable Support

private bool disposedValue = false; // To detect redundant calls
Expand Down
1 change: 1 addition & 0 deletions src/testhost.x86/testhost.x86.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<AssemblyName>testhost.x86</AssemblyName>
<TargetFrameworks>netcoreapp2.1;net451</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">netcoreapp2.1</TargetFrameworks>
<RuntimeFrameworkVersion>2.1.15</RuntimeFrameworkVersion>
<WarningsAsErrors>true</WarningsAsErrors>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>true</Prefer32Bit>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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.TestPlatform.AcceptanceTests.TranslationLayerTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

/// <inheritdoc />
public class MultiTestRunsFinalizationEventHandler : IMultiTestRunsFinalizationEventsHandler
{
/// <summary>
/// Gets the attachments.
/// </summary>
public List<AttachmentSet> Attachments { get; private set; }

/// <summary>
/// Gets the metrics.
/// </summary>
public IDictionary<string, object> Metrics { get; private set; }

/// <summary>
/// Gets the log message.
/// </summary>
public string LogMessage { get; private set; }

public List<string> Errors { get; set; }

/// <summary>
/// Gets the test message level.
/// </summary>
public TestMessageLevel TestMessageLevel { get; private set; }

public MultiTestRunsFinalizationEventHandler()
{
this.Errors = new List<string>();
this.Attachments = new List<AttachmentSet>();
}

public void EnsureSuccess()
{
if (this.Errors.Any())
{
throw new InvalidOperationException($"Test run reported errors:{Environment.NewLine}{string.Join(Environment.NewLine + Environment.NewLine, this.Errors)}");
}
}

public void HandleLogMessage(TestMessageLevel level, string message)
{
this.LogMessage = message;
this.TestMessageLevel = level;
if (level == TestMessageLevel.Error) {
this.Errors.Add(message);
}
}

public void HandleRawMessage(string rawMessage)
{
// No op
}

public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessStartInfo)
{
// No op
return -1;
}

public bool AttachDebuggerToProcess(int pid)
{
// No op
return true;
}

public void HandleMultiTestRunsFinalizationComplete(ICollection<AttachmentSet> attachments)
{
if(attachments != null)
{
this.Attachments.AddRange(attachments);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class RunEventHandler : ITestRunEventsHandler2
/// </summary>
public List<TestResult> TestResults { get; private set; }

/// <summary>
/// Gets the attachments.
/// </summary>
public List<AttachmentSet> Attachments { get; private set; }

/// <summary>
/// Gets the metrics.
/// </summary>
Expand All @@ -39,6 +44,7 @@ public RunEventHandler()
{
this.TestResults = new List<TestResult>();
this.Errors = new List<string>();
this.Attachments = new List<AttachmentSet>();
}

public void EnsureSuccess()
Expand Down Expand Up @@ -69,6 +75,11 @@ public void HandleTestRunComplete(
this.TestResults.AddRange(lastChunkArgs.NewTestResults);
}

if(runContextAttachments != null)
{
this.Attachments.AddRange(runContextAttachments);
}

this.Metrics = testRunCompleteArgs.Metrics;
}

Expand Down
Loading

0 comments on commit 872bbcc

Please sign in to comment.