-
Notifications
You must be signed in to change notification settings - Fork 341
Added method to look for new api in fakes datacollector #2339
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
Merged
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 e65d7fd
added check for .net runtime version
vritant24 18dd277
refactored code
vritant24 ee33f44
enable new configurator for net core
vritant24 d443bee
refactored to remove use of out param
vritant24 e70ea68
Removed Microsoft.VisualStudio.TestPlatform.Fakes from the "Microsoft…
AbhitejJohn fea6f01
Fixing method resolution.
AbhitejJohn 922340f
updated api call
vritant24 2dae2fa
fixed pr comments
vritant24 453dc53
merged conflict
vritant24 f648531
Fixing build - this doesn't need to be signed.
AbhitejJohn 746bc17
removed obsolete
vritant24 3b1ba0e
Merge branch 'master' into dev/vrbhardw/fakes_dc_update
AbhitejJohn 482797b
Looks like the signed build has a different way of producing nuget pa…
AbhitejJohn bb08fb5
Added method to look for new api in fakes datacollector
vritant24 a2e330a
added check for .net runtime version
vritant24 4a936e0
refactored code
vritant24 0474ee0
enable new configurator for net core
vritant24 611f49e
refactored to remove use of out param
vritant24 1b16fd1
updated api call
vritant24 74c4c79
fixed pr comments
vritant24 33f8e72
Removed Microsoft.VisualStudio.TestPlatform.Fakes from the "Microsoft…
AbhitejJohn 844c6c3
Fixing method resolution.
AbhitejJohn c8e1ffa
Fixing build - this doesn't need to be signed.
AbhitejJohn f8b30f1
removed obsolete
vritant24 a5f78b3
removed system.linq reference:
vritant24 e2014ba
fixed rebase errors
vritant24 cc69796
merged remote
vritant24 8842c0e
Fixing script vars
AbhitejJohn f87e376
Merge branch 'dev/vrbhardw/fakes_dc_update' of https://github.com/mic…
AbhitejJohn b051c34
Write value to the correct pipeline variable
nohwnd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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), | ||
|
|
@@ -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) | ||
|
|
@@ -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 | ||
| // 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.
Outdated
Show resolved
Hide resolved
|
||
| EnsureSettingsNode(runSettings, new DataCollectionRunSettings()); | ||
|
|
||
| // embed fakes settings | ||
|
|
@@ -116,6 +138,7 @@ private static bool TryAddFakesDataCollectorSettings( | |
|
|
||
| fakesSettings.Configuration = doc.DocumentElement; | ||
| XmlRunSettingsUtilities.InsertDataCollectorsNode(runSettings.CreateNavigator(), fakesSettings); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -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) | ||
|
|
@@ -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.
Outdated
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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
|
@@ -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"; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.