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 @@ -62,7 +62,7 @@
<FileToCopy Include="$(SourcePath)testhost\bin\$(Configuration)\net48\win7-x64\**\*.*" SubFolder="TestHostNetFramework\" />

<!-- copy datacollectors" -->
<FileToCopy Include="$(SourcePath)datacollector\bin\$(Configuration)\net472\**\*.*" SubFolder="vstest.console\" />
<FileToCopy Include="$(SourcePath)datacollector\bin\$(Configuration)\net472\**\*.*" SubFolder="" />
<FileToCopy Include="$(SourcePath)Microsoft.TestPlatform.Extensions.BlameDataCollector\bin\$(Configuration)\net472\**\*.*" SubFolder="Extensions\" />
<FileToCopy Include="$(SourcePath)DataCollectors\Microsoft.TestPlatform.Extensions.EventLogCollector\bin\$(Configuration)\$(NetFrameworkMinimum)\**\*.*" SubFolder="Extensions\" />
<FileToCopy Include="$(SourcePath)DataCollectors\DumpMinitool\bin\$(Configuration)\$(NetFrameworkMinimum)\win7-x64\**\*.*" SubFolder="Extensions\blame\" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.Utilities;

namespace Microsoft.VisualStudio.TestPlatform.Common.ExtensionDecorators;
internal class ExtensionDecoratorFactory
{
private readonly IFeatureFlag _featureFlag;

public ExtensionDecoratorFactory(IFeatureFlag featureFlag)
{
_featureFlag = featureFlag;
}

public ITestExecutor Decorate(ITestExecutor originalTestExecutor)
{
return _featureFlag.IsSet(FeatureFlag.DISABLE_SERIALTESTRUN_DECORATOR)
? originalTestExecutor
: new SerialTestRunDecorator(originalTestExecutor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Threading;
using System.Xml.Linq;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

namespace Microsoft.VisualStudio.TestPlatform.Common.ExtensionDecorators;

internal class SerialTestRunDecorator : ITestExecutor, ITestExecutor2, IDisposable
{
private readonly SemaphoreSlim _runSequentialEvent = new(1);

public ITestExecutor OriginalTestExecutor { get; }

public SerialTestRunDecorator(ITestExecutor originalTestExecutor)
{
OriginalTestExecutor = originalTestExecutor;
}

public void RunTests(IEnumerable<TestCase>? tests, IRunContext? runContext, IFrameworkHandle? frameworkHandle)
{
if (IsSerialTestRunEnabled(runContext))
{
EqtTrace.Info("SerializeTestRunDecorator.RunTests: Test cases will run sequentially");
if (tests is null)
{
return;
}

foreach (TestCase testToRun in tests)
{
_runSequentialEvent.Wait();
OriginalTestExecutor.RunTests(new List<TestCase> { testToRun }, runContext, new SerializeTestRunDecoratorFrameworkHandle(frameworkHandle!, _runSequentialEvent));
}
}
else
{
OriginalTestExecutor.RunTests(tests, runContext, frameworkHandle);
}
}

public void RunTests(IEnumerable<string>? sources, IRunContext? runContext, IFrameworkHandle? frameworkHandle)
{
if (IsSerialTestRunEnabled(runContext))
{
EqtTrace.Error("<ForceOneTestAtTimePerTestHost>true</ForceOneTestAtTimePerTestHost> is not supported for sources test run.");
frameworkHandle?.SendMessage(TestMessageLevel.Error, Resources.Resources.SerialTestRunInvalidScenario);
}
else
{
OriginalTestExecutor.RunTests(sources, runContext, frameworkHandle);
}
}

public bool ShouldAttachToTestHost(IEnumerable<string>? sources, IRunContext runContext)
{
if (OriginalTestExecutor is ITestExecutor2 executor)
{
return executor.ShouldAttachToTestHost(sources, runContext);
}

// If the adapter doesn't implement the new test executor interface we should attach to
// the default test host by default to preserve old behavior.
return true;
}

public bool ShouldAttachToTestHost(IEnumerable<TestCase>? tests, IRunContext runContext)
{
if (OriginalTestExecutor is ITestExecutor2 executor)
{
return executor.ShouldAttachToTestHost(tests, runContext);
}

// If the adapter doesn't implement the new test executor interface we should attach to
// the default test host by default to preserve old behavior.
return true;
}

public void Cancel()
=> OriginalTestExecutor.Cancel();

private static bool IsSerialTestRunEnabled(IRunContext? runContext)
{
if (runContext is null || runContext.RunSettings is null || runContext.RunSettings.SettingsXml is null)
{
return false;
}

XElement runSettings = XElement.Parse(runContext.RunSettings.SettingsXml);
XElement? serializeTestRun = runSettings.Element("RunConfiguration")?.Element("ForceOneTestAtTimePerTestHost");
return serializeTestRun is not null && bool.TryParse(serializeTestRun.Value, out bool enabled) && enabled;
}

public void Dispose()
=> _runSequentialEvent.Dispose();
}

internal class SerializeTestRunDecoratorFrameworkHandle : IFrameworkHandle
{
private readonly IFrameworkHandle _frameworkHandle;
private readonly SemaphoreSlim _testEnd;

public SerializeTestRunDecoratorFrameworkHandle(IFrameworkHandle frameworkHandle, SemaphoreSlim testEnd)
{
_frameworkHandle = frameworkHandle;
_testEnd = testEnd;
}

public bool EnableShutdownAfterTestRun { get => _frameworkHandle.EnableShutdownAfterTestRun; set => _frameworkHandle.EnableShutdownAfterTestRun = value; }

public int LaunchProcessWithDebuggerAttached(string filePath, string? workingDirectory, string? arguments, IDictionary<string, string?>? environmentVariables)
=> _frameworkHandle.LaunchProcessWithDebuggerAttached(filePath, workingDirectory, arguments, environmentVariables);

public void RecordAttachments(IList<AttachmentSet> attachmentSets)
=> _frameworkHandle.RecordAttachments(attachmentSets);

public void RecordEnd(TestCase testCase, TestOutcome outcome)
{
_frameworkHandle.RecordEnd(testCase, outcome);
_testEnd.Release();
}

public void RecordResult(TestResult testResult)
=> _frameworkHandle.RecordResult(testResult);

public void RecordStart(TestCase testCase)
=> _frameworkHandle.RecordStart(testCase);

public void SendMessage(TestMessageLevel testMessageLevel, string message)
=> _frameworkHandle.SendMessage(testMessageLevel, message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.Threading;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

namespace Microsoft.VisualStudio.TestPlatform.Common.ExtensionDecorators;

internal class SerialTestRunDecoratorFrameworkHandle : IFrameworkHandle
{
private readonly IFrameworkHandle _frameworkHandle;
private readonly SemaphoreSlim _testEnd;

public SerialTestRunDecoratorFrameworkHandle(IFrameworkHandle frameworkHandle, SemaphoreSlim testEnd)
{
_frameworkHandle = frameworkHandle;
_testEnd = testEnd;
}

public bool EnableShutdownAfterTestRun { get => _frameworkHandle.EnableShutdownAfterTestRun; set => _frameworkHandle.EnableShutdownAfterTestRun = value; }

public int LaunchProcessWithDebuggerAttached(string filePath, string? workingDirectory, string? arguments, IDictionary<string, string?>? environmentVariables)
=> _frameworkHandle.LaunchProcessWithDebuggerAttached(filePath, workingDirectory, arguments, environmentVariables);

public void RecordAttachments(IList<AttachmentSet> attachmentSets)
=> _frameworkHandle.RecordAttachments(attachmentSets);

public void RecordEnd(TestCase testCase, TestOutcome outcome)
{
_frameworkHandle.RecordEnd(testCase, outcome);
_testEnd.Release();
}

public void RecordResult(TestResult testResult)
=> _frameworkHandle.RecordResult(testResult);

public void RecordStart(TestCase testCase)
=> _frameworkHandle.RecordStart(testCase);

public void SendMessage(TestMessageLevel testMessageLevel, string message)
=> _frameworkHandle.SendMessage(testMessageLevel, message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
using System;
using System.Linq;

using Microsoft.VisualStudio.TestPlatform.Common.ExtensionDecorators;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.Utilities;

namespace Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities;

/// <summary>
Expand All @@ -16,6 +20,7 @@ public class LazyExtension<TExtension, TMetadata>
private static readonly object Synclock = new();
private readonly Type? _metadataType;
private readonly Func<TExtension>? _extensionCreator;
private readonly ExtensionDecoratorFactory _extensionDecoratorFactory = new(FeatureFlag.Instance);
private TExtension? _extension;
private TMetadata? _metadata;

Expand Down Expand Up @@ -96,7 +101,15 @@ public TExtension Value
TPDebug.Assert(TestPluginInfo.AssemblyQualifiedName is not null, "TestPluginInfo.AssemblyQualifiedName is null");
var pluginType = TestPluginManager.GetTestExtensionType(TestPluginInfo.AssemblyQualifiedName);
TPDebug.Assert(pluginType is not null, "pluginType is null");
_extension = TestPluginManager.CreateTestExtension<TExtension>(pluginType);

// If the extension is a test executor we decorate the adapter to augment the test platform capabilities.
var extension = TestPluginManager.CreateTestExtension<TExtension>(pluginType);
if (typeof(ITestExecutor).IsAssignableFrom(typeof(TExtension)))
{
extension = (TExtension)_extensionDecoratorFactory.Decorate((ITestExecutor)extension!);
}

_extension = extension;
}
}
}
Expand Down
18 changes: 13 additions & 5 deletions src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@
<data name="RunSettingsParseError" xml:space="preserve">
<value>An error occurred while loading the run settings. Error: {0}</value>
</data>
<data name="SerialTestRunInvalidScenario" xml:space="preserve">
<value>&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</value>
</data>
<data name="SettingsNodeInvalidName" xml:space="preserve">
<value>Invalid settings node specified. The name property of the settings node must be non-empty.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
<target state="translated">Trasování zásobníku:</target>
<note></note>
</trans-unit>
<trans-unit id="SerialTestRunInvalidScenario">
<source>&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</source>
<target state="new">&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
<target state="translated">Stapelüberwachung:</target>
<note></note>
</trans-unit>
<trans-unit id="SerialTestRunInvalidScenario">
<source>&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</source>
<target state="new">&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
<target state="translated">Seguimiento de la pila:</target>
<note></note>
</trans-unit>
<trans-unit id="SerialTestRunInvalidScenario">
<source>&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</source>
<target state="new">&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
<target state="translated">Arborescence des appels de procédure :</target>
<note></note>
</trans-unit>
<trans-unit id="SerialTestRunInvalidScenario">
<source>&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</source>
<target state="new">&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
<target state="translated">Analisi dello stack:</target>
<note></note>
</trans-unit>
<trans-unit id="SerialTestRunInvalidScenario">
<source>&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</source>
<target state="new">&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
<target state="translated">スタック トレース:</target>
<note></note>
</trans-unit>
<trans-unit id="SerialTestRunInvalidScenario">
<source>&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</source>
<target state="new">&lt;ForceOneTestAtTimePerTestHost&gt;true&lt;/ForceOneTestAtTimePerTestHost&gt; is not supported for sources test run.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Loading