Skip to content

Commit

Permalink
Adding test run attachments processing (#2463)
Browse files Browse the repository at this point in the history
* v1

* Merging v1

* Rename to MultiTestRunsFinalization

* New version

* More changes

* More changes

* Next changes

* Fix

* test

* More changes

* Dmc chagnes

* next

* small changes

* compiled

* More changes

* acceptance tests green

* Review comments #1

* Resolving more comments

* Tests for design mode client

* Tests for events handler

* revert not related changes

* More changes

* Compiling OK, tests OK

* Unit tests for manager

* More changes

* More tests

* tests for reqeust sender

* more tests

* Tests for cancelling

* Acceptance tests done

* Remove not used stuff

* Fix comments

* Fix race condition in test

* Fix another race condition

* Fix converting to xml

* fix next test

* fix test

* Next changes

* Review changes #1

* Fixing multi test finalization manager tests

* Fixes

* Fix last unit test

* Fix acceptance tests

* Progress feature, compiling + unit tests

* acceptance tests changes

* More changes

* Fixing resources accesability

* Fix test

* Fix race conditions in acceptance tests

* RFC changes merged

* Log warning in case of unexpected message id

* Fix spelling

* Additional comment

* Restore some stuff in interfaces

* Big renaming

* Added processingSettings

* Fix naming

* Move explanation to <remarks>
  • Loading branch information
jakubch1 committed Jul 2, 2020
1 parent df62aca commit c1b6b2c
Show file tree
Hide file tree
Showing 67 changed files with 3,250 additions and 491 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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.Client.TestRunAttachmentsProcessing
{
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using System.Collections.Generic;

/// <summary>
/// The test run attachments processing events handler.
/// </summary>
///
public class TestRunAttachmentsProcessingEventsHandler : ITestRunAttachmentsProcessingEventsHandler
{
private readonly ICommunicationManager communicationManager;

/// <summary>
/// Initializes a new instance of the <see cref="TestRunAttachmentsProcessingEventsHandler"/> class.
/// </summary>
/// <param name="communicationManager"> The communication manager. </param>
public TestRunAttachmentsProcessingEventsHandler(ICommunicationManager communicationManager)
{
this.communicationManager = communicationManager;
}

/// <inheritdoc/>
public void HandleTestRunAttachmentsProcessingComplete(TestRunAttachmentsProcessingCompleteEventArgs attachmentsProcessingCompleteEventArgs, IEnumerable<AttachmentSet> lastChunk)
{
if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("Test run attachments processing completed.");
}

var payload = new TestRunAttachmentsProcessingCompletePayload()
{
AttachmentsProcessingCompleteEventArgs = attachmentsProcessingCompleteEventArgs,
Attachments = lastChunk
};

this.communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, payload);
}

/// <inheritdoc/>
public void HandleTestRunAttachmentsProcessingProgress(TestRunAttachmentsProcessingProgressEventArgs attachmentsProcessingProgressEventArgs)
{
var payload = new TestRunAttachmentsProcessingProgressPayload()
{
AttachmentsProcessingProgressEventArgs = attachmentsProcessingProgressEventArgs,
};

this.communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingProgress, payload);
}

/// <inheritdoc/>
public void HandleProcessedAttachmentsChunk(IEnumerable<AttachmentSet> attachments)
{
throw new System.NotImplementedException();
}

/// <inheritdoc/>
public void HandleLogMessage(TestMessageLevel level, string message)
{
var testMessagePayload = new TestMessagePayload { MessageLevel = level, Message = message };
this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);
}

/// <inheritdoc/>
public void HandleRawMessage(string rawMessage)
{
// No-Op
}
}
}
43 changes: 42 additions & 1 deletion src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode
using System.Net;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.VisualStudio.TestPlatform.Client.TestRunAttachmentsProcessing;
using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper;
using Microsoft.VisualStudio.TestPlatform.Common.Logging;
using Microsoft.VisualStudio.TestPlatform.Common.Utilities;
Expand Down Expand Up @@ -199,6 +199,14 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
break;
}

case MessageType.TestRunAttachmentsProcessingStart:
{
var testRunAttachmentsProcessingPayload =
this.communicationManager.DeserializePayload<TestRunAttachmentsProcessingPayload>(message);
this.StartTestRunAttachmentsProcessing(testRunAttachmentsProcessingPayload, testRequestManager);
break;
}

