Skip to content

Commit c1b6b2c

Browse files
committed
Adding test run attachments processing (#2463)
* 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>
1 parent df62aca commit c1b6b2c

File tree

67 files changed

+3250
-491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3250
-491
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.VisualStudio.TestPlatform.Client.TestRunAttachmentsProcessing
5+
{
6+
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
7+
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;
8+
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
9+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
10+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
11+
using System.Collections.Generic;
12+
13+
/// <summary>
14+
/// The test run attachments processing events handler.
15+
/// </summary>
16+
///
17+
public class TestRunAttachmentsProcessingEventsHandler : ITestRunAttachmentsProcessingEventsHandler
18+
{
19+
private readonly ICommunicationManager communicationManager;
20+
21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="TestRunAttachmentsProcessingEventsHandler"/> class.
23+
/// </summary>
24+
/// <param name="communicationManager"> The communication manager. </param>
25+
public TestRunAttachmentsProcessingEventsHandler(ICommunicationManager communicationManager)
26+
{
27+
this.communicationManager = communicationManager;
28+
}
29+
30+
/// <inheritdoc/>
31+
public void HandleTestRunAttachmentsProcessingComplete(TestRunAttachmentsProcessingCompleteEventArgs attachmentsProcessingCompleteEventArgs, IEnumerable<AttachmentSet> lastChunk)
32+
{
33+
if (EqtTrace.IsInfoEnabled)
34+
{
35+
EqtTrace.Info("Test run attachments processing completed.");
36+
}
37+
38+
var payload = new TestRunAttachmentsProcessingCompletePayload()
39+
{
40+
AttachmentsProcessingCompleteEventArgs = attachmentsProcessingCompleteEventArgs,
41+
Attachments = lastChunk
42+
};
43+
44+
this.communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, payload);
45+
}
46+
47+
/// <inheritdoc/>
48+
public void HandleTestRunAttachmentsProcessingProgress(TestRunAttachmentsProcessingProgressEventArgs attachmentsProcessingProgressEventArgs)
49+
{
50+
var payload = new TestRunAttachmentsProcessingProgressPayload()
51+
{
52+
AttachmentsProcessingProgressEventArgs = attachmentsProcessingProgressEventArgs,
53+
};
54+
55+
this.communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingProgress, payload);
56+
}
57+
58+
/// <inheritdoc/>
59+
public void HandleProcessedAttachmentsChunk(IEnumerable<AttachmentSet> attachments)
60+
{
61+
throw new System.NotImplementedException();
62+
}
63+
64+
/// <inheritdoc/>
65+
public void HandleLogMessage(TestMessageLevel level, string message)
66+
{
67+
var testMessagePayload = new TestMessagePayload { MessageLevel = level, Message = message };
68+
this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);
69+
}
70+
71+
/// <inheritdoc/>
72+
public void HandleRawMessage(string rawMessage)
73+
{
74+
// No-Op
75+
}
76+
}
77+
}

src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode
99
using System.Net;
1010
using System.Threading;
1111
using System.Threading.Tasks;
12-
12+
using Microsoft.VisualStudio.TestPlatform.Client.TestRunAttachmentsProcessing;
1313
using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper;
1414
using Microsoft.VisualStudio.TestPlatform.Common.Logging;
1515
using Microsoft.VisualStudio.TestPlatform.Common.Utilities;
@@ -199,6 +199,14 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
199199
break;
200200
}
201201

202+
case MessageType.TestRunAttachmentsProcessingStart:
203+
{
204+
var testRunAttachmentsProcessingPayload =
205+
this.communicationManager.DeserializePayload<TestRunAttachmentsProcessingPayload>(message);
206+
this.StartTestRunAttachmentsProcessing(testRunAttachmentsProcessingPayload, testRequestManager);
207+
break;
208+
}
209+
202210
case MessageType.CancelDiscovery:
203211
{
204212
testRequestManager.CancelDiscovery();
@@ -217,6 +225,12 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
217225
break;
218226
}
219227

228+
case MessageType.TestRunAttachmentsProcessingCancel:
229+
{
230+
testRequestManager.CancelTestRunAttachmentsProcessing();
231+
break;
232+
}
233+
220234
case MessageType.CustomTestHostLaunchCallback:
221235
{
222236
this.onCustomTestHostLaunchAckReceived?.Invoke(message);
@@ -458,6 +472,33 @@ private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITe
458472
});
459473
}
460474

475+
private void StartTestRunAttachmentsProcessing(TestRunAttachmentsProcessingPayload attachmentsProcessingPayload, ITestRequestManager testRequestManager)
476+
{
477+
Task.Run(
478+
delegate
479+
{
480+
try
481+
{
482+
testRequestManager.ProcessTestRunAttachments(attachmentsProcessingPayload, new TestRunAttachmentsProcessingEventsHandler(this.communicationManager), this.protocolConfig);
483+
}
484+
catch (Exception ex)
485+
{
486+
EqtTrace.Error("DesignModeClient: Exception in StartTestRunAttachmentsProcessing: " + ex);
487+
488+
var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() };
489+
this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);
490+
491+
var payload = new TestRunAttachmentsProcessingCompletePayload()
492+
{
493+
Attachments = null
494+
};
495+
496+
// Send run complete to translation layer
497+
this.communicationManager.SendMessage(MessageType.TestRunAttachmentsProcessingComplete, payload);
498+
}
499+
});
500+
}
501+
461502
#region IDisposable Support
462503

