Skip to content

Commit

Permalink
make testplatform compatible with old testhost (microsoft#971)
Browse files Browse the repository at this point in the history
* fix for issue microsoft#970

* Address PR comment

* Addressed Pr comment

* Remove unused code

* Address PR comment

* Addressed PR comment

* Addressed PR comment

* Code cleanup
  • Loading branch information
Faizan2304 authored Aug 4, 2017
1 parent aee3599 commit 5dc8ff1
Show file tree
Hide file tree
Showing 31 changed files with 437 additions and 79 deletions.
17 changes: 16 additions & 1 deletion TestPlatform.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26605.1
VisualStudioVersion = 15.0.26507.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED0C35EB-7F31-4841-A24F-8EB708FFA959}"
EndProject
Expand Down Expand Up @@ -157,6 +157,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.Exte
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlameUnitTestProject", "test\TestAssets\BlameUnitTestProject\BlameUnitTestProject.csproj", "{6B2B841C-CCFF-469A-9939-EB07EA0401AE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleProjectWithOldTestHost", "test\TestAssets\SampleProjectWithOldTestHost\SampleProjectWithOldTestHost.csproj", "{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -827,6 +829,18 @@ Global
{6B2B841C-CCFF-469A-9939-EB07EA0401AE}.Release|x64.Build.0 = Release|Any CPU
{6B2B841C-CCFF-469A-9939-EB07EA0401AE}.Release|x86.ActiveCfg = Release|Any CPU
{6B2B841C-CCFF-469A-9939-EB07EA0401AE}.Release|x86.Build.0 = Release|Any CPU
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Debug|x64.ActiveCfg = Debug|Any CPU
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Debug|x64.Build.0 = Debug|Any CPU
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Debug|x86.ActiveCfg = Debug|Any CPU
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Debug|x86.Build.0 = Debug|Any CPU
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Release|Any CPU.Build.0 = Release|Any CPU
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Release|x64.ActiveCfg = Release|Any CPU
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Release|x64.Build.0 = Release|Any CPU
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Release|x86.ActiveCfg = Release|Any CPU
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -896,5 +910,6 @@ Global
{76D4BB7E-D981-42D5-BE96-6FAD8DEF9A4A} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959}
{488675EC-C8BB-40E0-AD4F-91F623D548B3} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}
{6B2B841C-CCFF-469A-9939-EB07EA0401AE} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A}
{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;

using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
Expand All @@ -20,7 +19,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.ClientProtocol;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

using Constants = Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Constants;

/// <summary>
Expand Down Expand Up @@ -121,11 +119,13 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH
isDebug: (testRunCriteria.TestHostLauncher != null && testRunCriteria.TestHostLauncher.IsDebug),
testCaseFilter: testRunCriteria.TestCaseFilter);

// This is workaround for the bug https://github.com/Microsoft/vstest/issues/970
var runsettings = this.RemoveNodesFromRunsettingsIfRequired(testRunCriteria.TestRunSettings, (testMessageLevel, message) => { this.LogMessage(testMessageLevel, message, eventHandler); });
if (testRunCriteria.HasSpecificSources)
{
var runRequest = new TestRunCriteriaWithSources(
testRunCriteria.AdapterSourceMap,
testRunCriteria.TestRunSettings,
runsettings,
executionContext);

this.RequestSender.StartTestRun(runRequest, eventHandler);
Expand All @@ -134,7 +134,7 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH
{
var runRequest = new TestRunCriteriaWithTests(
testRunCriteria.Tests,
testRunCriteria.TestRunSettings,
runsettings,
executionContext);

this.RequestSender.StartTestRun(runRequest, eventHandler);
Expand All @@ -144,14 +144,7 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH
catch (Exception exception)
{
EqtTrace.Error("ProxyExecutionManager.StartTestRun: Failed to start test run: {0}", exception);

// Log to vs ide test output
var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = exception.Message };
var rawMessage = this.dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload);
eventHandler.HandleRawMessage(rawMessage);

// Log to vstest.console
eventHandler.HandleLogMessage(TestMessageLevel.Error, exception.Message);
this.LogMessage(TestMessageLevel.Error, exception.Message, eventHandler);

// Send a run complete to caller. Similar logic is also used in ParallelProxyExecutionManager.StartTestRunOnConcurrentManager
// Aborted is `true`: in case of parallel run (or non shared host), an aborted message ensures another execution manager
Expand Down Expand Up @@ -187,6 +180,17 @@ public void Abort()

#endregion

private void LogMessage(TestMessageLevel testMessageLevel, string message, ITestRunEventsHandler eventHandler)
{
// Log to vs ide test output
var testMessagePayload = new TestMessagePayload { MessageLevel = testMessageLevel, Message = message };
var rawMessage = this.dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload);
eventHandler.HandleRawMessage(rawMessage);

// Log to vstest.console
eventHandler.HandleLogMessage(testMessageLevel, message);
}

