Skip to content
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

1187 add support for xplat vstest console in translationlayer #1893

Merged
merged 29 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4f522db
reverting back app domain culture setup
mayankbansal018 Aug 14, 2018
b245820
binding redirect for TW.Interfaces
mayankbansal018 Aug 14, 2018
55e4e2f
Merge remote-tracking branch 'upstream/master'
mayankbansal018 Aug 17, 2018
c4f2602
Run net451 test for Newtonsoft dependency
mayankbansal018 Aug 20, 2018
e35aa48
Merge remote-tracking branch 'upstream/master'
mayankbansal018 Aug 21, 2018
e4e0e7e
Merge remote-tracking branch 'upstream/master'
mayankbansal018 Oct 29, 2018
9bab4aa
Merge remote-tracking branch 'upstream/master'
mayankbansal018 Jan 14, 2019
f2aeb4a
Rename vstest.console.exe and xunit.console.exe to vstest.console
rouke-broersma Jan 14, 2019
e47c1e9
If vstest console path ends in .dll, start with dotnet
rouke-broersma Jan 14, 2019
45fa51e
change another instance of vstest.console.exe comment to vstest.console
rouke-broersma Jan 14, 2019
c8aa97e
Check if vstest console is dll and run with dotnet if true
rouke-broersma Jan 20, 2019
e397310
Change order of process start to give vstest.console.dll some more ti…
rouke-broersma Jan 20, 2019
696029e
Remove test logic that says vstest.console.dll is not supported by Vs…
rouke-broersma Jan 20, 2019
18daa43
Use DotnetHostHelper.GetDotnetPath instead of hardcoded dotnet execut…
rouke-broersma Jan 23, 2019
51668b8
Add missing process.Kill
rouke-broersma Jan 23, 2019
3142c73
vstest.console.dll is picked from debug\netcoreapp folder.
mayankbansal018 Jan 23, 2019
f87ce4a
Merge pull request #1 from mayankbansal018/1187_add_support_for_xpat_…
mayankbansal018 Jan 23, 2019
2eeab35
Fix Tranlation layer tests
mayankbansal018 Jan 24, 2019
3a8cd68
Merge pull request #2 from mayankbansal018/1187_add_support_for_xpat_…
mayankbansal018 Jan 24, 2019
ff1b4bd
Merge branch 'master' into 1187_add_support_for_xpat_vstest_console_i…
mayankbansal018 Jan 24, 2019
be99176
Fix Azure pipeline
mayankbansal018 Jan 24, 2019
cda8bf9
Merge pull request #3 from mayankbansal018/1187_add_support_for_xpat_…
mayankbansal018 Jan 24, 2019
4f022d7
PR Comments
mayankbansal018 Jan 24, 2019
ccaeb07
Merge pull request #4 from mayankbansal018/1187_add_support_for_xpat_…
mayankbansal018 Jan 24, 2019
6f0e7d2
Fix
mayankbansal018 Jan 24, 2019
e68fa1d
Merge pull request #5 from mayankbansal018/1187_add_support_for_xpat_…
mayankbansal018 Jan 24, 2019
2f81919
Merge remote-tracking branch 'upstream/master'
mayankbansal018 Feb 8, 2019
d0a4701
Merge branch 'master' into 1187_add_support_for_xpat_vstest_console_i…
mayankbansal018 Feb 8, 2019
03c3a96
Merge pull request #6 from mayankbansal018/1187_add_support_for_xpat_…
mayankbansal018 Feb 8, 2019
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 @@ -11,7 +11,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer
using System.Globalization;

/// <summary>
/// Vstest.console.exe process manager
/// Vstest.console process manager
Copy link
Contributor

Choose a reason for hiding this comment

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

Would have loved to see some unit tests for this class.

/// </summary>
internal class VsTestConsoleProcessManager : IProcessManager
{
Expand All @@ -34,10 +34,16 @@ internal class VsTestConsoleProcessManager : IProcessManager
/// </summary>
private const string DIAG_ARGUMENT = "/diag:{0};tracelevel={1}";

/// <summary>
/// Name of the xplat dotnet cli tool
/// </summary>
private const string DOTNET_EXECUTABLE = "dotnet";

private string vstestConsolePath;
private object syncObject = new object();
private bool vstestConsoleStarted = false;
private bool vstestConsoleExited = false;
private readonly bool isNetCoreRunner;
private Process process;

#endregion
Expand All @@ -50,10 +56,11 @@ internal class VsTestConsoleProcessManager : IProcessManager
/// <summary>
/// Creates an instance of VsTestConsoleProcessManager class.
/// </summary>
/// <param name="vstestConsolePath">The fullpath to vstest.console.exe</param>
/// <param name="vstestConsolePath">The fullpath to vstest.console</param>
public VsTestConsoleProcessManager(string vstestConsolePath)
{
this.vstestConsolePath = vstestConsolePath;
isNetCoreRunner = vstestConsolePath.EndsWith(".dll");
}

#endregion Constructor
Expand All @@ -72,33 +79,35 @@ public bool IsProcessInitialized()
}

