Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed CC for in-process console scenarios #4084

Merged
merged 5 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed CC for in-proces console scenarios
  • Loading branch information
Codrin Poienaru committed Oct 21, 2022
commit f07350156bacaea9cf6e7dc1d8acd15474b6ee22
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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;
using System.Collections.Generic;

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

namespace Microsoft.VisualStudio.TestPlatform.Client;

internal class InProcessTestRunAttachmentsProcessingEventsHandler : ITestRunAttachmentsProcessingEventsHandler
cvpoienaru marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly ITestRunAttachmentsProcessingEventsHandler _oldEventsHandler;

public InProcessTestRunAttachmentsProcessingEventsHandler(
ITestRunAttachmentsProcessingEventsHandler oldEventsHandler)
{
_oldEventsHandler = oldEventsHandler;
}

public void HandleLogMessage(TestMessageLevel level, string? message)
{
_oldEventsHandler.HandleLogMessage(level, message);
}

public void HandleProcessedAttachmentsChunk(IEnumerable<AttachmentSet> attachments)
{
// Not implemented by design, keep in sync with the same named method from
// TestRunAttachmentsProcessingEventsHandler.cs.
throw new NotImplementedException();
cvpoienaru marked this conversation as resolved.
Show resolved Hide resolved
}

public void HandleRawMessage(string rawMessage)
{
// No-Op
}

public void HandleTestRunAttachmentsProcessingComplete(
TestRunAttachmentsProcessingCompleteEventArgs attachmentsProcessingCompleteEventArgs,
IEnumerable<AttachmentSet>? lastChunk)
{
_oldEventsHandler.HandleTestRunAttachmentsProcessingComplete(
attachmentsProcessingCompleteEventArgs,
lastChunk);
}

public void HandleTestRunAttachmentsProcessingProgress(
TestRunAttachmentsProcessingProgressEventArgs attachmentsProcessingProgressEventArgs)
{
_oldEventsHandler.HandleTestRunAttachmentsProcessingProgress(
attachmentsProcessingProgressEventArgs);
}
}
45 changes: 43 additions & 2 deletions src/vstest.console/InProcessVsTestConsoleWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.VisualStudio.TestPlatform.Client;
using Microsoft.VisualStudio.TestPlatform.Client.DesignMode;
using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper;
using Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces;
Expand Down Expand Up @@ -830,7 +831,7 @@ await ProcessTestRunAttachmentsAsync(
}

/// <inheritdoc/>
public Task ProcessTestRunAttachmentsAsync(
public async Task ProcessTestRunAttachmentsAsync(
IEnumerable<AttachmentSet> attachments,
IEnumerable<InvokedDataCollector>? invokedDataCollectors,
string? processingSettings,
Expand All @@ -839,7 +840,47 @@ public Task ProcessTestRunAttachmentsAsync(
ITestRunAttachmentsProcessingEventsHandler eventsHandler,
CancellationToken cancellationToken)
{
throw new NotImplementedException();
_testPlatformEventSource.TranslationLayerTestRunAttachmentsProcessingStart();

try
{
var attachmentProcessingPayload = new TestRunAttachmentsProcessingPayload
{
Attachments = attachments,
InvokedDataCollectors = invokedDataCollectors,
RunSettings = processingSettings,
CollectMetrics = collectMetrics
};

using (cancellationToken.Register(() =>
TestRequestManager?.CancelTestRunAttachmentsProcessing()))
{
// Awaiting the attachment processing task here. The implementation of the
// underlying operation guarantees the event handler is called when processing
// is complete, so when awaiting ends, the results have already been passed to
// the caller via the event handler. No need for further synchronization.
await Task.Run(() =>
TestRequestManager?.ProcessTestRunAttachments(
attachmentProcessingPayload,
new InProcessTestRunAttachmentsProcessingEventsHandler(eventsHandler),
new ProtocolConfig { Version = _highestSupportedVersion }),
CancellationToken.None)
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
.ConfigureAwait(false);
}
}
catch (Exception ex)
cvpoienaru marked this conversation as resolved.
Show resolved Hide resolved
{
EqtTrace.Error("InProcessVsTestConsoleWrapper.ProcessTestRunAttachmentsAsync: Exception occurred: " + ex ?? "payload is null");
cvpoienaru marked this conversation as resolved.
Show resolved Hide resolved

var attachmentsProcessingArgs = new TestRunAttachmentsProcessingCompleteEventArgs(
isCanceled: cancellationToken.IsCancellationRequested,
ex);

eventsHandler.HandleLogMessage(TestMessageLevel.Error, ex?.ToString());
eventsHandler.HandleTestRunAttachmentsProcessingComplete(attachmentsProcessingArgs, lastChunk: null);
}

_testPlatformEventSource.TranslationLayerTestRunAttachmentsProcessingStop();
}

/// <inheritdoc/>
Expand Down