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

Added method to look for new api in fakes datacollector #2339

Merged
merged 31 commits into from
Apr 1, 2020
Merged
Changes from 5 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5f85da9
Added method to look for new api in fakes datacollector
vritant24 Feb 21, 2020
e65d7fd
added check for .net runtime version
vritant24 Feb 21, 2020
18dd277
refactored code
vritant24 Feb 25, 2020
ee33f44
enable new configurator for net core
vritant24 Feb 25, 2020
d443bee
refactored to remove use of out param
vritant24 Mar 3, 2020
e70ea68
Removed Microsoft.VisualStudio.TestPlatform.Fakes from the "Microsoft…
AbhitejJohn Mar 19, 2020
fea6f01
Fixing method resolution.
AbhitejJohn Mar 19, 2020
922340f
updated api call
vritant24 Mar 19, 2020
2dae2fa
fixed pr comments
vritant24 Mar 19, 2020
453dc53
merged conflict
vritant24 Mar 19, 2020
f648531
Fixing build - this doesn't need to be signed.
AbhitejJohn Mar 19, 2020
746bc17
removed obsolete
vritant24 Mar 20, 2020
3b1ba0e
Merge branch 'master' into dev/vrbhardw/fakes_dc_update
AbhitejJohn Mar 20, 2020
482797b
Looks like the signed build has a different way of producing nuget pa…
AbhitejJohn Mar 20, 2020
bb08fb5
Added method to look for new api in fakes datacollector
vritant24 Feb 21, 2020
a2e330a
added check for .net runtime version
vritant24 Feb 21, 2020
4a936e0
refactored code
vritant24 Feb 25, 2020
0474ee0
enable new configurator for net core
vritant24 Feb 25, 2020
611f49e
refactored to remove use of out param
vritant24 Mar 3, 2020
1b16fd1
updated api call
vritant24 Mar 19, 2020
74c4c79
fixed pr comments
vritant24 Mar 19, 2020
33f8e72
Removed Microsoft.VisualStudio.TestPlatform.Fakes from the "Microsoft…
AbhitejJohn Mar 19, 2020
844c6c3
Fixing method resolution.
AbhitejJohn Mar 19, 2020
c8e1ffa
Fixing build - this doesn't need to be signed.
AbhitejJohn Mar 19, 2020
f8b30f1
removed obsolete
vritant24 Mar 20, 2020
a5f78b3
removed system.linq reference:
vritant24 Mar 20, 2020
e2014ba
fixed rebase errors
vritant24 Mar 20, 2020
cc69796
merged remote
vritant24 Mar 20, 2020
8842c0e
Fixing script vars
AbhitejJohn Mar 20, 2020
f87e376
Merge branch 'dev/vrbhardw/fakes_dc_update' of https://github.com/mic…
AbhitejJohn Mar 20, 2020
b051c34
Write value to the correct pipeline variable
nohwnd Mar 20, 2020
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
98 changes: 72 additions & 26 deletions src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Utilities
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
#if NET451
using System.Reflection;
#endif
using System.Xml;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
Expand Down Expand Up @@ -44,12 +42,6 @@ public static string GenerateFakesSettingsForRunConfiguration(string[] sources,
throw new ArgumentNullException(nameof(runSettingsXml));
}

// do not generate fakes for netcore
if (IsNetCoreFramework(runSettingsXml))
{
return runSettingsXml;
}

var doc = new XmlDocument();
using (var xmlReader = XmlReader.Create(
new StringReader(runSettingsXml),
Expand All @@ -58,7 +50,9 @@ public static string GenerateFakesSettingsForRunConfiguration(string[] sources,
doc.Load(xmlReader);
}

return !TryAddFakesDataCollectorSettings(doc, sources) ? runSettingsXml : doc.OuterXml;
var isNetFramework = !IsNetCoreFramework(runSettingsXml);

return !TryAddFakesDataCollectorSettings(doc, sources, isNetFramework) ? runSettingsXml : doc.OuterXml;
}

private static bool IsNetCoreFramework(string runSettingsXml)
Expand All @@ -77,31 +71,59 @@ private static bool IsNetCoreFramework(string runSettingsXml)
/// <returns>true if runSettings was modified; false otherwise.</returns>
private static bool TryAddFakesDataCollectorSettings(
XmlDocument runSettings,
IEnumerable<string> sources)
IEnumerable<string> sources,
bool isNetFramework)
{
// If user provided fakes settings don't do anything
if (XmlRunSettingsUtilities.ContainsDataCollector(runSettings.CreateNavigator(), FakesMetadata.DataCollectorUri))
{
return false;
}

Func<IEnumerable<string>, string> configurator;
// A new Fakes Congigurator API makes the decision to add the right datacollector uri to the configuration
vritant24 marked this conversation as resolved.
Show resolved Hide resolved
// There now exist two data collector URIs to support two different scenarios. The new scanrio involves
// using the CLRIE profiler, and the old involves using the Intellitrace profiler (which isn't supported in
// .NET Core scenarios). The old API still exists for fallback measures.

// fakes supported?
if (!TryGetFakesDataCollectorConfigurator(out configurator))
var newConfigurator = TryGetFakesNewDataCollectorConfigurator();
if (newConfigurator != null)
{
var fakesSettings = newConfigurator(sources, isNetFramework);
XmlRunSettingsUtilities.InsertDataCollectorsNode(runSettings.CreateNavigator(), fakesSettings);
return true;
}

return AddFallbackFakesSettings(runSettings, sources, isNetFramework);
}