case MessageType.CancelDiscovery:
{
testRequestManager.CancelDiscovery();
Expand All @@ -217,6 +225,12 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
break;
}

case MessageType.TestRunAttachmentsProcessingCancel:
{
testRequestManager.CancelTestRunAttachmentsProcessing();
break;
}

case MessageType.CustomTestHostLaunchCallback:
{
this.onCustomTestHostLaunchAckReceived?.Invoke(message);
Expand Down Expand Up @@ -458,6 +472,33 @@ private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITe
});
}

private void StartTestRunAttachmentsProcessing(TestRunAttachmentsProcessingPayload attachmentsProcessingPayload, ITestRequestManager testRequestManager)
{
Task.Run(
delegate
{
try
{
testRequestManager.ProcessTestRunAttachments(attachmentsProcessingPayload, new TestRunAttachmentsProcessingEventsHandler(this.communicationManager), this.protocolConfig);
}
catch (Exception ex)
{
EqtTrace.Error("DesignModeClient: Exception in StartTestRunAttachmentsProcessing: " + ex);

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

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

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

#region IDisposable Support

private bool disposedValue = false; // To detect redundant calls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public interface ITestRequestManager : IDisposable
/// <param name="protocolConfig">Protocol related information</param>
void RunTests(TestRunRequestPayload testRunRequestPayLoad, ITestHostLauncher customTestHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig);

/// <summary>
/// Processes test run attachments
/// </summary>
/// <param name="testRunAttachmentsProcessingPayload">Test run attachments processing payload</param>
/// <param name="testRunAttachmentsProcessingEventsHandler">Test run attachments processing events handler</param>
void ProcessTestRunAttachments(TestRunAttachmentsProcessingPayload testRunAttachmentsProcessingPayload, ITestRunAttachmentsProcessingEventsHandler testRunAttachmentsProcessingEventsHandler, ProtocolConfig protocolConfig);

/// <summary>
/// Cancel the current TestRun request
/// </summary>
Expand All @@ -58,5 +65,10 @@ public interface ITestRequestManager : IDisposable
/// Cancels the current discovery request
/// </summary>
void CancelDiscovery();

/// <summary>
/// Cancels the current test run attachments processing request
/// </summary>
void CancelTestRunAttachmentsProcessing();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine
{
/// <summary>
/// Orchestrates test run attachments processing operations.
/// </summary>
internal interface ITestRunAttachmentsProcessingManager
{
/// <summary>
/// Processes attachments and provides results through handler
/// </summary>
/// <param name="attachments">Collection of attachments</param>
/// <param name="eventHandler">EventHandler for handling test run attachments processing event</param>
/// <param name="cancellationToken">Cancellation token</param>
Task ProcessTestRunAttachmentsAsync(IRequestData requestData, IEnumerable<AttachmentSet> attachments, ITestRunAttachmentsProcessingEventsHandler eventHandler, CancellationToken cancellationToken);

/// <summary>
/// Processes attachments
/// </summary>
/// <param name="attachments">Collection of attachments</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Collection of attachments.</returns>
Task<Collection<AttachmentSet>> ProcessTestRunAttachmentsAsync(IRequestData requestData, IEnumerable<AttachmentSet> attachments, CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,19 @@ public static class TelemetryDataConstants

public static string NumberOfAdapterUsedToDiscoverTests = "VS.TestDiscovery.AdaptersUsedCount";

// *********************Attachments Processing****************************
public static string NumberOfAttachmentsSentForProcessing = "VS.AttachmentsProcessing.InitialAttachmentsCount";

public static string NumberOfAttachmentsAfterProcessing = "VS.AttachmentsProcessing.FinalAttachmentsCount";

public static string TimeTakenInSecForAttachmentsProcessing = "VS.AttachmentsProcessing.TotalTimeTakenInSec";
public static string AttachmentsProcessingState = "VS.AttachmentsProcessing.State";

// **************Events Name **********************************
public static string TestDiscoveryCompleteEvent = "vs/testplatform/testdiscoverysession";

public static string TestExecutionCompleteEvent = "vs/testplatform/testrunsession";

public static string TestAttachmentsProcessingCompleteEvent = "vs/testplatform/testattachmentsprocessingsession";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ public static class MessageType
/// </summary>
public const string CustomTestHostLaunchCallback = "TestExecution.CustomTestHostLaunchCallback";

/// <summary>
/// Test run attachments processing
/// </summary>
public const string TestRunAttachmentsProcessingStart = "TestRunAttachmentsProcessing.Start";

/// <summary>
/// Test run attachments processing callback
/// </summary>
public const string TestRunAttachmentsProcessingComplete = "TestRunAttachmentsProcessing.Complete";

/// <summary>
/// Test run attachments processing progress
/// </summary>
public const string TestRunAttachmentsProcessingProgress = "TestRunAttachmentsProcessing.Progress";

/// <summary>
/// Cancel test run attachments processing
/// </summary>
public const string TestRunAttachmentsProcessingCancel = "TestRunAttachmentsProcessing.Cancel";

/// <summary>
/// Extensions Initialization
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.ObjectModel
{
using System.Collections.Generic;

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

/// <summary>
/// Test run attachments processing complete payload.
/// </summary>
public class TestRunAttachmentsProcessingCompletePayload
{
/// <summary>
/// Gets or sets the test run attachments processing complete args.
/// </summary>
public TestRunAttachmentsProcessingCompleteEventArgs AttachmentsProcessingCompleteEventArgs { get; set; }

/// <summary>
/// Gets or sets the attachments.
/// </summary>
public IEnumerable<AttachmentSet> Attachments { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.ObjectModel
{
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;

/// <summary>
/// Test run attachments processing complete payload.
/// </summary>
public class TestRunAttachmentsProcessingProgressPayload
{
/// <summary>
/// Gets or sets the test run attachments processing complete args.
/// </summary>
public TestRunAttachmentsProcessingProgressEventArgs AttachmentsProcessingProgressEventArgs { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,41 @@ public interface ITestPlatformEventSource
/// Mark the completion of Metrics Dispose.
/// </summary>
void MetricsDisposeStop();

/// <summary>
/// The test run attachments processing request start.
/// </summary>
void TestRunAttachmentsProcessingRequestStart();

/// <summary>
/// The test run attachments processing request stop.
/// </summary>
void TestRunAttachmentsProcessingRequestStop();

/// <summary>
/// The test run attachments processing start.
/// </summary>
/// <param name="numberOfAttachments">
/// The number of attachments.
/// </param>
void TestRunAttachmentsProcessingStart(long numberOfAttachments);

/// <summary>
/// The test run attachments processing stop.
/// </summary>
/// <param name="numberOfAttachments">
/// The number of attachments.
/// </param>
void TestRunAttachmentsProcessingStop(long numberOfAttachments);

/// <summary>
/// Mark the start of translation layer test run attachments processing request.
/// </summary>
void TranslationLayerTestRunAttachmentsProcessingStart();

/// <summary>
/// Mark the completion of translation layer test run attachments processing request.
/// </summary>
void TranslationLayerTestRunAttachmentsProcessingStop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,47 @@ public void MetricsDisposeStop()
{
this.WriteEvent(TestPlatformInstrumentationEvents.MetricsDisposeStopEventId);
}

/// <inheritdoc/>
[Event(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingRequestStartEventId)]
public void TestRunAttachmentsProcessingRequestStart()
{
this.WriteEvent(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingRequestStartEventId);
}

/// <inheritdoc/>
[Event(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingRequestStopEventId)]
public void TestRunAttachmentsProcessingRequestStop()
{
this.WriteEvent(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingRequestStopEventId);
}

/// <inheritdoc/>
[Event(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingStartEventId)]
public void TestRunAttachmentsProcessingStart(long numberOfAttachments)
{
this.WriteEvent(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingStartEventId, numberOfAttachments);
}

/// <inheritdoc/>
[Event(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingStopEventId)]
public void TestRunAttachmentsProcessingStop(long numberOfAttachments)
{
this.WriteEvent(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingStopEventId, numberOfAttachments);
}

/// <inheritdoc/>
[Event(TestPlatformInstrumentationEvents.TranslationLayerTestRunAttachmentsProcessingStartEventId)]
public void TranslationLayerTestRunAttachmentsProcessingStart()
{
this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerTestRunAttachmentsProcessingStartEventId);
}

/// <inheritdoc/>
[Event(TestPlatformInstrumentationEvents.TranslationLayerTestRunAttachmentsProcessingStopEventId)]
public void TranslationLayerTestRunAttachmentsProcessingStop()
{
this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerTestRunAttachmentsProcessingStopEventId);
}
}
}
Loading

0 comments on commit c1b6b2c

Please sign in to comment.