463504
private bool disposedValue = false; // To detect redundant calls

src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public interface ITestRequestManager : IDisposable
4444
/// <param name="protocolConfig">Protocol related information</param>
4545
void RunTests(TestRunRequestPayload testRunRequestPayLoad, ITestHostLauncher customTestHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig);
4646

47+
/// <summary>
48+
/// Processes test run attachments
49+
/// </summary>
50+
/// <param name="testRunAttachmentsProcessingPayload">Test run attachments processing payload</param>
51+
/// <param name="testRunAttachmentsProcessingEventsHandler">Test run attachments processing events handler</param>
52+
void ProcessTestRunAttachments(TestRunAttachmentsProcessingPayload testRunAttachmentsProcessingPayload, ITestRunAttachmentsProcessingEventsHandler testRunAttachmentsProcessingEventsHandler, ProtocolConfig protocolConfig);
53+
4754
/// <summary>
4855
/// Cancel the current TestRun request
4956
/// </summary>
@@ -58,5 +65,10 @@ public interface ITestRequestManager : IDisposable
5865
/// Cancels the current discovery request
5966
/// </summary>
6067
void CancelDiscovery();
68+
69+
/// <summary>
70+
/// Cancels the current test run attachments processing request
71+
/// </summary>
72+
void CancelTestRunAttachmentsProcessing();
6173
}
6274
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
5+
using System.Collections.Generic;
6+
using System.Collections.ObjectModel;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine
11+
{
12+
/// <summary>
13+
/// Orchestrates test run attachments processing operations.
14+
/// </summary>
15+
internal interface ITestRunAttachmentsProcessingManager
16+
{
17+
/// <summary>
18+
/// Processes attachments and provides results through handler
19+
/// </summary>
20+
/// <param name="attachments">Collection of attachments</param>
21+
/// <param name="eventHandler">EventHandler for handling test run attachments processing event</param>
22+
/// <param name="cancellationToken">Cancellation token</param>
23+
Task ProcessTestRunAttachmentsAsync(IRequestData requestData, IEnumerable<AttachmentSet> attachments, ITestRunAttachmentsProcessingEventsHandler eventHandler, CancellationToken cancellationToken);
24+
25+
/// <summary>
26+
/// Processes attachments
27+
/// </summary>
28+
/// <param name="attachments">Collection of attachments</param>
29+
/// <param name="cancellationToken">Cancellation token</param>
30+
/// <returns>Collection of attachments.</returns>
31+
Task<Collection<AttachmentSet>> ProcessTestRunAttachmentsAsync(IRequestData requestData, IEnumerable<AttachmentSet> attachments, CancellationToken cancellationToken);
32+
}
33+
}

src/Microsoft.TestPlatform.Common/Telemetry/TelemetryDataConstants.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,19 @@ public static class TelemetryDataConstants
9090

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

93+
// *********************Attachments Processing****************************
94+
public static string NumberOfAttachmentsSentForProcessing = "VS.AttachmentsProcessing.InitialAttachmentsCount";
95+
96+
public static string NumberOfAttachmentsAfterProcessing = "VS.AttachmentsProcessing.FinalAttachmentsCount";
97+
98+
public static string TimeTakenInSecForAttachmentsProcessing = "VS.AttachmentsProcessing.TotalTimeTakenInSec";
99+
public static string AttachmentsProcessingState = "VS.AttachmentsProcessing.State";
100+
93101
// **************Events Name **********************************
94102
public static string TestDiscoveryCompleteEvent = "vs/testplatform/testdiscoverysession";
95103

96104
public static string TestExecutionCompleteEvent = "vs/testplatform/testrunsession";
105+
106+
public static string TestAttachmentsProcessingCompleteEvent = "vs/testplatform/testattachmentsprocessingsession";
97107
}
98108
}

src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,26 @@ public static class MessageType
123123
/// </summary>
124124
public const string CustomTestHostLaunchCallback = "TestExecution.CustomTestHostLaunchCallback";
125125

