Skip to content
Merged
Show file tree
Hide file tree
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 number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal async Task RunTestsAsync(IEnumerable<TestCase>? tests, IRunContext? run
// this boundary so the execution engine no longer depends on the VSTest run context.
var deploymentContext = new DeploymentContext(runContext?.TestRunDirectory, runContext?.RunSettings?.SettingsXml);

await RunTestsFromRightContextAsync(frameworkHandle, async testRunToken => await TestExecutionManager.RunTestsAsync(testElements, deploymentContext, frameworkHandle, testResultRecorder, new TestElementFilterProvider(runContext), testRunToken).ConfigureAwait(false)).ConfigureAwait(false);
await RunTestsFromRightContextAsync(frameworkHandle, async testRunToken => await TestExecutionManager.RunTestsAsync(testElements, deploymentContext, frameworkHandle.ToAdapterMessageLogger(), testResultRecorder, new TestElementFilterProvider(runContext), testRunToken).ConfigureAwait(false)).ConfigureAwait(false);
}
finally
{
Expand Down Expand Up @@ -223,7 +223,7 @@ internal async Task RunTestsAsync(IEnumerable<string>? sources, IRunContext? run
// this boundary so the execution engine no longer depends on the VSTest run context.
var deploymentContext = new DeploymentContext(runContext?.TestRunDirectory, runContext?.RunSettings?.SettingsXml);

await RunTestsFromRightContextAsync(frameworkHandle, async testRunToken => await TestExecutionManager.RunTestsAsync(sources, deploymentContext, frameworkHandle, testResultRecorder, new TestElementFilterProvider(runContext), testSourceHandler, isMTP, testRunToken).ConfigureAwait(false)).ConfigureAwait(false);
await RunTestsFromRightContextAsync(frameworkHandle, async testRunToken => await TestExecutionManager.RunTestsAsync(sources, deploymentContext, frameworkHandle.ToAdapterMessageLogger(), testResultRecorder, new TestElementFilterProvider(runContext), testSourceHandler, isMTP, testRunToken).ConfigureAwait(false)).ConfigureAwait(false);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using ExecutionScope = Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope;
Expand All @@ -20,16 +19,16 @@ internal partial class TestExecutionManager
/// </summary>
/// <param name="tests">Tests to execute.</param>
/// <param name="deploymentContext">Host-provided test-run directory and run settings XML.</param>
/// <param name="frameworkHandle">Handle to record test start/end/results.</param>
/// <param name="messageLogger">Logger used to report test messages back to the host.</param>
/// <param name="testResultRecorder">Recorder used to report test results back to the host.</param>
/// <param name="filterProvider">Provider for the test filter, or <see langword="null"/> for no filter.</param>
/// <param name="isDeploymentDone">Indicates if deployment is done.</param>
internal virtual async Task ExecuteTestsAsync(IEnumerable<UnitTestElement> tests, DeploymentContext deploymentContext, IFrameworkHandle frameworkHandle, ITestResultRecorder testResultRecorder, ITestElementFilterProvider? filterProvider, bool isDeploymentDone)
internal virtual async Task ExecuteTestsAsync(IEnumerable<UnitTestElement> tests, DeploymentContext deploymentContext, IAdapterMessageLogger messageLogger, ITestResultRecorder testResultRecorder, ITestElementFilterProvider? filterProvider, bool isDeploymentDone)
{
_testResultRecorder = testResultRecorder;
_testElementFilterProvider = filterProvider;

InitializeRandomTestOrder(frameworkHandle.ToAdapterMessageLogger());
InitializeRandomTestOrder(messageLogger);

var testsBySource = (from test in tests
group test by test.TestMethod.AssemblyName into testGroup
Expand All @@ -43,7 +42,7 @@ group test by test.TestMethod.AssemblyName into testGroup
foreach (var group in testsBySource)
{
_testRunCancellationToken?.ThrowIfCancellationRequested();
await ExecuteTestsInSourceAsync(group.Tests, deploymentContext, frameworkHandle, group.Source, isDeploymentDone).ConfigureAwait(false);
await ExecuteTestsInSourceAsync(group.Tests, deploymentContext, messageLogger, group.Source, isDeploymentDone).ConfigureAwait(false);
}
}

Expand All @@ -52,10 +51,10 @@ group test by test.TestMethod.AssemblyName into testGroup
/// </summary>
/// <param name="tests">Tests to execute.</param>
/// <param name="deploymentContext">Host-provided test-run directory and run settings XML.</param>
/// <param name="frameworkHandle">Handle to record test start/end/results.</param>
/// <param name="messageLogger">Logger used to report test messages back to the host.</param>
/// <param name="source">The test container for the tests.</param>
/// <param name="isDeploymentDone">Indicates if deployment is done.</param>
private async Task ExecuteTestsInSourceAsync(IEnumerable<UnitTestElement> tests, DeploymentContext deploymentContext, IFrameworkHandle frameworkHandle, string source, bool isDeploymentDone)
private async Task ExecuteTestsInSourceAsync(IEnumerable<UnitTestElement> tests, DeploymentContext deploymentContext, IAdapterMessageLogger messageLogger, string source, bool isDeploymentDone)
{
DebugEx.Assert(!StringEx.IsNullOrEmpty(source), "Source cannot be empty");

Expand All @@ -66,7 +65,7 @@ private async Task ExecuteTestsInSourceAsync(IEnumerable<UnitTestElement> tests,
}
#endif

IAdapterMessageLogger adapterMessageLogger = frameworkHandle.ToAdapterMessageLogger();
IAdapterMessageLogger adapterMessageLogger = messageLogger;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NIT (Dim 15 — Code Structure): adapterMessageLogger is now a trivial alias for the incoming parameter messageLogger; the two names exist only because the earlier code called frameworkHandle.ToAdapterMessageLogger() here to produce a new wrapper.

Follow-up cleanup option: rename the parameter from messageLogger to adapterMessageLogger (matching the existing local variable) and drop this assignment, keeping the rest of the method body unchanged. Alternatively, remove the local and replace all downstream uses of adapterMessageLogger with messageLogger. Either way no behavior change.


using ITestSourceHost isolationHost = PlatformServiceProvider.Instance.CreateTestSourceHost(source, deploymentContext.RunSettingsXml);
bool usesAppDomains = isolationHost is TestSourceHost { UsesAppDomain: true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Helpers;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
Expand Down Expand Up @@ -89,31 +87,31 @@ private static Task DefaultFactoryAsync(Func<Task> taskGetter)
/// </summary>
/// <param name="tests">Tests to be run.</param>
/// <param name="deploymentContext">Host-provided test-run directory and run settings XML.</param>
/// <param name="frameworkHandle">Handle to the framework to record results and to do framework operations.</param>
/// <param name="messageLogger">Logger used to report test messages back to the host.</param>
/// <param name="testResultRecorder">Recorder used to report test results back to the host.</param>
/// <param name="filterProvider">Provider for the test filter, or <see langword="null"/> for no filter.</param>
/// <param name="runCancellationToken">Test run cancellation token.</param>
internal async Task RunTestsAsync(IEnumerable<UnitTestElement> tests, DeploymentContext deploymentContext, IFrameworkHandle frameworkHandle, ITestResultRecorder testResultRecorder, ITestElementFilterProvider? filterProvider, TestRunCancellationToken runCancellationToken)
internal async Task RunTestsAsync(IEnumerable<UnitTestElement> tests, DeploymentContext deploymentContext, IAdapterMessageLogger messageLogger, ITestResultRecorder testResultRecorder, ITestElementFilterProvider? filterProvider, TestRunCancellationToken runCancellationToken)
{
DebugEx.Assert(tests != null, "tests");
DebugEx.Assert(deploymentContext != null, "deploymentContext");
DebugEx.Assert(frameworkHandle != null, "frameworkHandle");
DebugEx.Assert(messageLogger != null, "messageLogger");
DebugEx.Assert(runCancellationToken != null, "runCancellationToken");

_testRunCancellationToken = runCancellationToken;
PlatformServiceProvider.Instance.TestRunCancellationToken = _testRunCancellationToken;

#if !WINDOWS_UWP && !WIN_UI
bool isDeploymentDone = Deploy(tests, deploymentContext, frameworkHandle);
bool isDeploymentDone = Deploy(tests, deploymentContext, messageLogger);
#else
const bool isDeploymentDone = false;
#endif

// Placing this after deployment since we need information post deployment that we pass in as properties.
CacheSessionParameters(deploymentContext.RunSettingsXml, frameworkHandle.ToAdapterMessageLogger());
CacheSessionParameters(deploymentContext.RunSettingsXml, messageLogger);

// Execute the tests
await ExecuteTestsAsync(tests, deploymentContext, frameworkHandle, testResultRecorder, filterProvider, isDeploymentDone).ConfigureAwait(false);
await ExecuteTestsAsync(tests, deploymentContext, messageLogger, testResultRecorder, filterProvider, isDeploymentDone).ConfigureAwait(false);

#if !WINDOWS_UWP && !WIN_UI
if (!_hasAnyTestFailed)
Expand All @@ -123,7 +121,7 @@ internal async Task RunTestsAsync(IEnumerable<UnitTestElement> tests, Deployment
#endif
}

internal async Task RunTestsAsync(IEnumerable<string> sources, DeploymentContext deploymentContext, IFrameworkHandle frameworkHandle, ITestResultRecorder testResultRecorder, ITestElementFilterProvider? filterProvider, ITestSourceHandler testSourceHandler, bool isMTP, TestRunCancellationToken cancellationToken)
internal async Task RunTestsAsync(IEnumerable<string> sources, DeploymentContext deploymentContext, IAdapterMessageLogger messageLogger, ITestResultRecorder testResultRecorder, ITestElementFilterProvider? filterProvider, ITestSourceHandler testSourceHandler, bool isMTP, TestRunCancellationToken cancellationToken)
{
_testRunCancellationToken = cancellationToken;
PlatformServiceProvider.Instance.TestRunCancellationToken = _testRunCancellationToken;
Expand All @@ -132,7 +130,7 @@ internal async Task RunTestsAsync(IEnumerable<string> sources, DeploymentContext

var tests = new List<UnitTestElement>();

IAdapterMessageLogger logger = frameworkHandle.ToAdapterMessageLogger();
IAdapterMessageLogger logger = messageLogger;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NIT (Dim 15 — Code Structure): Same trivial alias pattern as in ExecuteTestsInSourceAsync: logger is now identically equal to messageLogger. This line was meaningful before (it called frameworkHandle.ToAdapterMessageLogger()) but is now dead.

Follow-up cleanup: rename the parameter or remove the local and update the handful of downstream uses in this method.


// deploy everything first.
foreach (string source in sources)
Expand All @@ -148,16 +146,16 @@ internal async Task RunTestsAsync(IEnumerable<string> sources, DeploymentContext
}

#if !WINDOWS_UWP && !WIN_UI
bool isDeploymentDone = Deploy(tests, deploymentContext, frameworkHandle);
bool isDeploymentDone = Deploy(tests, deploymentContext, messageLogger);
#else
const bool isDeploymentDone = false;
#endif

// Placing this after deployment since we need information post deployment that we pass in as properties.
CacheSessionParameters(deploymentContext.RunSettingsXml, frameworkHandle.ToAdapterMessageLogger());
CacheSessionParameters(deploymentContext.RunSettingsXml, messageLogger);

// Run tests.
await ExecuteTestsAsync(tests, deploymentContext, frameworkHandle, testResultRecorder, filterProvider, isDeploymentDone).ConfigureAwait(false);
await ExecuteTestsAsync(tests, deploymentContext, messageLogger, testResultRecorder, filterProvider, isDeploymentDone).ConfigureAwait(false);

#if !WINDOWS_UWP && !WIN_UI
if (!_hasAnyTestFailed)
Expand All @@ -172,8 +170,8 @@ internal async Task RunTestsAsync(IEnumerable<string> sources, DeploymentContext
/// Runs deployment for the given tests via the platform-agnostic deployment service using the neutral
/// <see cref="DeploymentContext"/> supplied by the adapter boundary.
/// </summary>
private static bool Deploy(IEnumerable<UnitTestElement> tests, DeploymentContext deploymentContext, IFrameworkHandle frameworkHandle)
=> PlatformServiceProvider.Instance.TestDeployment.Deploy(tests, deploymentContext, frameworkHandle.ToAdapterMessageLogger());
private static bool Deploy(IEnumerable<UnitTestElement> tests, DeploymentContext deploymentContext, IAdapterMessageLogger messageLogger)
=> PlatformServiceProvider.Instance.TestDeployment.Deploy(tests, deploymentContext, messageLogger);
#endif

internal virtual UnitTestDiscoverer GetUnitTestDiscoverer(ITestSourceHandler testSourceHandler) => new(testSourceHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal static async Task<ImmutableArray<TestResult>> RunTestsAsync(IEnumerable
var frameworkHandle = new InternalFrameworkHandle();

ITestResultRecorder testResultRecorder = frameworkHandle.ToTestResultRecorder(Environment.MachineName, MSTestSettings.CurrentSettings);
await testExecutionManager.ExecuteTestsAsync(ToUnitTestElements(testCases), new DeploymentContext(null, null), frameworkHandle, testResultRecorder, filterProvider: null, false);
await testExecutionManager.ExecuteTestsAsync(ToUnitTestElements(testCases), new DeploymentContext(null, null), frameworkHandle.ToAdapterMessageLogger(), testResultRecorder, filterProvider: null, false);
return frameworkHandle.GetFlattenedTestResults();
}

Expand All @@ -55,7 +55,7 @@ internal static async Task<ImmutableArray<TestResult>> RunTestsAsync(IEnumerable
var runContext = new InternalRunContext(runSettingsXml, testCaseFilter);

ITestResultRecorder testResultRecorder = frameworkHandle.ToTestResultRecorder(Environment.MachineName, MSTestSettings.CurrentSettings);
await testExecutionManager.ExecuteTestsAsync(ToUnitTestElements(testCases), new DeploymentContext(runContext.TestRunDirectory, runContext.RunSettings?.SettingsXml), frameworkHandle, testResultRecorder, new TestElementFilterProvider(runContext), false);
await testExecutionManager.ExecuteTestsAsync(ToUnitTestElements(testCases), new DeploymentContext(runContext.TestRunDirectory, runContext.RunSettings?.SettingsXml), frameworkHandle.ToAdapterMessageLogger(), testResultRecorder, new TestElementFilterProvider(runContext), false);
return frameworkHandle.GetFlattenedTestResults();
}

Expand Down
Loading
Loading