Skip to content
Merged
Changes from all commits
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
Original file line numberDiff line numberDiff line change
Expand Up@@ -496,11 +496,27 @@ private async Task<TestResult[]> ExecuteTestAsync(ITestContext executionContext,
{
try
{
ExecutionContext? capturedContext = testMethodInfo.Parent.ExecutionContext
?? testMethodInfo.Parent.Parent.ExecutionContext;

// Fast path: when no ExecutionContext was captured (the common case),
// ExecutionContextHelpers.RunOnContext would simply call the action inline.
// Skip the TaskCompletionSource bridge, async-lambda closure, and Action
// delegate allocations entirely.
if (capturedContext is null)
{
using (TestContextImplementation.SetCurrentTestContext(executionContext as TestContext))
{
testMethodInfo.TestContext = executionContext;
return await _testMethodInfo.Executor.ExecuteAsync(testMethodInfo).ConfigureAwait(false);
}
}
Comment thread
Evangelink marked this conversation as resolved.

var tcs = new TaskCompletionSource<TestResult[]>();

#pragma warning disable VSTHRD101 // Avoid unsupported async delegates
ExecutionContextHelpers.RunOnContext(
testMethodInfo.Parent.ExecutionContext ?? testMethodInfo.Parent.Parent.ExecutionContext,
capturedContext,
async () =>
{
try
Expand Down