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
Expand Up @@ -50,7 +50,7 @@ public class TestPluginCache
/// <summary>
/// Initializes a new instance of the <see cref="TestPluginCache"/> class.
/// </summary>
protected TestPluginCache()
public TestPluginCache()
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
{
_filterableExtensionPaths = new List<string>();
_unfilterableExtensionPaths = new List<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class InProcDataCollectionExtensionManager

private readonly IDataCollectionSink _inProcDataCollectionSink;
private readonly string? _defaultCodeBase;
private readonly List<string?> _codeBasePaths;
internal readonly HashSet<string?> CodeBasePaths;
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
private readonly IFileHelper _fileHelper;

internal IDictionary<string, IInProcDataCollector> InProcDataCollectors;
Expand Down Expand Up @@ -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?> { _defaultCodeBase };
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
Evangelink marked this conversation as resolved.
Show resolved Hide resolved

// 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
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ public InProcDataCollectionExtensionManagerTests()
_inProcDataCollectionManager = new TestableInProcDataCollectionExtensionManager(_settingsXml, _mockTestEventsPublisher.Object, _defaultCodebase, _testPluginCache, _mockFileHelper.Object);
}

[TestMethod]
public void CheckExtensionPathsDuplicates()
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
{
var testPluginCache = new TestPluginCache();
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
// 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, _defaultCodebase, 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(_defaultCodebase));
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
Assert.IsTrue(inProcDataCollectionExtensionManager.CodeBasePaths.Contains(Path.GetDirectoryName(@"c:\test1\Collector.dll")));
Assert.IsTrue(inProcDataCollectionExtensionManager.CodeBasePaths.Contains(Path.GetDirectoryName(@"c:\test2\Collector.dll")));


}
Evangelink marked this conversation as resolved.
Show resolved Hide resolved


[TestMethod]
public void InProcDataCollectionExtensionManagerShouldLoadsDataCollectorsFromRunSettings()
{
Expand Down