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
Added API to provide mutiple regex patterns for enumerating files. #922
Changes from 3 commits
8cd40b9
3f9f7d6
5a0c3c5
61947c2
1475d89
22b401b
2a4c289
78ac212
aefca03
809354e
b66c255
8288e00
35432f9
08e1ae2
235b9c1
08141e6
c071b7f
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 |
---|---|---|
|
@@ -175,15 +175,17 @@ private void AddExtensionAssemblies(string runSettings) | |
var adapterPath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(customTestAdaptersPath)); | ||
if (!Directory.Exists(adapterPath)) | ||
{ | ||
EqtTrace.Warning(string.Format("AdapterPath Not Found:", adapterPath)); | ||
if (EqtTrace.IsWarningEnabled) | ||
{ | ||
EqtTrace.Warning(string.Format("AdapterPath Not Found:", adapterPath)); | ||
} | ||
|
||
continue; | ||
} | ||
|
||
var extensionAssemblies = new List<string>(this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.TestAdapterRegexPattern, SearchOption.AllDirectories)); | ||
extensionAssemblies.AddRange(this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.TestLoggerRegexPattern, SearchOption.AllDirectories)); | ||
extensionAssemblies.AddRange(this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.RunTimeRegexPattern, SearchOption.AllDirectories)); | ||
extensionAssemblies.AddRange(this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.SettingsProviderRegexPattern, SearchOption.AllDirectories)); | ||
var patterns = new string[] { TestPlatformConstants.TestAdapterRegexPattern, TestPlatformConstants.TestLoggerRegexPattern, TestPlatformConstants.RunTimeRegexPattern, TestPlatformConstants.SettingsProviderRegexPattern }; | ||
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. nit: runtime is one word 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. Most of the patterns are compatible with 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. On measuring perf, it is observed that |
||
|
||
var extensionAssemblies = new List<string>(this.fileHelper.EnumerateFiles(adapterPath, patterns, SearchOption.AllDirectories)); | ||
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. Not sure if the responsibility to combine and create a regex should be with EnumerateFiles. |
||
if (extensionAssemblies.Count > 0) | ||
{ | ||
this.UpdateExtensions(extensionAssemblies, true); | ||
|
@@ -215,7 +217,7 @@ private void AddExtensionAssembliesFromSource(TestRunCriteria testRunCriteria) | |
var sourceDirectory = Path.GetDirectoryName(source); | ||
if (!string.IsNullOrEmpty(sourceDirectory) && this.fileHelper.DirectoryExists(sourceDirectory)) | ||
{ | ||
loggersToUpdate.AddRange(this.fileHelper.EnumerateFiles(sourceDirectory, TestPlatformConstants.TestLoggerRegexPattern, SearchOption.TopDirectoryOnly).ToList()); | ||
loggersToUpdate.AddRange(this.fileHelper.EnumerateFiles(sourceDirectory, TestPlatformConstants.TestLoggerRegexPattern, SearchOption.TopDirectoryOnly)); | ||
} | ||
} | ||
|
||
|
@@ -233,13 +235,9 @@ private static void AddExtensionAssembliesFromExtensionDirectory() | |
{ | ||
var fileHelper = new FileHelper(); | ||
var extensionsFolder = Path.Combine(Path.GetDirectoryName(typeof(TestPlatform).GetTypeInfo().Assembly.Location), "Extensions"); | ||
var defaultExtensionPaths = new List<string>(); | ||
if (fileHelper.DirectoryExists(extensionsFolder)) | ||
{ | ||
var dlls = fileHelper.EnumerateFiles(extensionsFolder, ".*.dll", SearchOption.TopDirectoryOnly); | ||
defaultExtensionPaths.AddRange(dlls); | ||
var exes = fileHelper.EnumerateFiles(extensionsFolder, ".*.exe", SearchOption.TopDirectoryOnly); | ||
defaultExtensionPaths.AddRange(exes); | ||
var defaultExtensionPaths = fileHelper.EnumerateFiles(extensionsFolder, new string[] { ".*.dll", ".*.exe" }, SearchOption.TopDirectoryOnly); | ||
TestPluginCache.Instance.DefaultExtensionPaths = defaultExtensionPaths; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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.TestPlatform.PerformanceTests | ||
{ | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
|
||
using Microsoft.TestPlatform.TestUtilities.PerfInstrumentation; | ||
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class FileHelperTests : PerformanceTestBase | ||
{ | ||
[TestMethod] | ||
public void EnumerateFilesPerfTests() | ||
{ | ||
var fileHelper = new FileHelper(); | ||
var stopwatch = new Stopwatch(); | ||
var adapterPath = Directory.GetCurrentDirectory(); | ||
var patterns = new string[] | ||
{ | ||
".*CoreUtilities.dll", | ||
".*CommunicationUtilities.dll", | ||
".*CrossPlatEngine.dll", | ||
".*TestUtilities.dll" | ||
}; | ||
|
||
stopwatch.Start(); | ||
var extensionAssemblies = | ||
new List<string>( | ||
fileHelper.EnumerateFiles( | ||
adapterPath, | ||
patterns[0], | ||
SearchOption.AllDirectories)); | ||
extensionAssemblies.AddRange( | ||
fileHelper.EnumerateFiles( | ||
adapterPath, | ||
patterns[1], | ||
SearchOption.AllDirectories)); | ||
extensionAssemblies.AddRange( | ||
fileHelper.EnumerateFiles( | ||
adapterPath, | ||
patterns[2], | ||
SearchOption.AllDirectories)); | ||
extensionAssemblies.AddRange( | ||
fileHelper.EnumerateFiles( | ||
adapterPath, | ||
patterns[3], | ||
SearchOption.AllDirectories)); | ||
|
||
stopwatch.Stop(); | ||
var timeForOldApi = stopwatch.ElapsedMilliseconds; | ||
|
||
stopwatch.Restart(); | ||
var extensionAssembliesNew = | ||
new List<string>(fileHelper.EnumerateFiles(adapterPath, patterns, SearchOption.AllDirectories)); | ||
stopwatch.Stop(); | ||
var timeForNewApi = stopwatch.ElapsedMilliseconds; | ||
|
||
Assert.AreEqual(extensionAssemblies.Count, extensionAssembliesNew.Count); | ||
Assert.IsTrue(timeForNewApi < timeForOldApi); | ||
} | ||
} | ||
} |
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.
If all these patterns are known why not Regex.Compile it directly in this class. We will save some time during runtime?