Skip to content

Commit

Permalink
next
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubch1 committed Jun 9, 2020
1 parent 97ab178 commit 2314550
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 49 deletions.
49 changes: 21 additions & 28 deletions src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
{
var multiTestRunsFinalizationPayload =
this.communicationManager.DeserializePayload<MultiTestRunsFinalizationPayload>(message);
this.FinalizeMultiTestRuns(multiTestRunsFinalizationPayload, testRequestManager);
this.StartMultiTestRunsFinalization(multiTestRunsFinalizationPayload, testRequestManager);
break;
}

Expand Down Expand Up @@ -468,39 +468,32 @@ private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITe
});
}

private void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload finalizationPayload, ITestRequestManager testRequestManager)
private void StartMultiTestRunsFinalization(MultiTestRunsFinalizationPayload finalizationPayload, ITestRequestManager testRequestManager)
{
lock(this.lockObject)
{
try
Task.Run(
delegate
{
var handler = new MultiTestRunsDataCollectorAttachmentsHandler(new CodeCoverageDataAttachmentsHandler());
handler.HandleAttachements(finalizationPayload.Attachments);

var payload = new MultiTestRunsFinalizationCompletePayload()
try
{
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);
testRequestManager.ResetOptions();
testRequestManager.FinalizeMultiTestRuns(finalizationPayload);
}
catch (Exception ex)
{
EqtTrace.Error("DesignModeClient: Exception in StartMultiTestRunsFinalization: " + ex);

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

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

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

#region IDisposable Support
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol;
using System;
using System.Threading;

namespace Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunsFinalization
{
public class MultiTestRunsFinalizationRequest : IMultiTestRunsFinalizationRequest
{
public event EventHandler<string> OnRawMessageReceived;

public void Abort()
{
if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose("MultiTestRunsFinalizationRequest.Abort: Aborting.");
}

lock (this.syncObject)
{
if (this.disposed)
{
throw new ObjectDisposedException("MultiTestRunsFinalizationRequest");
}

if (this.finalizationInProgress)
{
this.finalizationManager.Abort();
}
else
{
if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("MultiTestRunsFinalizationRequest.Abort: No operation to abort.");
}

return;
}
}

if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("MultiTestRunsFinalizationRequest.Abort: Aborted.");
}
}

public void FinalizeMultiTestRunsAsync()
{
throw new NotImplementedException();
}

/// <summary>
/// Wait for discovery completion
/// </summary>
/// <param name="timeout"> The timeout. </param>
bool IRequest.WaitForCompletion(int timeout)
{
if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose("MultiTestRunsFinalizationRequest.WaitForCompletion: Waiting with timeout {0}.", timeout);
}

if (this.disposed)
{
throw new ObjectDisposedException("MultiTestRunsFinalizationRequest");
}

// This method is not synchronized as it can lead to dead-lock
// (the discoveryCompletionEvent cannot be raised unless that lock is released)
if (this.finalizationCompleted != null)
{
return this.finalizationCompleted.WaitOne(timeout);
}

return true;
}

#region IDisposable implementation

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or
/// resetting unmanaged resources.
/// </summary>
public void Dispose()
{
this.Dispose(true);

GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose("MultiTestRunsFinalizationRequest.Dispose: Starting.");
}

lock (this.syncObject)
{
if (!this.disposed)
{
if (disposing)
{
if (this.finalizationCompleted != null)
{
this.finalizationCompleted.Dispose();
}
}

// Indicate that object has been disposed
this.finalizationCompleted = null;
this.disposed = true;
}
}

if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("DiscoveryRequest.Dispose: Completed.");
}
}

#endregion

#region privates fields

/// <summary>
/// If this request has been disposed.
/// </summary>
private bool disposed = false;

/// <summary>
/// It get set when current discovery request is completed.
/// </summary>
private ManualResetEvent finalizationCompleted = new ManualResetEvent(false);

/// <summary>
/// Sync object for various operations
/// </summary>
private object syncObject = new Object();

/// <summary>
/// Whether or not the test discovery is in progress.
/// </summary>
private bool finalizationInProgress;

/// <summary>
/// Discovery Start Time
/// </summary>
private DateTime finalizationStartTime;

/// <summary>
/// Finalization manager
/// </summary>
private IMultiTestRunsFinalizationManager finalizationManager;

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public interface ITestRequestManager : IDisposable
/// <param name="protocolConfig">Protocol related information</param>
void RunTests(TestRunRequestPayload testRunRequestPayLoad, ITestHostLauncher customTestHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig);

/// <summary>
/// Finalize multi test runs
/// </summary>
/// <param name="multiTestRunsFinalizationPayload">Multi test runs finalization payload</param>
void FinalizeMultiTestRuns(MultiTestRunsFinalizationPayload multiTestRunsFinalizationPayload);

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

/// <summary>
/// Cancels the current multi test runs finalization request
/// </summary>
void CancelMultiTestRunsFinalizaiton();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ public interface IMultiTestRunsFinalizationManager
/// <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);

/// <summary>
/// Aborts multi test runs finalization
/// </summary>
void Abort();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,24 +375,6 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec
break;
}

case MessageType.MultiTestRunsFinalizationStart:
{
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
Expand Up @@ -34,5 +34,13 @@ public void FinalizeMultiTestRuns(ICollection<AttachmentSet> attachments, IMulti
attachmentsHandler.HandleAttachements(attachments);
eventHandler.HandleMultiTestRunsFinalizationComplete(attachments);
}

/// <summary>
/// Aborts multi test runs finalization
/// </summary>
public void Abort()
{
throw new System.NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +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.

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client
{
/// <summary>
/// IMultiTestRunsFinalizationRequest
/// </summary>
public interface IMultiTestRunsFinalizationRequest : IRequest
{
/// <summary>
/// Starts tests discovery async.
/// </summary>
void FinalizeMultiTestRunsAsync();

/// <summary>
/// Aborts the discovery request
/// </summary>
void Abort();
}
}
Loading

0 comments on commit 2314550

Please sign in to comment.