private void InitializeExtensions(IEnumerable<string> sources)
{
var extensions = new List<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client
using System.Linq;
using System.Reflection;
using System.Threading;

using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;
using Microsoft.VisualStudio.TestPlatform.Utilities;
Expand All @@ -30,6 +30,10 @@ public abstract class ProxyOperationManager
private readonly IProcessHelper processHelper;
private readonly int connectionTimeout;
private readonly string versionCheckPropertyName = "IsVersionCheckRequired";
private readonly string makeRunsettingsCompatiblePropertyName = "MakeRunsettingsCompatible";
private bool versionCheckRequired = true;
private bool makeRunsettingsCompatible;
private bool makeRunsettingsCompatibleSet;
private readonly ManualResetEventSlim testHostExited = new ManualResetEventSlim(false);

private int testHostProcessId;
Expand Down Expand Up @@ -157,14 +161,9 @@ public virtual bool SetupChannel(IEnumerable<string> sources, CancellationToken
// Handling special case for dotnet core projects with older test hosts
// Older test hosts are not aware of protocol version check
// Hence we should not be sending VersionCheck message to these test hosts
bool checkRequired = true;
var property = this.testHostManager.GetType().GetRuntimeProperties().FirstOrDefault(p => string.Equals(p.Name, versionCheckPropertyName, StringComparison.OrdinalIgnoreCase));
if (property != null)
{
checkRequired = (bool)property.GetValue(this.testHostManager);
}
this.CompatIssueWithVersionCheckAndRunsettings();

if (checkRequired)
if (this.versionCheckRequired)
{
this.RequestSender.CheckVersionWithTestHost();
}
Expand Down Expand Up @@ -203,7 +202,7 @@ public virtual void Close()
this.initialized = false;

EqtTrace.Warning("ProxyOperationManager: Timed out waiting for test host to exit. Will terminate process.");

// please clean up test host.
this.testHostManager.CleanTestHostAsync(CancellationToken.None).Wait();

Expand Down Expand Up @@ -245,6 +244,46 @@ protected string GetTimestampedLogFile(string logFile)
Path.GetExtension(logFile))).AddDoubleQuote();
}

/// <summary>
/// This function will remove the unknown runsettings node from runsettings for old testhost who throws exception for unknown node.
/// </summary>
/// <param name="runsettingsXml">runsettings string</param>
/// <returns>runsetting after removing unrequired nodes</returns>
protected string RemoveNodesFromRunsettingsIfRequired(string runsettingsXml, Action<TestMessageLevel, string> logMessage)
{
var updatedRunSettingsXml = runsettingsXml;
if (!this.makeRunsettingsCompatibleSet)
{
this.CompatIssueWithVersionCheckAndRunsettings();
}

if (this.makeRunsettingsCompatible)
{
logMessage.Invoke(TestMessageLevel.Warning, CrossPlatEngineResources.OldTestHostIsGettingUsed);
updatedRunSettingsXml = InferRunSettingsHelper.MakeRunsettingsCompatible(runsettingsXml);
}

return updatedRunSettingsXml;
}

