diff --git a/TestPlatform.sln b/TestPlatform.sln
index 3849fef928..4db14778e0 100644
--- a/TestPlatform.sln
+++ b/TestPlatform.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.26730.16
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29025.244
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED0C35EB-7F31-4841-A24F-8EB708FFA959}"
EndProject
@@ -170,6 +170,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SettingsMigrator", "src\Set
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SettingsMigrator.UnitTests", "test\SettingsMigrator.UnitTests\SettingsMigrator.UnitTests.csproj", "{E7D4921C-F12D-4E1C-85AC-8B7F91C59B0E}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiscoveryTestProject", "test\TestAssets\DiscoveryTestProject\DiscoveryTestProject.csproj", "{D16ACC60-52F8-4912-8870-5733A9F6852D}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -852,6 +854,18 @@ Global
{E7D4921C-F12D-4E1C-85AC-8B7F91C59B0E}.Release|x64.Build.0 = Release|Any CPU
{E7D4921C-F12D-4E1C-85AC-8B7F91C59B0E}.Release|x86.ActiveCfg = Release|Any CPU
{E7D4921C-F12D-4E1C-85AC-8B7F91C59B0E}.Release|x86.Build.0 = Release|Any CPU
+ {D16ACC60-52F8-4912-8870-5733A9F6852D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D16ACC60-52F8-4912-8870-5733A9F6852D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D16ACC60-52F8-4912-8870-5733A9F6852D}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {D16ACC60-52F8-4912-8870-5733A9F6852D}.Debug|x64.Build.0 = Debug|Any CPU
+ {D16ACC60-52F8-4912-8870-5733A9F6852D}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {D16ACC60-52F8-4912-8870-5733A9F6852D}.Debug|x86.Build.0 = Debug|Any CPU
+ {D16ACC60-52F8-4912-8870-5733A9F6852D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D16ACC60-52F8-4912-8870-5733A9F6852D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D16ACC60-52F8-4912-8870-5733A9F6852D}.Release|x64.ActiveCfg = Release|Any CPU
+ {D16ACC60-52F8-4912-8870-5733A9F6852D}.Release|x64.Build.0 = Release|Any CPU
+ {D16ACC60-52F8-4912-8870-5733A9F6852D}.Release|x86.ActiveCfg = Release|Any CPU
+ {D16ACC60-52F8-4912-8870-5733A9F6852D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -925,6 +939,7 @@ Global
{A7E2261B-B2E6-4CBF-983F-E3A3FF8E52E3} = {D9A30E32-D466-4EC5-B4F2-62E17562279B}
{69F5FF81-5615-4F06-B83C-FCF979BB84CA} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959}
{E7D4921C-F12D-4E1C-85AC-8B7F91C59B0E} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
+ {D16ACC60-52F8-4912-8870-5733A9F6852D} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0541B30C-FF51-4E28-B172-83F5F3934BCD}
diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
index 2c80c6ef3e..41e6b135ae 100644
--- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
+++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
@@ -196,6 +196,12 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
break;
}
+ case MessageType.CancelDiscovery:
+ {
+ testRequestManager.CancelDiscovery();
+ break;
+ }
+
case MessageType.CancelTestRun:
{
testRequestManager.CancelTestRun();
diff --git a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs
index db1e20024a..d23975afed 100644
--- a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs
+++ b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs
@@ -53,5 +53,10 @@ public interface ITestRequestManager : IDisposable
/// Abort the current TestRun
///
void AbortTestRun();
+
+ ///
+ /// Cancels the current discovery request
+ ///
+ void CancelDiscovery();
}
}
diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs
index 099a15d6ad..b7eb93ded8 100644
--- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs
+++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs
@@ -63,6 +63,11 @@ public static class MessageType
///
public const string DiscoveryComplete = "TestDiscovery.Completed";
+ ///
+ /// Cancel Test Discovery
+ ///
+ public const string CancelDiscovery = "TestDiscovery.Cancel";
+
///
/// The session start.
///
diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscovererEnumerator.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscovererEnumerator.cs
index 4ab2a1aa17..48666d0c3d 100644
--- a/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscovererEnumerator.cs
+++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscovererEnumerator.cs
@@ -10,7 +10,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery
using System.IO;
using System.Linq;
using System.Reflection;
-
+ using System.Threading;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities;
using Microsoft.VisualStudio.TestPlatform.Common.Filtering;
@@ -33,44 +33,59 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery
///
internal class DiscovererEnumerator
{
- private DiscoveryResultCache discoveryResultCache;
- private ITestPlatformEventSource testPlatformEventSource;
- private IRequestData requestData;
- private IAssemblyProperties assemblyProperties;
+ private readonly DiscoveryResultCache discoveryResultCache;
+ private readonly ITestPlatformEventSource testPlatformEventSource;
+ private readonly IRequestData requestData;
+ private readonly IAssemblyProperties assemblyProperties;
+ private readonly CancellationToken cancellationToken;
///
/// Initializes a new instance of the class.
///
/// The request data for providing discovery services and data.
/// The discovery result cache.
- /// Metric Collector
- public DiscovererEnumerator(IRequestData requestData, DiscoveryResultCache discoveryResultCache) : this(requestData, discoveryResultCache, TestPlatformEventSource.Instance)
+ public DiscovererEnumerator(IRequestData requestData, DiscoveryResultCache discoveryResultCache, CancellationToken token)
+ : this(requestData, discoveryResultCache, TestPlatformEventSource.Instance, token)
{
}
- internal DiscovererEnumerator(IRequestData requestData,
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The request data for providing discovery services and data.
+ /// The discovery result cache.
+ /// Telemetry events receiver
+ /// Cancellation Token to abort discovery
+ public DiscovererEnumerator(IRequestData requestData,
DiscoveryResultCache discoveryResultCache,
- ITestPlatformEventSource testPlatformEventSource)
+ ITestPlatformEventSource testPlatformEventSource,
+ CancellationToken token)
+ : this(requestData, discoveryResultCache, testPlatformEventSource, new AssemblyProperties(), token)
{
- this.discoveryResultCache = discoveryResultCache;
- this.testPlatformEventSource = testPlatformEventSource;
- this.requestData = requestData;
- this.assemblyProperties = new AssemblyProperties();
}
- // Added this to make class testable, needed a PEHeader mocked Instance
- internal DiscovererEnumerator(IRequestData requestData,
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The request data for providing discovery services and data.
+ /// The discovery result cache.
+ /// Telemetry events receiver
+ /// Information on the assemblies being discovered
+ /// Cancellation Token to abort discovery
+ public DiscovererEnumerator(IRequestData requestData,
DiscoveryResultCache discoveryResultCache,
ITestPlatformEventSource testPlatformEventSource,
- IAssemblyProperties assemblyProperties)
+ IAssemblyProperties assemblyProperties,
+ CancellationToken token)
{
+ // Added this to make class testable, needed a PEHeader mocked Instance
this.discoveryResultCache = discoveryResultCache;
this.testPlatformEventSource = testPlatformEventSource;
this.requestData = requestData;
this.assemblyProperties = assemblyProperties;
+ this.cancellationToken = token;
}
-
///
/// Discovers tests from the sources.
///
@@ -78,14 +93,20 @@ internal DiscovererEnumerator(IRequestData requestData,
/// The settings.
/// The test case filter.
/// The logger.
- internal void LoadTests(IDictionary> testExtensionSourceMap, IRunSettings settings, string testCaseFilter, IMessageLogger logger)
+ public void LoadTests(IDictionary> testExtensionSourceMap, IRunSettings settings, string testCaseFilter, IMessageLogger logger)
{
this.testPlatformEventSource.DiscoveryStart();
- foreach (var kvp in testExtensionSourceMap)
+ try
{
- this.LoadTestsFromAnExtension(kvp.Key, kvp.Value, settings, testCaseFilter, logger);
+ foreach (var kvp in testExtensionSourceMap)
+ {
+ this.LoadTestsFromAnExtension(kvp.Key, kvp.Value, settings, testCaseFilter, logger);
+ }
+ }
+ finally
+ {
+ this.testPlatformEventSource.DiscoveryStop(this.discoveryResultCache.TotalDiscoveredTests);
}
- this.testPlatformEventSource.DiscoveryStop(this.discoveryResultCache.TotalDiscoveredTests);
}
///
@@ -105,7 +126,7 @@ private void LoadTestsFromAnExtension(string extensionAssembly, IEnumerable> GetDiscoverers(
string extensionAssembly,
@@ -436,7 +473,7 @@ private static IEnumerable
public class DiscoveryManager : IDiscoveryManager
{
- private TestSessionMessageLogger sessionMessageLogger;
- private ITestPlatformEventSource testPlatformEventSource;
- private IRequestData requestData;
+ private readonly TestSessionMessageLogger sessionMessageLogger;
+ private readonly ITestPlatformEventSource testPlatformEventSource;
+ private readonly IRequestData requestData;
private ITestDiscoveryEventsHandler2 testDiscoveryEventsHandler;
private DiscoveryCriteria discoveryCriteria;
+ private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
///
/// Initializes a new instance of the class.
@@ -109,7 +110,7 @@ public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEve
// If there are sources to discover
if (verifiedExtensionSourceMap.Any())
{
- new DiscovererEnumerator(this.requestData, discoveryResultCache).LoadTests(
+ new DiscovererEnumerator(this.requestData, discoveryResultCache, cancellationTokenSource.Token).LoadTests(
verifiedExtensionSourceMap,
RunSettingsUtilities.CreateAndInitializeRunSettings(discoveryCriteria.RunSettings),
discoveryCriteria.TestCaseFilter,
@@ -138,9 +139,10 @@ public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEve
// Collecting Total Tests Discovered
this.requestData.MetricsCollection.Add(TelemetryDataConstants.TotalTestsDiscovered, totalDiscoveredTestCount);
-
- var discoveryCompleteEventsArgs = new DiscoveryCompleteEventArgs(totalDiscoveredTestCount, false);
- discoveryCompleteEventsArgs.Metrics = this.requestData.MetricsCollection.Metrics;
+ var discoveryCompleteEventsArgs = new DiscoveryCompleteEventArgs(totalDiscoveredTestCount, false)
+ {
+ Metrics = this.requestData.MetricsCollection.Metrics
+ };
eventHandler.HandleDiscoveryComplete(discoveryCompleteEventsArgs, lastChunk);
}
@@ -161,7 +163,7 @@ public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEve
///
public void Abort()
{
- // do nothing for now.
+ this.cancellationTokenSource.Cancel();
}
private void OnReportTestCases(IEnumerable testCases)
diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.Designer.cs
index ee5729186a..29ba479681 100644
--- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.Designer.cs
+++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.Designer.cs
@@ -250,6 +250,15 @@ internal static string StringSeperator {
}
}
+ ///
+ /// Looks up a localized string similar to Discovery of tests cancelled..
+ ///
+ internal static string TestDiscoveryCancelled {
+ get {
+ return ResourceManager.GetString("TestDiscoveryCancelled", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Logging TestHost Diagnostics in file: {0}.
///
diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx
index f23a139ea2..8e51734589 100644
--- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx
+++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx
@@ -195,4 +195,7 @@
No test matches the given testcase filter `{0}` in {1}
+
+ Discovery of tests cancelled.
+
\ No newline at end of file
diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf
index 4b13ac29a5..e9ebcc811b 100644
--- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf
+++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf
@@ -202,6 +202,11 @@
Žádný test neodpovídá danému filtru testovacích případů {0} v: {1}
+
+
+ Discovery of tests cancelled.
+
+