/// <summary>
/// Call xUnit.console.exe with the parameters previously specified
/// Call vstest.console with the parameters previously specified
/// </summary>
public void StartProcess(ConsoleParameters consoleParameters)
{
this.process = new Process();
process.StartInfo.FileName = vstestConsolePath;
process.StartInfo.Arguments = string.Join(" ", BuildArguments(consoleParameters));

//process.StartInfo.WorkingDirectory = WorkingDirectory;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;

//process.StartInfo.RedirectStandardOutput = true;
//process.StartInfo.RedirectStandardError = true;
var info = new ProcessStartInfo(GetConsoleRunner(), string.Join(" ", BuildArguments(consoleParameters)))
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};

EqtTrace.Verbose("VsTestCommandLineWrapper: {0} {1}", process.StartInfo.FileName,
process.StartInfo.Arguments);
EqtTrace.Verbose("VsTestCommandLineWrapper: {0} {1}", info.FileName, info.Arguments);
mayankbansal018 marked this conversation as resolved.
Show resolved Hide resolved

process.Start();
process.EnableRaisingEvents = true;
process.Exited += Process_Exited;
process = Process.Start(info);

lock (syncObject)
{
vstestConsoleExited = false;
vstestConsoleStarted = true;
}

process.EnableRaisingEvents = true;
process.Exited += Process_Exited;

process.OutputDataReceived += Process_OutputDataReceived;
process.ErrorDataReceived += Process_ErrorDataReceived;
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}

/// <summary>
Expand All @@ -109,8 +118,10 @@ public void ShutdownProcess()
// Ideally process should die by itself
if (IsProcessInitialized())
{
this.process.Kill();
this.process.Dispose();
vstestConsoleExited = true;
rouke-broersma marked this conversation as resolved.
Show resolved Hide resolved
process.OutputDataReceived -= Process_OutputDataReceived;
process.ErrorDataReceived -= Process_ErrorDataReceived;
process.Dispose();
this.process = null;
}
}
Expand All @@ -119,26 +130,54 @@ private void Process_Exited(object sender, EventArgs e)
{
lock (syncObject)
{
vstestConsoleExited = true;
ShutdownProcess();

this.ProcessExited?.Invoke(sender, e);
}
}

private string[] BuildArguments(ConsoleParameters parameters)
private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
var args = new List<string>();
if (e.Data != null)
{
EqtTrace.Error(e.Data);
}
}

private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
EqtTrace.Verbose(e.Data);
}
}

// Start Vstest.console.exe with args: --parentProcessId|/parentprocessid:<ppid> --port|/port:<port>
args.Add(string.Format(CultureInfo.InvariantCulture, PARENT_PROCESSID_ARGUMENT, parameters.ParentProcessId));
args.Add(string.Format(CultureInfo.InvariantCulture, PORT_ARGUMENT, parameters.PortNumber));
private string[] BuildArguments(ConsoleParameters parameters)
{
var args = new List<string>
{
// Start Vstest.console with args: --parentProcessId|/parentprocessid:<ppid> --port|/port:<port>
string.Format(CultureInfo.InvariantCulture, PARENT_PROCESSID_ARGUMENT, parameters.ParentProcessId),
string.Format(CultureInfo.InvariantCulture, PORT_ARGUMENT, parameters.PortNumber)
};

if(!string.IsNullOrEmpty(parameters.LogFilePath))
if (!string.IsNullOrEmpty(parameters.LogFilePath))
{
// Extra args: --diag|/diag:<PathToLogFile>;tracelevel=<tracelevel>
args.Add(string.Format(CultureInfo.InvariantCulture, DIAG_ARGUMENT, parameters.LogFilePath, parameters.TraceLevel));
}

if (isNetCoreRunner)
{
args.Insert(0, vstestConsolePath);
}

return args.ToArray();
}

