Skip to content

Commit

Permalink
Aborting discovery (#2896)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanan07 authored May 11, 2021
1 parent 02b06df commit 9b8fac9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

using CommonResources = Common.Resources.Resources;

/// <summary>
/// ParallelDiscoveryEventsHandler for handling the discovery events in case of parallel discovery
/// </summary>
Expand Down Expand Up @@ -122,6 +124,13 @@ public void HandleRawMessage(string rawMessage)
// Always aggregate data, deserialize and raw for complete events
var message = this.dataSerializer.DeserializeMessage(rawMessage);

// Do not send CancellationRequested message to Output window in IDE, as it is not useful for user
if (string.Equals(message.MessageType, MessageType.TestMessage)
&& rawMessage.IndexOf(CommonResources.CancellationRequested) >= 0)
{
return;
}

// Do not deserialize further
if (!string.Equals(MessageType.DiscoveryComplete, message.MessageType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ internal class ParallelProxyDiscoveryManager : ParallelOperationManager<IProxyDi

private IRequestData requestData;

// This field indicates if abort was requested by testplatform (user)
private bool discoveryAbortRequested = false;

#endregion

#region Concurrency Keeper Objects
Expand Down Expand Up @@ -89,6 +92,7 @@ public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEve
/// <inheritdoc/>
public void Abort()
{
this.discoveryAbortRequested = true;
this.DoActionOnAllManagers((proxyManager) => proxyManager.Abort(), doActionsInParallel: true);
}

Expand Down Expand Up @@ -121,8 +125,13 @@ public bool HandlePartialDiscoveryComplete(IProxyDiscoveryManager proxyDiscovery
}
}

// Discovery is completed. Schedule the clean up for managers and handlers.
if (allDiscoverersCompleted)
/*
If discovery is complete or discovery aborting was requsted by testPlatfrom(user)
we need to stop all ongoing discoveries, because we want to separate aborting request
when testhost crashed by itself and when user requested it (f.e. through TW)
Schedule the clean up for managers and handlers.
*/
if (allDiscoverersCompleted || discoveryAbortRequested)
{
// Reset enumerators
this.sourceEnumerator = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ public void DiscoveryTestsShouldProcessAllSourcesOnDiscoveryAbortsForAnySource()
Assert.AreEqual(2, processedSources.Count, "All Sources must be processed.");
}

/// <summary>
/// Create ParallelProxyDiscoveryManager with parallel level 1 and two sources,
/// Overall discovery should stop, if aborting was requested
/// </summary>
[TestMethod]
public void DiscoveryTestsShouldStopDiscoveryIfAbortionWasRequested()
{
// Since the hosts are aborted, total aggregated tests sent across will be -1
var discoveryManagerMock = new Mock<IProxyDiscoveryManager>();
this.createdMockManagers.Add(discoveryManagerMock);
var parallelDiscoveryManager = this.SetupDiscoveryManager(() => discoveryManagerMock.Object, 1, true, totalTests: -1);

Task.Run(() =>
{
parallelDiscoveryManager.DiscoverTests(this.testDiscoveryCriteria, this.mockHandler.Object);
parallelDiscoveryManager.Abort();
});

Assert.IsTrue(this.discoveryCompleted.Wait(taskTimeout), "Test discovery not completed.");
Assert.AreEqual(1, processedSources.Count, "One source should be processed.");
}

[TestMethod]
public void DiscoveryTestsShouldProcessAllSourceIfOneDiscoveryManagerIsStarved()
{
Expand Down

0 comments on commit 9b8fac9

Please sign in to comment.