-
Notifications
You must be signed in to change notification settings - Fork 331
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
Filtering sources based on assembly type #1537
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 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.Common.Interfaces | ||
{ | ||
using Microsoft.VisualStudio.TestPlatform.Common.Utilities; | ||
|
||
/// <summary> | ||
/// Metadata that is available for input test source, e.g. Whether it is native or managed dll, etc.. | ||
/// </summary> | ||
public interface IAssemblyProperties | ||
{ | ||
/// <summary> | ||
/// Determines assembly type from file. | ||
/// </summary> | ||
AssemblyType GetAssemblyType(string filePath); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery | |
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces; | ||
using Microsoft.VisualStudio.TestPlatform.Common.Logging; | ||
using Microsoft.VisualStudio.TestPlatform.Common.Telemetry; | ||
using Microsoft.VisualStudio.TestPlatform.Common.Utilities; | ||
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing; | ||
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
|
@@ -33,6 +34,7 @@ internal class DiscovererEnumerator | |
private DiscoveryResultCache discoveryResultCache; | ||
private ITestPlatformEventSource testPlatformEventSource; | ||
private IRequestData requestData; | ||
private IAssemblyProperties assemblyProperties; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DiscovererEnumerator"/> class. | ||
|
@@ -51,8 +53,22 @@ internal DiscovererEnumerator(IRequestData requestData, | |
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, | ||
DiscoveryResultCache discoveryResultCache, | ||
ITestPlatformEventSource testPlatformEventSource, | ||
IAssemblyProperties assemblyProperties) | ||
{ | ||
this.discoveryResultCache = discoveryResultCache; | ||
this.testPlatformEventSource = testPlatformEventSource; | ||
this.requestData = requestData; | ||
this.assemblyProperties = assemblyProperties; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Discovers tests from the sources. | ||
/// </summary> | ||
|
@@ -89,7 +105,7 @@ private void LoadTestsFromAnExtension(string extensionAssembly, IEnumerable<stri | |
// Stopwatch to collect metrics | ||
var timeStart = DateTime.UtcNow; | ||
|
||
var discovererToSourcesMap = GetDiscovererToSourcesMap(extensionAssembly, sources, logger); | ||
var discovererToSourcesMap = GetDiscovererToSourcesMap(extensionAssembly, sources, logger, this.assemblyProperties); | ||
var totalAdapterLoadTIme = DateTime.UtcNow - timeStart; | ||
|
||
// Collecting Data Point for TimeTaken to Load Adapters | ||
|
@@ -222,7 +238,8 @@ private void SetAdapterLoggingSettings(IMessageLogger messageLogger, IRunSetting | |
internal static Dictionary<LazyExtension<ITestDiscoverer, ITestDiscovererCapabilities>, IEnumerable<string>> GetDiscovererToSourcesMap( | ||
string extensionAssembly, | ||
IEnumerable<string> sources, | ||
IMessageLogger logger) | ||
IMessageLogger logger, | ||
IAssemblyProperties assemblyProperties) | ||
{ | ||
var allDiscoverers = GetDiscoverers(extensionAssembly, throwOnError: true); | ||
|
||
|
@@ -237,14 +254,24 @@ internal static Dictionary<LazyExtension<ITestDiscoverer, ITestDiscovererCapabil | |
return null; | ||
} | ||
|
||
IDictionary<AssemblyType, IEnumerable<string>> assemblyTypeToSoucesMap = null; | ||
var result = new Dictionary<LazyExtension<ITestDiscoverer, ITestDiscovererCapabilities>, IEnumerable<string>>(); | ||
var sourcesForWhichNoDiscovererIsAvailable = new List<string>(sources); | ||
|
||
foreach (var discoverer in allDiscoverers) | ||
{ | ||
var sourcesToCheck = sources; | ||
|
||
if (discoverer.Metadata.AssemblyType == AssemblyType.Native || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a chance discoverer can support both managed and native? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. adapter can't mention both |
||
discoverer.Metadata.AssemblyType == AssemblyType.Managed) | ||
{ | ||
assemblyTypeToSoucesMap = assemblyTypeToSoucesMap ?? GetAssemblyTypeToSoucesMap(sources, assemblyProperties); | ||
sourcesToCheck = assemblyTypeToSoucesMap[AssemblyType.None].Concat(assemblyTypeToSoucesMap[discoverer.Metadata.AssemblyType]); | ||
} | ||
|
||
// Find the sources which this discoverer can look at. | ||
// Based on whether it is registered for a matching file extension or no file extensions at all. | ||
var matchingSources = (from source in sources | ||
var matchingSources = (from source in sourcesToCheck | ||
where | ||
(discoverer.Metadata.FileExtension == null | ||
|| discoverer.Metadata.FileExtension.Contains( | ||
|
@@ -277,6 +304,49 @@ internal static Dictionary<LazyExtension<ITestDiscoverer, ITestDiscovererCapabil | |
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Get assembly type to sources map. | ||
/// </summary> | ||
/// <param name="sources">Sources.</param> | ||
/// <param name="assemblyType">Assembly type.</param> | ||
/// <returns>Sources with mathcing assembly type.</returns> | ||
private static IDictionary<AssemblyType, IEnumerable<string>> GetAssemblyTypeToSoucesMap(IEnumerable<string> sources, IAssemblyProperties assemblyProperties) | ||
{ | ||
var assemblyTypeToSoucesMap = new Dictionary<AssemblyType, IEnumerable<string>>() | ||
{ | ||
{ AssemblyType.Native, new List<string>()}, | ||
{ AssemblyType.Managed, new List<string>()}, | ||
{ AssemblyType.None, new List<string>()} | ||
}; | ||
|
||
if (sources != null && sources.Any()) | ||
{ | ||
foreach (string source in sources) | ||
{ | ||
var sourcesList = IsAssembly(source) ? | ||
assemblyTypeToSoucesMap[assemblyProperties.GetAssemblyType(source)] : | ||
assemblyTypeToSoucesMap[AssemblyType.None]; | ||
|
||
((List<string>)sourcesList).Add(source); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
} | ||
|
||
return assemblyTypeToSoucesMap; | ||
} | ||
|
||
/// <summary> | ||
/// Finds if a file is an assembly or not. | ||
/// </summary> | ||
/// <param name="filePath">File path.</param> | ||
/// <returns>True if file is an assembly.</returns> | ||
private static bool IsAssembly(string filePath) | ||
{ | ||
var fileExtension = Path.GetExtension(filePath); | ||
|
||
return ".dll".Equals(fileExtension, StringComparison.OrdinalIgnoreCase) || | ||
".exe".Equals(fileExtension, StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", | ||
"CA1006:DoNotNestGenericTypesInMemberSignatures")] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
needed a AssemblyProperties
or remove comment.