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

Aborting discovery #2896

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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