-
Notifications
You must be signed in to change notification settings - Fork 145
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
[CIVisibility] TestPlatform AssemblyResolver .ctor integration #5088
Merged
tonyredondo
merged 4 commits into
master
from
tony/testplatform-assemblyresolver-ctor-integration
Jan 19, 2024
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
This file contains 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
This file contains 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
85 changes: 85 additions & 0 deletions
85
.../Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/AssemblyResolverCtorIntegration.cs
This file contains 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// <copyright file="AssemblyResolverCtorIntegration.cs" company="Datadog"> | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
// </copyright> | ||
#nullable enable | ||
|
||
using System; | ||
using System.ComponentModel; | ||
using System.Threading.Tasks; | ||
using Datadog.Trace.ClrProfiler.CallTarget; | ||
|
||
namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing; | ||
|
||
/// <summary> | ||
/// System.Void Microsoft.VisualStudio.TestPlatform.Common.Utilities.AssemblyResolver::.ctor(System.Collections.Generic.IEnumerable`1[System.String]) calltarget instrumentation | ||
/// </summary> | ||
[InstrumentMethod( | ||
AssemblyName = "Microsoft.VisualStudio.TestPlatform.Common", | ||
TypeName = "Microsoft.VisualStudio.TestPlatform.Common.Utilities.AssemblyResolver", | ||
MethodName = ".ctor", | ||
ReturnTypeName = ClrNames.Void, | ||
ParameterTypeNames = ["System.Collections.Generic.IEnumerable`1[System.String]"], | ||
MinimumVersion = "15.0.0", | ||
MaximumVersion = "15.*.*", | ||
IntegrationName = IntegrationName)] | ||
[Browsable(false)] | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public class AssemblyResolverCtorIntegration | ||
{ | ||
private const string IntegrationName = "TestPlatformAssemblyResolver"; | ||
|
||
private static TaskCompletionSource<bool>? _callHasBeenCompletedTaskCompletionSource; | ||
|
||
/// <summary> | ||
/// OnMethodBegin callback | ||
/// </summary> | ||
/// <typeparam name="TTarget">Type of the target</typeparam> | ||
/// <typeparam name="TArg1">Type of the argument 1 (System.Collections.Generic.IEnumerable`1[System.String])</typeparam> | ||
/// <param name="instance">Instance value, aka `this` of the instrumented method</param> | ||
/// <param name="directories">Instance of System.Collections.Generic.IEnumerable`1[System.String]</param> | ||
/// <returns>Calltarget state value</returns> | ||
internal static CallTargetState OnMethodBegin<TTarget, TArg1>(TTarget instance, ref TArg1 directories) | ||
{ | ||
Common.Log.Debug("Microsoft.VisualStudio.TestPlatform.Common.Utilities.AssemblyResolver.ctor started."); | ||
_callHasBeenCompletedTaskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously); | ||
return CallTargetState.GetDefault(); | ||
} | ||
|
||
/// <summary> | ||
/// OnMethodEnd callback | ||
/// </summary> | ||
/// <typeparam name="TTarget">Type of the target</typeparam> | ||
/// <param name="instance">Instance value, aka `this` of the instrumented method.</param> | ||
/// <param name="exception">Exception instance in case the original code threw an exception.</param> | ||
/// <param name="state">Calltarget state value</param> | ||
/// <returns>A return value, in an async scenario will be T of Task of T</returns> | ||
internal static CallTargetReturn OnMethodEnd<TTarget>(TTarget instance, Exception? exception, in CallTargetState state) | ||
{ | ||
_callHasBeenCompletedTaskCompletionSource?.TrySetResult(exception is null); | ||
Common.Log.Debug("Microsoft.VisualStudio.TestPlatform.Common.Utilities.AssemblyResolver.ctor finished."); | ||
return CallTargetReturn.GetDefault(); | ||
} | ||
|
||
internal static Task WaitForCallToBeCompletedAsync() | ||
{ | ||
if (_callHasBeenCompletedTaskCompletionSource?.Task is { } callTask) | ||
{ | ||
if (!callTask.IsCompleted) | ||
{ | ||
return InternalWaitForCallToBeCompletedAsync(callTask); | ||
} | ||
|
||
Common.Log.Debug("Microsoft.VisualStudio.TestPlatform.Common.Utilities.AssemblyResolver.ctor already ran."); | ||
} | ||
|
||
return Task.CompletedTask; | ||
|
||
static async Task InternalWaitForCallToBeCompletedAsync(Task<bool> callTask) | ||
{ | ||
Common.Log.Debug("Waiting for Microsoft.VisualStudio.TestPlatform.Common.Utilities.AssemblyResolver.ctor to be completed..."); | ||
await callTask.ConfigureAwait(false); | ||
Common.Log.Debug("Call to Microsoft.VisualStudio.TestPlatform.Common.Utilities.AssemblyResolver.ctor is completed."); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any risk of
new AssemblyResolver()
being called more than once? 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's called twice but for different scenarios, one as of them for the IDE an scenario that is not covered by CI Visibility. So we are safe.