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

TestPlugin cache refactored. #709

Merged
merged 16 commits into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Resolved conflicts.
  • Loading branch information
Harsh Jain committed Apr 17, 2017
commit 11153a6b479056d86baca491444f57d3d6c3742a
2 changes: 1 addition & 1 deletion scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function Publish-Package
Move-Item $coreCLR20PackageDir\$file $coreCLRExtensionsDir -Force
}

# Note Note: If there are some dependencies for the TestHostRuntimeProvider assemblies, those need to be moved too.
# Note Note: If there are some dependencies for the TestHostRuntimeProvider assemblies, those need to be moved too.
$runtimeproviders = @("Microsoft.TestPlatform.TestHostRuntimeProvider.dll", "Microsoft.TestPlatform.TestHostRuntimeProvider.pdb")
foreach($file in $runtimeproviders) {
Write-Verbose "Move-Item $fullCLRPackageDir\$file $fullCLRExtensionsDir -Force"
Expand Down
27 changes: 19 additions & 8 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCrite
throw new ArgumentNullException(nameof(discoveryCriteria));
}

// Update cache with Extension Folder's files
this.AddExtensionAssemblies(discoveryCriteria.RunSettings);

var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(discoveryCriteria.RunSettings);

testHostManager.Initialize(TestSessionMessageLogger.Instance, discoveryCriteria.RunSettings);

var discoveryManager = this.TestEngine.GetDiscoveryManager(testHostManager, discoveryCriteria, protocolConfig);
discoveryManager.Initialize();

Expand All @@ -111,7 +111,6 @@ public ITestRunRequest CreateTestRunRequest(TestRunCriteria testRunCriteria, Pro
throw new ArgumentNullException(nameof(testRunCriteria));
}

// Update cache with Extension Folder's files
this.AddExtensionAssemblies(testRunCriteria.TestRunSettings);

var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings);
Expand Down Expand Up @@ -147,6 +146,19 @@ public void Dispose()
throw new NotImplementedException();
}

/// <summary>
/// The initialize.
/// </summary>
/// <param name="pathToAdditionalExtensions"> The path to additional extensions. </param>
/// <param name="loadOnlyWellKnownExtensions"> The load only well known extensions. </param>
/// <param name="forceX86Discoverer"> The force x86 discoverer. </param>
public void Initialize(IEnumerable<string> pathToAdditionalExtensions, bool loadOnlyWellKnownExtensions, bool forceX86Discoverer)
{
// TODO: ForceX86Discoverer options
this.TestEngine.GetExtensionManager()
.UseAdditionalExtensions(pathToAdditionalExtensions, loadOnlyWellKnownExtensions);
}

/// <summary>
/// The update extensions.
/// </summary>
Expand Down Expand Up @@ -186,7 +198,7 @@ private void AddExtensionAssemblies(string runSettings)