126+
/// <summary>
127+
/// Test run attachments processing
128+
/// </summary>
129+
public const string TestRunAttachmentsProcessingStart = "TestRunAttachmentsProcessing.Start";
130+
131+
/// <summary>
132+
/// Test run attachments processing callback
133+
/// </summary>
134+
public const string TestRunAttachmentsProcessingComplete = "TestRunAttachmentsProcessing.Complete";
135+
136+
/// <summary>
137+
/// Test run attachments processing progress
138+
/// </summary>
139+
public const string TestRunAttachmentsProcessingProgress = "TestRunAttachmentsProcessing.Progress";
140+
141+
/// <summary>
142+
/// Cancel test run attachments processing
143+
/// </summary>
144+
public const string TestRunAttachmentsProcessingCancel = "TestRunAttachmentsProcessing.Cancel";
145+
126146
/// <summary>
127147
/// Extensions Initialization
128148
/// </summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel
5+
{
6+
using System.Collections.Generic;
7+
8+
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
9+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
10+
11+
/// <summary>
12+
/// Test run attachments processing complete payload.
13+
/// </summary>
14+
public class TestRunAttachmentsProcessingCompletePayload
15+
{
16+
/// <summary>
17+
/// Gets or sets the test run attachments processing complete args.
18+
/// </summary>
19+
public TestRunAttachmentsProcessingCompleteEventArgs AttachmentsProcessingCompleteEventArgs { get; set; }
20+
21+
/// <summary>
22+
/// Gets or sets the attachments.
23+
/// </summary>
24+
public IEnumerable<AttachmentSet> Attachments { get; set; }
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel
5+
{
6+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
7+
8+
/// <summary>
9+
/// Test run attachments processing complete payload.
10+
/// </summary>
11+
public class TestRunAttachmentsProcessingProgressPayload
12+
{
13+
/// <summary>
14+
/// Gets or sets the test run attachments processing complete args.
15+
/// </summary>
16+
public TestRunAttachmentsProcessingProgressEventArgs AttachmentsProcessingProgressEventArgs { get; set; }
17+
}
18+
}

src/Microsoft.TestPlatform.CoreUtilities/Tracing/Interfaces/ITestPlatformEventSource.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,41 @@ public interface ITestPlatformEventSource
182182
/// Mark the completion of Metrics Dispose.
183183
/// </summary>
184184
void MetricsDisposeStop();
185+
186+
/// <summary>
187+
/// The test run attachments processing request start.
188+
/// </summary>
189+
void TestRunAttachmentsProcessingRequestStart();
190+
191+
/// <summary>
192+
/// The test run attachments processing request stop.
193+
/// </summary>
194+
void TestRunAttachmentsProcessingRequestStop();
195+
196+
/// <summary>
197+
/// The test run attachments processing start.
198+
/// </summary>
199+
/// <param name="numberOfAttachments">
200+
/// The number of attachments.
201+
/// </param>
202+
void TestRunAttachmentsProcessingStart(long numberOfAttachments);
203+
204+
/// <summary>
205+
/// The test run attachments processing stop.
206+
/// </summary>
207+
/// <param name="numberOfAttachments">
208+
/// The number of attachments.
209+
/// </param>
210+
void TestRunAttachmentsProcessingStop(long numberOfAttachments);
211+
212+
/// <summary>
213+
/// Mark the start of translation layer test run attachments processing request.
214+
/// </summary>
215+
void TranslationLayerTestRunAttachmentsProcessingStart();
216+
217+
/// <summary>
218+
/// Mark the completion of translation layer test run attachments processing request.
219+
/// </summary>
220+
void TranslationLayerTestRunAttachmentsProcessingStop();
185221
}
186222
}

src/Microsoft.TestPlatform.CoreUtilities/Tracing/TestPlatformEventSource.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,5 +237,47 @@ public void MetricsDisposeStop()
237237
{
238238
this.WriteEvent(TestPlatformInstrumentationEvents.MetricsDisposeStopEventId);
239239
}
240+
241+
/// <inheritdoc/>
242+
[Event(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingRequestStartEventId)]
243+
public void TestRunAttachmentsProcessingRequestStart()
244+
{
245+
this.WriteEvent(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingRequestStartEventId);
246+
}
247+
248+
/// <inheritdoc/>
249+
[Event(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingRequestStopEventId)]
250+
public void TestRunAttachmentsProcessingRequestStop()
251+
{
252+
this.WriteEvent(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingRequestStopEventId);
253+
}
254+
255+
/// <inheritdoc/>
256+
[Event(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingStartEventId)]
257+
public void TestRunAttachmentsProcessingStart(long numberOfAttachments)
258+
{
259+
this.WriteEvent(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingStartEventId, numberOfAttachments);
260+
}
261+
262+
/// <inheritdoc/>
263+
[Event(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingStopEventId)]
264+
public void TestRunAttachmentsProcessingStop(long numberOfAttachments)
265+
{
266+
this.WriteEvent(TestPlatformInstrumentationEvents.TestRunAttachmentsProcessingStopEventId, numberOfAttachments);
267+
}
268+
269+
/// <inheritdoc/>
270+
[Event(TestPlatformInstrumentationEvents.TranslationLayerTestRunAttachmentsProcessingStartEventId)]
271+
public void TranslationLayerTestRunAttachmentsProcessingStart()
272+
{
273+
this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerTestRunAttachmentsProcessingStartEventId);
274+
}
275+
276+
/// <inheritdoc/>
277+
[Event(TestPlatformInstrumentationEvents.TranslationLayerTestRunAttachmentsProcessingStopEventId)]
278+
public void TranslationLayerTestRunAttachmentsProcessingStop()
279+
{
280+
this.WriteEvent(TestPlatformInstrumentationEvents.TranslationLayerTestRunAttachmentsProcessingStopEventId);
281+
}
240282
}
241283
}

0 commit comments

Comments
 (0)