private void CompatIssueWithVersionCheckAndRunsettings()
{
var properties = this.testHostManager.GetType().GetRuntimeProperties();

var versionCheckProperty = properties.FirstOrDefault(p => string.Equals(p.Name, versionCheckPropertyName, StringComparison.OrdinalIgnoreCase));
if (versionCheckProperty != null)
{
this.versionCheckRequired = (bool)versionCheckProperty.GetValue(this.testHostManager);
}

var makeRunsettingsCompatibleProperty = properties.FirstOrDefault(p => string.Equals(p.Name, makeRunsettingsCompatiblePropertyName, StringComparison.OrdinalIgnoreCase));
if (makeRunsettingsCompatibleProperty != null)
{
this.makeRunsettingsCompatible = (bool)makeRunsettingsCompatibleProperty.GetValue(this.testHostManager);
this.makeRunsettingsCompatibleSet = true;
}
}

private void TestHostManagerHostLaunched(object sender, HostProviderEventArgs e)
{
EqtTrace.Verbose(e.Data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public void StartTestRun(

this.activeTestRun.RunTests();
}
catch(Exception e)
{
this.testRunEventsHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.ToString());
this.Abort();
}
finally
{
this.activeTestRun = null;
Expand Down Expand Up @@ -121,6 +126,11 @@ public void StartTestRun(

this.activeTestRun.RunTests();
}
catch(Exception e)
{
this.testRunEventsHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.ToString());
this.Abort();
}
finally
{
this.activeTestRun = null;
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,7 @@
<data name="FailedToLaunchTestHost" xml:space="preserve">
<value>Failed to launch testhost with error: {0}</value>
</data>
<data name="OldTestHostIsGettingUsed" xml:space="preserve">
<value>You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
<target state="new">Failed to launch testhost with error: {0}</target>
<note></note>
</trans-unit>
<trans-unit id="OldTestHostIsGettingUsed">
<source>You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0.</source>
<target state="new">You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
<target state="new">Failed to launch testhost with error: {0}</target>
<note></note>
</trans-unit>
<trans-unit id="OldTestHostIsGettingUsed">
<source>You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0.</source>
<target state="new">You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
<target state="new">Failed to launch testhost with error: {0}</target>
<note></note>
</trans-unit>
<trans-unit id="OldTestHostIsGettingUsed">
<source>You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0.</source>
<target state="new">You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
<target state="new">Failed to launch testhost with error: {0}</target>
<note></note>
</trans-unit>
<trans-unit id="OldTestHostIsGettingUsed">
<source>You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0.</source>
<target state="new">You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
<target state="new">Failed to launch testhost with error: {0}</target>
<note></note>
</trans-unit>
<trans-unit id="OldTestHostIsGettingUsed">
<source>You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0.</source>
<target state="new">You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
<target state="new">Failed to launch testhost with error: {0}</target>
<note></note>
</trans-unit>
<trans-unit id="OldTestHostIsGettingUsed">
<source>You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0.</source>
<target state="new">You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
<target state="new">Failed to launch testhost with error: {0}</target>
<note></note>
</trans-unit>
<trans-unit id="OldTestHostIsGettingUsed">
<source>You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0.</source>
<target state="new">You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
<target state="new">Failed to launch testhost with error: {0}</target>
<note></note>
</trans-unit>
<trans-unit id="OldTestHostIsGettingUsed">
<source>You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0.</source>
<target state="new">You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
<target state="new">Failed to launch testhost with error: {0}</target>
<note></note>
</trans-unit>
<trans-unit id="OldTestHostIsGettingUsed">
<source>You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0.</source>
<target state="new">You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Loading

0 comments on commit 5dc8ff1

Please sign in to comment.