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

Test adapter loading strategy #3380

Merged
merged 10 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TestPlatform.sln
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AttachVS", "src\AttachVS\At
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "playground", "playground", "{6CE2F530-582B-4695-A209-41065E103426}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
playground\README.md = playground\README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestPlatform.Playground", "playground\TestPlatform.Playground\TestPlatform.Playground.csproj", "{545A88D3-1AE2-4D39-9B7C-C691768AD17F}"
Expand Down
283 changes: 180 additions & 103 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected DataCollectorExtensionManager(
/// </returns>
public static DataCollectorExtensionManager Create(IMessageLogger messageLogger)
{
TestPluginManager.Instance.GetSpecificTestExtensions<DataCollectorConfig, DataCollector, IDataCollectorCapabilities, DataCollectorMetadata>(
TestPluginManager.GetSpecificTestExtensions<DataCollectorConfig, DataCollector, IDataCollectorCapabilities, DataCollectorMetadata>(
TestPlatformConstants.DataCollectorEndsWithPattern,
out var unfilteredTestExtensions,
out var filteredTestExtensions);
Expand All @@ -78,7 +78,7 @@ public static DataCollectorExtensionManager Create(IMessageLogger messageLogger)
/// </returns>
public static DataCollectorExtensionManager Create(string extensionAssemblyFilePath, bool skipCache, IMessageLogger messageLogger)
{
TestPluginManager.Instance.GetTestExtensions<DataCollectorConfig, DataCollector, IDataCollectorCapabilities, DataCollectorMetadata>(
TestPluginManager.GetTestExtensions<DataCollectorConfig, DataCollector, IDataCollectorCapabilities, DataCollectorMetadata>(
extensionAssemblyFilePath,
out var unfilteredTestExtensions,
out var filteredTestExtensions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ public static TestDiscoveryExtensionManager Create()
if (s_testDiscoveryExtensionManager == null)
{

TestPluginManager.Instance
.GetSpecificTestExtensions<TestDiscovererPluginInformation, ITestDiscoverer, ITestDiscovererCapabilities, TestDiscovererMetadata>(
TestPluginManager.GetSpecificTestExtensions<TestDiscovererPluginInformation, ITestDiscoverer, ITestDiscovererCapabilities, TestDiscovererMetadata>(
TestPlatformConstants.TestAdapterEndsWithPattern,
out var unfilteredTestExtensions,
out var testExtensions);
Expand All @@ -90,8 +89,7 @@ public static TestDiscoveryExtensionManager Create()
public static TestDiscoveryExtensionManager GetDiscoveryExtensionManager(string extensionAssembly)
{

TestPluginManager.Instance
.GetTestExtensions<TestDiscovererPluginInformation, ITestDiscoverer, ITestDiscovererCapabilities, TestDiscovererMetadata>(
TestPluginManager.GetTestExtensions<TestDiscovererPluginInformation, ITestDiscoverer, ITestDiscovererCapabilities, TestDiscovererMetadata>(
extensionAssembly,
out var unfilteredTestExtensions,
out var testExtensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,13 @@ internal static TestExecutorExtensionManager Create()
{

// Get all extensions for ITestExecutor.
TestPluginManager.Instance
.GetSpecificTestExtensions<TestExecutorPluginInformation, ITestExecutor, ITestExecutorCapabilities, TestExecutorMetadata>(
TestPluginManager.GetSpecificTestExtensions<TestExecutorPluginInformation, ITestExecutor, ITestExecutorCapabilities, TestExecutorMetadata>(
TestPlatformConstants.TestAdapterEndsWithPattern,
out var unfilteredTestExtensions1,
out var testExtensions1);

// Get all extensions for ITestExecutor2.
TestPluginManager.Instance
.GetSpecificTestExtensions<TestExecutorPluginInformation2, ITestExecutor2, ITestExecutorCapabilities, TestExecutorMetadata>(
TestPluginManager.GetSpecificTestExtensions<TestExecutorPluginInformation2, ITestExecutor2, ITestExecutorCapabilities, TestExecutorMetadata>(
TestPlatformConstants.TestAdapterEndsWithPattern,
out var unfilteredTestExtensions2,
out var testExtensions2);
Expand Down Expand Up @@ -152,15 +150,13 @@ internal static TestExecutorExtensionManager GetExecutionExtensionManager(string
{

// Get all extensions for ITestExecutor.
TestPluginManager.Instance
.GetTestExtensions<TestExecutorPluginInformation, ITestExecutor, ITestExecutorCapabilities, TestExecutorMetadata>(
TestPluginManager.GetTestExtensions<TestExecutorPluginInformation, ITestExecutor, ITestExecutorCapabilities, TestExecutorMetadata>(
extensionAssembly,
out var unfilteredTestExtensions1,
out var testExtensions1);

// Get all extensions for ITestExecutor2.
TestPluginManager.Instance
.GetTestExtensions<TestExecutorPluginInformation2, ITestExecutor2, ITestExecutorCapabilities, TestExecutorMetadata>(
TestPluginManager.GetTestExtensions<TestExecutorPluginInformation2, ITestExecutor2, ITestExecutorCapabilities, TestExecutorMetadata>(
extensionAssembly,
out var unfilteredTestExtensions2,
out var testExtensions2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public LazyExtension<TExtension, TMetadata> TryGetTestExtension(string extension
break;
}
}

return testExtension;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected TestLoggerExtensionManager(
public static TestLoggerExtensionManager Create(IMessageLogger messageLogger)
{

TestPluginManager.Instance.GetSpecificTestExtensions<TestLoggerPluginInformation, ITestLogger, ITestLoggerCapabilities, TestLoggerMetadata>(
TestPluginManager.GetSpecificTestExtensions<TestLoggerPluginInformation, ITestLogger, ITestLoggerCapabilities, TestLoggerMetadata>(
TestPlatformConstants.TestLoggerEndsWithPattern,
out IEnumerable<LazyExtension<ITestLogger, Dictionary<string, object>>> unfilteredTestExtensions,
out IEnumerable<LazyExtension<ITestLogger, ITestLoggerCapabilities>> filteredTestExtensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ public static T CreateTestExtension<T>(Type extensionType!!)
/// <param name="filtered">
/// Receives test extensions filtered by Identifier data
/// </param>
public void GetSpecificTestExtensions<TPluginInfo, TExtension, IMetadata, TMetadata>(
public static void GetSpecificTestExtensions<TPluginInfo, TExtension, IMetadata, TMetadata>(
string endsWithPattern,
out IEnumerable<LazyExtension<TExtension, Dictionary<string, object>>> unfiltered,
out IEnumerable<LazyExtension<TExtension, IMetadata>> filtered) where TMetadata : IMetadata where TPluginInfo : TestPluginInformation
{
var extensions = TestPluginCache.Instance.DiscoverTestExtensions<TPluginInfo, TExtension>(endsWithPattern);
GetExtensions<TPluginInfo, TExtension, IMetadata, TMetadata>(extensions, out unfiltered, out filtered);
TestPluginManager.GetExtensions<TPluginInfo, TExtension, IMetadata, TMetadata>(extensions, out unfiltered, out filtered);
}

/// <summary>
Expand Down Expand Up @@ -142,14 +142,14 @@ public void GetSpecificTestExtensions<TPluginInfo, TExtension, IMetadata, TMetad
/// <param name="skipCache">
/// Skip the extensions cache.
/// </param>
public void GetTestExtensions<TPluginInfo, TExtension, IMetadata, TMetadata>(
public static void GetTestExtensions<TPluginInfo, TExtension, IMetadata, TMetadata>(
string extensionAssembly,
out IEnumerable<LazyExtension<TExtension, Dictionary<string, object>>> unfiltered,
out IEnumerable<LazyExtension<TExtension, IMetadata>> filtered,
bool skipCache = false) where TMetadata : IMetadata where TPluginInfo : TestPluginInformation
{
var extensions = TestPluginCache.Instance.GetTestExtensions<TPluginInfo, TExtension>(extensionAssembly, skipCache);
GetExtensions<TPluginInfo, TExtension, IMetadata, TMetadata>(extensions, out unfiltered, out filtered);
TestPluginManager.GetExtensions<TPluginInfo, TExtension, IMetadata, TMetadata>(extensions, out unfiltered, out filtered);
}

/// <summary>
Expand All @@ -158,7 +158,7 @@ public void GetTestExtensions<TPluginInfo, TExtension, IMetadata, TMetadata>(
/// <typeparam name="T"> Type of TestPluginIInformation. </typeparam>
/// <param name="dictionary"> The dictionary containing plugin identifier data and its info. </param>
/// <returns> Collection of test plugins information </returns>
private IEnumerable<TestPluginInformation> GetValuesFromDictionary<T>(Dictionary<string, T> dictionary) where T : TestPluginInformation
private static IEnumerable<TestPluginInformation> GetValuesFromDictionary<T>(Dictionary<string, T> dictionary) where T : TestPluginInformation
{
var values = new List<TestPluginInformation>();

Expand Down Expand Up @@ -193,15 +193,15 @@ private IEnumerable<TestPluginInformation> GetValuesFromDictionary<T>(Dictionary
/// <param name="filtered">
/// Receives test extensions filtered by Identifier data
/// </param>
private void GetExtensions<TPluginInfo, TExtension, IMetadata, TMetadata>(
private static void GetExtensions<TPluginInfo, TExtension, IMetadata, TMetadata>(
Dictionary<string, TPluginInfo> testPluginInfo,
out IEnumerable<LazyExtension<TExtension, Dictionary<string, object>>> unfiltered,
out IEnumerable<LazyExtension<TExtension, IMetadata>> filtered) where TMetadata : IMetadata where TPluginInfo : TestPluginInformation
{
var unfilteredExtensions = new List<LazyExtension<TExtension, Dictionary<string, object>>>();
var filteredExtensions = new List<LazyExtension<TExtension, IMetadata>>();

var testPlugins = GetValuesFromDictionary(testPluginInfo);
var testPlugins = TestPluginManager.GetValuesFromDictionary(testPluginInfo);
foreach (var plugin in testPlugins)
{
if (!string.IsNullOrEmpty(plugin.IdentifierData))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected TestRuntimeExtensionManager(
/// </returns>
public static TestRuntimeExtensionManager Create(IMessageLogger messageLogger)
{
TestPluginManager.Instance.GetSpecificTestExtensions<TestRuntimePluginInformation, ITestRuntimeProvider, ITestRuntimeCapabilities, TestRuntimeMetadata>(
TestPluginManager.GetSpecificTestExtensions<TestRuntimePluginInformation, ITestRuntimeProvider, ITestRuntimeCapabilities, TestRuntimeMetadata>(
TestPlatformConstants.RunTimeEndsWithPattern,
out IEnumerable<LazyExtension<ITestRuntimeProvider, Dictionary<string, object>>> unfilteredTestExtensions,
out IEnumerable<LazyExtension<ITestRuntimeProvider, ITestRuntimeCapabilities>> filteredTestExtensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ public static SettingsProviderExtensionManager Create()
if (s_settingsProviderExtensionManager == null)
{

TestPluginManager.Instance
.GetSpecificTestExtensions<TestSettingsProviderPluginInformation, ISettingsProvider, ISettingsProviderCapabilities, TestSettingsProviderMetadata>(
TestPluginManager.GetSpecificTestExtensions<TestSettingsProviderPluginInformation, ISettingsProvider, ISettingsProviderCapabilities, TestSettingsProviderMetadata>(
TestPlatformConstants.TestAdapterEndsWithPattern,
out var unfilteredTestExtensions,
out var testExtensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,15 @@ public static IEnumerable<string> GetTestAdaptersPaths(string runSettings)
return testAdaptersPaths;
}

/// <summary>
/// Gets the test adapter loading strategy
/// </summary>
/// <param name="runSettings">Test run settings</param>
/// <returns>Test adapter loading strategy</returns>
internal static TestAdapterLoadingStrategy GetLoadingStrategy(string runSettings)
{
var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runSettings);

return runConfiguration.TestAdapterLoadingStrategy;
}
}
3 changes: 3 additions & 0 deletions src/Microsoft.TestPlatform.ObjectModel/Friends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
[assembly: InternalsVisibleTo("Microsoft.VisualStudio.TestPlatform.Extensions.MSPhoneAdapter, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("datacollector, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.VisualStudio.TestPlatform.Common, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("vstest.console, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.VisualStudio.TestPlatform.Client, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]

[assembly: InternalsVisibleTo("Microsoft.TestPlatform.ObjectModel.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("datacollector.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.Extensions.EventLogCollector.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.ObjectModel.ManagedNameUtilities.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("vstest.console.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ public bool DisableAppDomain
}
}

/// <summary>
/// Gets or sets the test adapter loading strategy.
/// </summary>
internal TestAdapterLoadingStrategy TestAdapterLoadingStrategy { get; set; }

/// <summary>
/// Gets a value indicating whether parallelism needs to be disabled by the adapters.
/// </summary>
Expand Down Expand Up @@ -323,11 +328,7 @@ public string TestAdaptersPaths
/// Gets or sets the execution thread apartment state.
/// </summary>
[CLSCompliant(false)]
public PlatformApartmentState ExecutionThreadApartmentState
{
get;
set;
}
public PlatformApartmentState ExecutionThreadApartmentState { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to treat the errors from test adapters as warnings.
Expand Down Expand Up @@ -501,6 +502,13 @@ public override XmlElement ToXml()
root.AppendChild(testAdaptersPaths);
}

if (this.TestAdapterLoadingStrategy != TestAdapterLoadingStrategy.Default)
{
XmlElement adapterLoadingStrategy = doc.CreateElement("TestAdapterLoadingStrategy");
adapterLoadingStrategy.InnerXml = this.TestAdapterLoadingStrategy.ToString();
root.AppendChild(adapterLoadingStrategy);
}

XmlElement treatTestAdapterErrorsAsWarnings = doc.CreateElement("TreatTestAdapterErrorsAsWarnings");
treatTestAdapterErrorsAsWarnings.InnerXml = TreatTestAdapterErrorsAsWarnings.ToString();
root.AppendChild(treatTestAdapterErrorsAsWarnings);
Expand Down Expand Up @@ -761,6 +769,21 @@ public static RunConfiguration FromXml(XmlReader reader)
runConfiguration.TestAdaptersPaths = reader.ReadElementContentAsString();
break;

case "TestAdapterLoadingStrategy":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
value = reader.ReadElementContentAsString();
if (Enum.TryParse<TestAdapterLoadingStrategy>(value, out var loadingStrategy))
{
runConfiguration.TestAdapterLoadingStrategy = loadingStrategy;
}
else
{
throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
}

break;

case "TreatTestAdapterErrorsAsWarnings":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
bool treatTestAdapterErrorsAsWarnings = false;
Expand Down
Loading