private static bool AddFallbackFakesSettings(
XmlDocument runSettings,
IEnumerable<string> sources,
bool isNetFramework)
{

// The fallback settings is for the old implementation of fakes
// that only supports .Net Framework versions
if (!isNetFramework)
{
return false;
}

Func<IEnumerable<string>, string> oldConfigurator = TryGetFakesDataCollectorConfigurator();
if (oldConfigurator == null)
{
return false;
}

// if no fakes, return settings unchanged
var fakesConfiguration = configurator(sources);
var fakesConfiguration = oldConfigurator(sources);
if (fakesConfiguration == null)
{
return false;
}

// integrate fakes settings in configuration
// if the settings don't have any data collector settings, populate with empty settings
// if the settings doesn't have any data collector settings, populate with empty settings
AbhitejJohn marked this conversation as resolved.
Show resolved Hide resolved
EnsureSettingsNode(runSettings, new DataCollectionRunSettings());

// embed fakes settings
Expand All @@ -116,6 +138,7 @@ private static bool TryAddFakesDataCollectorSettings(

fakesSettings.Configuration = doc.DocumentElement;
XmlRunSettingsUtilities.InsertDataCollectorsNode(runSettings.CreateNavigator(), fakesSettings);

return true;
}

Expand All @@ -138,22 +161,20 @@ private static void EnsureSettingsNode(XmlDocument settings, TestRunSettings set
}
}

private static bool TryGetFakesDataCollectorConfigurator(out Func<IEnumerable<string>, string> configurator)
private static Func<IEnumerable<string>, string> TryGetFakesDataCollectorConfigurator()
{
#if NET451
try
{
Assembly assembly = Assembly.Load(FakesConfiguratorAssembly);

var type = assembly?.GetType(ConfiguratorAssemblyQualifiedName, false);
if (type != null)

var method = type?.GetMethod(ConfiguratorMethodName, BindingFlags.Public | BindingFlags.Static);

if (method != null)
{
var method = type.GetMethod(ConfiguratorMethodName, BindingFlags.Public | BindingFlags.Static);
if (method != null)
{
configurator = (Func<IEnumerable<string>, string>)method.CreateDelegate(typeof(Func<IEnumerable<string>, string>));
return true;
}
return (Func<IEnumerable<string>, string>)method.CreateDelegate(typeof(Func<IEnumerable<string>, string>));
}
}
catch (Exception ex)
Expand All @@ -164,8 +185,33 @@ private static bool TryGetFakesDataCollectorConfigurator(out Func<IEnumerable<st
}
}
#endif
configurator = null;
return false;
return null;
}

private static Func<IEnumerable<string>, bool, DataCollectorSettings> TryGetFakesNewDataCollectorConfigurator()
{
try
{
Assembly assembly = Assembly.Load(FakesConfiguratorAssembly);

AbhitejJohn marked this conversation as resolved.
Show resolved Hide resolved
var type = assembly?.GetType(ConfiguratorAssemblyQualifiedName, false);

var method = type?.GetMethod(ConfiguratorMethodName, BindingFlags.Public | BindingFlags.Static);

if (method != null)
{
return (Func<IEnumerable<string>, bool, DataCollectorSettings>)method.CreateDelegate(typeof(Func<IEnumerable<string>, bool, DataCollectorSettings>));
}
}
catch (Exception ex)
{
if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("Failed to create newly implemented Fakes Configurator. Reason:{0} ", ex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this show up in test platform diagnostic logs? Its probably used in some places in this file already but eqttrace logs IIRC are enabled and viewed differently from how we enable TP diagnostic logs in general.

}
}

return null;
}

/// <summary>
Expand Down Expand Up @@ -205,4 +251,4 @@ internal static class FakesMetadata
public const string DataCollectorAssemblyQualifiedName = "Microsoft.VisualStudio.TraceCollector.UnitTestIsolationDataCollector, Microsoft.VisualStudio.TraceCollector, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
}
}
}
}