if (adapterFiles.Count > 0)
{
this.UpdateExtensions(extensionAssemblies, true);
this.UpdateExtensions(adapterFiles, true);
}
}
}
Expand All @@ -200,16 +212,15 @@ private void AddExtensionAssemblies(string runSettings)
/// </param>
private void AddExtensionAssembliesFromSource(TestRunCriteria testRunCriteria)
{
// Find source directories
var sources = testRunCriteria.Sources;
IEnumerable<string> sources = testRunCriteria.Sources;
if (testRunCriteria.HasSpecificTests)
{
// If the test execution is with a test filter, group them by sources
sources = testRunCriteria.Tests.Select(tc => tc.Source).Distinct();
}

// Currently we support discovering loggers only from Source directory
var loggersToUpdate = new List<string>();
List<string> loggersToUpdate = new List<string>();

foreach (var source in sources)
{
var sourceDirectory = Path.GetDirectoryName(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class TestPluginCache

private static TestPluginCache instance;

private List<string> defaultExtensionPaths = new List<string>();

#endregion

#region Constructor
Expand Down Expand Up @@ -308,6 +310,21 @@ public void UpdateExtensions(IEnumerable<string> additionalExtensionsPath, bool

#region Utility methods

internal IEnumerable<string> DefaultExtensionPaths
{
get
{
return this.defaultExtensionPaths;
}
set
{
if (value != null)
{
this.defaultExtensionPaths.AddRange(value);
}
}
}

/// <summary>
/// Checks if a directory exists
/// </summary>
Expand Down Expand Up @@ -525,7 +542,7 @@ private Assembly CurrentDomainAssemblyResolve(AssemblyLoadContext loadContext, A
}
}
}

/// <summary>
/// Log the extensions
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
Expand Down Expand Up @@ -119,7 +121,12 @@ public override void Close()
private void InitializeExtensions(IEnumerable<string> sources)
{
var sourceList = sources.ToList();
var extensions = this.testHostManager.GetTestPlatformExtensions(sourceList, TestPluginCache.Instance.PathToExtensions);
var extensions = this.testHostManager.GetTestPlatformExtensions(sourceList, TestPluginCache.Instance.DefaultExtensionPaths).ToList();
if (TestPluginCache.Instance.PathToExtensions != null)
{
var regex = new Regex(TestPlatformConstants.TestAdapterRegexPattern, RegexOptions.IgnoreCase);
extensions.AddRange(TestPluginCache.Instance.PathToExtensions.Where(ext => regex.IsMatch(ext)));
}

// Only send this if needed.
if (extensions.Count() > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,12 @@ public void Abort()
private void InitializeExtensions(IEnumerable<string> sources)
{
var sourceList = sources.ToList();
var extensions = this.testHostManager.GetTestPlatformExtensions(
sourceList,
TestPluginCache.Instance.PathToExtensions);
var extensions = this.testHostManager.GetTestPlatformExtensions(sourceList, TestPluginCache.Instance.DefaultExtensionPaths).ToList();
if (TestPluginCache.Instance.PathToExtensions != null)
{
var regex = new Regex(TestPlatformConstants.TestAdapterRegexPattern, RegexOptions.IgnoreCase);
extensions.AddRange(TestPluginCache.Instance.PathToExtensions.Where(ext => (regex.IsMatch(ext))));
}

// Only send this if needed.
if (extensions.Count() > 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TestPlatformRoot Condition="$(TestPlatformRoot) == ''">..\..\</TestPlatformRoot>
</PropertyGroup>
Expand Down
28 changes: 3 additions & 25 deletions src/vstest.console/CommandLine/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,16 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors;
using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities;
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities;
using Microsoft.VisualStudio.TestPlatform.Common;

using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
Expand Down Expand Up @@ -201,9 +198,6 @@ private int GetArgumentProcessors(string[] args, out List<IArgumentProcessor> pr
// Initialize Runsettings with defaults
RunSettingsManager.Instance.AddDefaultRunSettings();

// Default extensions path is required because RunTests argument processor has dependency on TestEngine, which further has dependency on TestRuntimeExtensionManager, which currently loads runtimeprovider from extensions folder.
this.UpdateDefaultExtensions();

// Ensure we have an action argument.
this.EnsureActionArgumentIsPresent(processors, processorFactory);

Expand Down Expand Up @@ -348,22 +342,6 @@ private void PrintSplashScreen()
this.Output.WriteLine(string.Empty, OutputLevel.Information);
}

private void UpdateDefaultExtensions()
{
var fileHelper = new FileHelper();
var extensionsFolder = Path.Combine(Path.GetDirectoryName(typeof(Executor).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);

TestPluginCache.Instance.UpdateExtensions(defaultExtensionPaths, true);
}
}

#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,6 @@ public void GetDefaultResolutionPathsShouldReturnAdditionalExtensionPathsDirecto
CollectionAssert.AreEqual(expectedExtensions, resolutionPaths.ToList());
}

[TestMethod]
public void GetDefaultResolutionPathsShouldReturnDirectoryFromDefaultExtensionsPath()
{
// Setup the testable instance.
TestPluginCache.Instance = this.testablePluginCache;

var defaultExtensionsFile = typeof(TestPluginCache).GetTypeInfo().Assembly.Location;
this.testablePluginCache.DefaultExtensionPaths = new List<string>() { defaultExtensionsFile };

var resolutionPaths = TestPluginCache.Instance.GetDefaultResolutionPaths();

var currentDirectory = Path.GetDirectoryName(typeof(TestPluginCache).GetTypeInfo().Assembly.Location);

Assert.IsNotNull(resolutionPaths);
CollectionAssert.AreEqual(new List<string> { currentDirectory }, resolutionPaths.ToList());
}

#endregion

#region GetResolutionPaths tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void InitializeShouldInitializeExtensionsIfPresent()

try
{
var extensions = new[] { "c:\\e1.TestAdapter.dll", "c:\\e2.TestAdapter.dll" };
var extensions = new[] { "c:\\e1.dll", "c:\\e2.dll" };

// Setup Mocks.
TestPluginCacheTests.SetupMockAdditionalPathExtensions(extensions);
Expand All @@ -94,13 +94,13 @@ public void InitializeShouldQueryTestHostManagerForExtensions()
TestPluginCache.Instance = null;
try
{
TestPluginCacheTests.SetupMockAdditionalPathExtensions(new[] { "c:\\e1.TestAdapter.dll" });
TestPluginCacheTests.SetupMockAdditionalPathExtensions(new[] { "c:\\e1.dll" });
this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);
this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>())).Returns(new[] { "he1.dll", "c:\\e1.dll" });

this.testDiscoveryManager.Initialize();

this.mockRequestSender.Verify(s => s.InitializeDiscovery(new[] { "he1.dll", "c:\\e1.TestAdapter.dll" }, true), Times.Once);
this.mockRequestSender.Verify(s => s.InitializeDiscovery(new[] { "he1.dll", "c:\\e1.dll" }, true), Times.Once);
}
finally
{
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.