private string GetConsoleRunner()
{
return isNetCoreRunner ? DOTNET_EXECUTABLE : vstestConsolePath;
rouke-broersma marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@

namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests
{
using System.Collections.Generic;
using System.Linq;

using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Linq;

/// <summary>
/// The Run Tests using VsTestConsoleWrapper API's
/// </summary>
[TestClass]
public class CustomTestHostTests : AcceptanceTestBase
{
private const string Netcoreapp = "netcoreapp";
private const string Message = "VsTestConsoleWrapper donot support .Net Core Runner";

private IVsTestConsoleWrapper vstestConsoleWrapper;
private RunEventHandler runEventHandler;

Expand All @@ -41,7 +37,6 @@ public void Cleanup()
public void RunTestsWithCustomTestHostLaunch(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

var customTestHostLauncher = new CustomTestHostLauncher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@

namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Microsoft.TestPlatform.TestUtilities;
using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

/// <summary>
/// The Run Tests using VsTestConsoleWrapper API's
/// </summary>
[TestClass]
public class DifferentTestFrameworkSimpleTests : AcceptanceTestBase
{
private const string Netcoreapp = "netcoreapp";
private const string Message = "VsTestConsoleWrapper donot support .Net Core Runner";

private IVsTestConsoleWrapper vstestConsoleWrapper;
private RunEventHandler runEventHandler;

Expand All @@ -44,7 +40,6 @@ public void Cleanup()
public void RunTestsWithNunitAdapter(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

var sources = new List<string>
Expand Down Expand Up @@ -82,7 +77,6 @@ public void RunTestsWithNunitAdapter(RunnerInfo runnerInfo)
public void RunTestsWithXunitAdapter(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

// Xunit >= 2.2 won't support net451, Minimum target framework it supports is net452.
Expand Down Expand Up @@ -129,7 +123,6 @@ public void RunTestsWithXunitAdapter(RunnerInfo runnerInfo)
public void RunTestsWithChutzpahAdapter(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

var sources = new List<string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@

namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests
{
using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.TestPlatform.TestUtilities;
using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces;
using Microsoft.VisualStudio.TestPlatform.Common.Telemetry;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using VisualStudio.TestPlatform.ObjectModel.Logging;

[TestClass]
public class DiscoverTests : AcceptanceTestBase
{
private const string Netcoreapp = "netcoreapp";
private const string Message = "VsTestConsoleWrapper donot support .Net Core Runner";

private IVsTestConsoleWrapper vstestConsoleWrapper;
private DiscoveryEventHandler discoveryEventHandler;
private DiscoveryEventHandler2 discoveryEventHandler2;
Expand All @@ -44,7 +40,6 @@ public void DiscoverTestsUsingDiscoveryEventHandler1(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);

this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

this.vstestConsoleWrapper.DiscoverTests(this.GetTestAssemblies(), this.GetDefaultRunSettings(), this.discoveryEventHandler);
Expand All @@ -59,7 +54,6 @@ public void DiscoverTestsUsingDiscoveryEventHandler1(RunnerInfo runnerInfo)
public void DiscoverTestsUsingDiscoveryEventHandler2AndTelemetryOptedOut(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

this.vstestConsoleWrapper.DiscoverTests(
Expand All @@ -78,7 +72,6 @@ public void DiscoverTestsUsingDiscoveryEventHandler2AndTelemetryOptedOut(RunnerI
public void DiscoverTestsShouldFailForFramework35(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

string runSettingsXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
Expand Down Expand Up @@ -106,7 +99,6 @@ public void DiscoverTestsShouldFailForFramework35(RunnerInfo runnerInfo)
public void DiscoverTestsUsingDiscoveryEventHandler2AndTelemetryOptedIn(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

this.vstestConsoleWrapper.DiscoverTests(this.GetTestAssemblies(), this.GetDefaultRunSettings(), new TestPlatformOptions() { CollectMetrics = true }, this.discoveryEventHandler2);
Expand All @@ -126,7 +118,6 @@ public void DiscoverTestsUsingDiscoveryEventHandler2AndTelemetryOptedIn(RunnerIn
public void DiscoverTestsUsingEventHandler2AndBatchSize(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

var discoveryEventHandlerForBatchSize = new DiscoveryEventHandlerForBatchSize();
Expand Down Expand Up @@ -155,7 +146,6 @@ public void DiscoverTestsUsingEventHandler2AndBatchSize(RunnerInfo runnerInfo)
public void DiscoverTestsUsingEventHandler1AndBatchSize(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

var discoveryEventHandlerForBatchSize = new DiscoveryEventHandlerForBatchSize();
Expand Down Expand Up @@ -183,7 +173,6 @@ public void DiscoverTestsUsingEventHandler1AndBatchSize(RunnerInfo runnerInfo)
public void DiscoverTestsUsingSourceNavigation(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

this.vstestConsoleWrapper.DiscoverTests(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@

namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests
{
using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Linq;

[TestClass]
public class LiveUnitTestingTests : AcceptanceTestBase
{
private const string Netcoreapp = "netcoreapp";
private const string Message = "VsTestConsoleWrapper donot support .Net Core Runner";

private IVsTestConsoleWrapper vstestConsoleWrapper;
private DiscoveryEventHandler discoveryEventHandler;
private DiscoveryEventHandler2 discoveryEventHandler2;
Expand All @@ -43,7 +38,6 @@ public void Cleanup()
public void DiscoverTestsUsingLiveUnitTesting(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

string runSettingsXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
Expand All @@ -69,7 +63,6 @@ public void DiscoverTestsUsingLiveUnitTesting(RunnerInfo runnerInfo)
public void RunTestsWithLiveUnitTesting(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
this.Setup();

string runSettingsXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
Expand Down
Loading