Skip to content

Commit

Permalink
Loading extensions should not fail on any faulty extension (#854)
Browse files Browse the repository at this point in the history
* Loading extensions should not fail on any faulty extension

* nit fix

* Create failure in Unittests in different way
  • Loading branch information
smadala authored Jun 20, 2017
1 parent cdcdf90 commit 8451cd4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class TestPluginDiscoverer
"MICROSOFT.VISUALSTUDIO.TESTPLATFORM.OBJECTMODEL.DLL",
"VSTEST_EXECUTIONENGINE_PLATFORMBRIDGE.DLL",
"VSTEST_EXECUTIONENGINE_PLATFORMBRIDGE.WINMD",
"VSTEST.EXECUTIONENGINE.WINDOWSPHONE.DLL",
"VSTEST.EXECUTIONENGINE.WINDOWSPHONE.DLL",
"MICROSOFT.CSHARP.DLL",
"MICROSOFT.VISUALBASIC.DLL",
"CLRCOMPRESSION.DLL",
Expand All @@ -51,7 +51,7 @@ internal class TestPluginDiscoverer
/// The path to the extensions.
/// </param>
/// <param name="loadOnlyWellKnownExtensions">
/// Should load only well known extensions or all.
/// Should load only well known extensions or all.
/// </param>
/// <returns>
/// The <see cref="Dictionary"/>` of assembly qualified name and testplugin information.
Expand All @@ -73,8 +73,8 @@ public Dictionary<string, TPluginInfo> GetTestExtensionsInformation<TPluginInfo,
fileSearchTask.Wait();

var binaries = fileSearchTask.Result.Where(storageFile =>
(storageFile.Name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)

(storageFile.Name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)
|| storageFile.Name.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
&& !storageFile.Name.StartsWith(SYSTEM_ASSEMBLY_PREFIX, StringComparison.OrdinalIgnoreCase)
&& !platformAssemblies.Contains(storageFile.Name.ToUpperInvariant())
Expand Down Expand Up @@ -142,13 +142,17 @@ private void GetTestExtensionsFromFiles<TPluginInfo, TExtension>(
// Scan each of the files for data extensions.
foreach (var file in files)
{
Assembly assembly = null;
try
{
Assembly assembly = null;
var assemblyName = Path.GetFileNameWithoutExtension(file);
assembly = Assembly.Load(new AssemblyName(assemblyName));
if (assembly != null)
{
this.GetTestExtensionsFromAssembly<TPluginInfo, TExtension>(assembly, pluginInfos);
}

// Check whether this assembly is known or not.
// Check whether this assembly is known or not.
//if (loadOnlyWellKnownExtensions && assembly != null)
//{
// var extensionAssemblyName = new AssemblyName(assembly.FullName);
Expand All @@ -161,14 +165,9 @@ private void GetTestExtensionsFromFiles<TPluginInfo, TExtension>(
}
catch (Exception e)
{
EqtTrace.Warning("TestPluginDiscoverer: Failed to load file '{0}'. Skipping test extension scan for this file. Error: {1}", file, e.ToString());
EqtTrace.Warning("TestPluginDiscoverer: Failed to load extensions from file '{0}'. Skipping test extension scan for this file. Error: {1}", file, e);
continue;
}

if (assembly != null)
{
this.GetTestExtensionsFromAssembly<TPluginInfo, TExtension>(assembly, pluginInfos);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace TestPlatform.Common.UnitTests.ExtensionFramework
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using MSTest.TestFramework.AssertExtensions;

[TestClass]
public class TestPluginDiscovererTests
{
Expand Down Expand Up @@ -110,6 +112,19 @@ public void GetTestExtensionsInformationShouldReturnSettingsProviderExtensions()
Assert.IsTrue(testExtensions.ContainsKey(pluginInformation2.IdentifierData));
}

[TestMethod]
public void GetTestExtensionsInformationShouldNotAbortOnFaultyExtensions()
{
var pathToExtensions = new List<string>
{
typeof(TestPluginDiscovererTests).GetTypeInfo().Assembly.Location,
};

var testExtensions = this.testPluginDiscoverer.GetTestExtensionsInformation<FaultyTestExecutorPluginInformation, ITestExecutor>(pathToExtensions, loadOnlyWellKnownExtensions: true);

Assert.That.DoesNotThrow(() =>this.testPluginDiscoverer.GetTestExtensionsInformation<FaultyTestExecutorPluginInformation, ITestExecutor>(pathToExtensions, loadOnlyWellKnownExtensions: true));
}

#region implementations

#region Discoverers
Expand Down Expand Up @@ -263,6 +278,17 @@ public void Load(XmlReader reader)

#endregion

internal class FaultyTestExecutorPluginInformation : TestExtensionPluginInformation
{
/// <summary>
/// Default constructor
/// </summary>
/// <param name="type"> The Type. </param>
public FaultyTestExecutorPluginInformation(Type type): base(type)
{
throw new Exception();
}
}
#endregion
}
}

0 comments on commit 8451cd4

Please sign in to comment.