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

fixed paths duplicates #3907

Merged
merged 12 commits into from
Aug 1, 2022
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ internal class InProcDataCollectionExtensionManager

private readonly IDataCollectionSink _inProcDataCollectionSink;
private readonly string? _defaultCodeBase;
private readonly List<string?> _codeBasePaths;
internal /* for testing purposes */ readonly HashSet<string?> CodeBasePaths;
private readonly IFileHelper _fileHelper;

internal IDictionary<string, IInProcDataCollector> InProcDataCollectors;
@@ -61,13 +61,13 @@ protected InProcDataCollectionExtensionManager(string? runSettings, ITestEventsP
_inProcDataCollectionSink = new InProcDataCollectionSink();
_defaultCodeBase = defaultCodeBase;
_fileHelper = fileHelper;
_codeBasePaths = new List<string?> { _defaultCodeBase };
CodeBasePaths = new HashSet<string?>(StringComparer.OrdinalIgnoreCase) { _defaultCodeBase };

// Get Datacollector code base paths from test plugin cache
var extensionPaths = testPluginCache.GetExtensionPaths(DataCollectorEndsWithPattern);
foreach (var extensionPath in extensionPaths)
{
_codeBasePaths.Add(Path.GetDirectoryName(extensionPath)!);
CodeBasePaths.Add(Path.GetDirectoryName(extensionPath)!);
}

// Initialize InProcDataCollectors
@@ -248,7 +248,7 @@ private string GetCodebase(string codeBase)
return codeBase;
}

foreach (var extensionPath in _codeBasePaths)
foreach (var extensionPath in CodeBasePaths)
{
if (extensionPath is null)
{
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
using System.Reflection;
using System.Xml;

using Microsoft.TestPlatform.TestUtilities;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces;
@@ -53,6 +54,24 @@ public InProcDataCollectionExtensionManagerTests()
_inProcDataCollectionManager = new TestableInProcDataCollectionExtensionManager(_settingsXml, _mockTestEventsPublisher.Object, _defaultCodebase, _testPluginCache, _mockFileHelper.Object);
}

[TestMethod]
public void CodeBasePathsAreDeduplicatedWithCaseIgnoring()
{
var testPluginCache = new TestableTestPluginCache();
// the boolean argument refers to adding the paths to which list(we have two lists)and the duplicate happened when we merged the two lists and they had the same path
testPluginCache.UpdateExtensions(new List<string> { @"C:\TEST1\Collector.dll" }, false);
testPluginCache.UpdateExtensions(new List<string> { @"c:\test1\Collector.dll", @"c:\test2\Collector.dll" }, true);
Evangelink marked this conversation as resolved.
Show resolved Hide resolved

var inProcDataCollectionExtensionManager = new TestableInProcDataCollectionExtensionManager(_settingsXml, _mockTestEventsPublisher.Object, null, testPluginCache, _mockFileHelper.Object);

Assert.AreEqual(3, inProcDataCollectionExtensionManager.CodeBasePaths.Count); // "CodeBasePaths" contains the two extensions(after removing duplicates) and the "_defaultCodebase"

Assert.IsTrue(inProcDataCollectionExtensionManager.CodeBasePaths.Contains(null));
Assert.IsTrue(inProcDataCollectionExtensionManager.CodeBasePaths.Contains(Path.GetDirectoryName(@"c:\test1\Collector.dll")));
Assert.IsTrue(inProcDataCollectionExtensionManager.CodeBasePaths.Contains(Path.GetDirectoryName(@"c:\test2\Collector.dll")));
}


[TestMethod]
public void InProcDataCollectionExtensionManagerShouldLoadsDataCollectorsFromRunSettings()
{