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

Fix RemoteExecutor for VS testhost #7426

Merged
merged 8 commits into from
May 24, 2021
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
30 changes: 29 additions & 1 deletion src/Microsoft.DotNet.RemoteExecutor/src/RemoteExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Xunit;
using IOPath = System.IO.Path;
Copy link
Member

Choose a reason for hiding this comment

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

Why not just use using System.IO; and Path?

Copy link
Member Author

Choose a reason for hiding this comment

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

RemoteExecutor has a field named Path.


namespace Microsoft.DotNet.RemoteExecutor
{
Expand Down Expand Up @@ -51,17 +52,44 @@ static RemoteExecutor()
return;
}

HostRunnerName = System.IO.Path.GetFileName(processFileName);
Path = typeof(RemoteExecutor).Assembly.Location;

if (IsNetCore())
{
HostRunner = processFileName;

string hostName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "dotnet.exe" : "dotnet";

// Partially addressing https://github.com/dotnet/arcade/issues/6371
// We expect to run tests with dotnet. However in certain scenarios we may have a different apphost (e.g. Visual Studio testhost).
// Attempt to find and use dotnet.
if (!IOPath.GetFileName(HostRunner).Equals(hostName, StringComparison.OrdinalIgnoreCase))
{
string runtimePath = IOPath.GetDirectoryName(typeof(object).Assembly.Location);

// In case we are running the app via a runtime, dotnet.exe is located 3 folders above the runtime. Example:
// runtime -> C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.6\
// dotnet.exe -> C:\Program Files\dotnet\shared\dotnet.exe
// This should also work on Unix and locally built runtime/testhost.
string directory = GetDirectoryName(GetDirectoryName(GetDirectoryName(runtimePath)));
if (directory != string.Empty)
RussKie marked this conversation as resolved.
Show resolved Hide resolved
{
string dotnetExe = IOPath.Combine(directory, hostName);
if (File.Exists(dotnetExe))
{
HostRunner = dotnetExe;
}
}
}
}
else if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase))
{
HostRunner = Path;
}

HostRunnerName = IOPath.GetFileName(HostRunner);

static string GetDirectoryName(string path) => string.IsNullOrEmpty(path) ? string.Empty : IOPath.GetDirectoryName(path);
}

private static bool IsNetCore() =>
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.DotNet.RemoteExecutor/tests/RemoteExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.DotNet.RemoteExecutor.Tests
{
public class RemoteExecutorTests
{
[Fact(Skip = "Remote executor is broken in VS test explorer")]
[Fact]
public void AsyncAction_ThrowException()
{
Assert.Throws<RemoteExecutionException>(() =>
Expand All @@ -22,7 +22,7 @@ public void AsyncAction_ThrowException()
);
}

[Fact(Skip = "Remote executor is broken in VS test explorer")]
[Fact]
public void AsyncAction()
{
RemoteExecutor.Invoke(async () =>
Expand All @@ -31,7 +31,7 @@ public void AsyncAction()
}, new RemoteInvokeOptions { RollForward = "Major" }).Dispose();
}

[Fact(Skip = "Remote executor is broken in VS test explorer")]
[Fact]
public void AsyncFunc_ThrowException()
{
Assert.Throws<RemoteExecutionException>(() =>
Expand All @@ -44,7 +44,7 @@ public void AsyncFunc_ThrowException()
);
}

[Fact(Skip = "Remote executor is broken in VS test explorer")]
[Fact]
public void AsyncFunc_InvalidReturnCode()
{
Assert.Throws<TrueException>(() =>
Expand All @@ -56,7 +56,7 @@ public void AsyncFunc_InvalidReturnCode()
);
}

[Fact(Skip = "Remote executor is broken in VS test explorer")]
[Fact]
public void AsyncFunc_NoThrow_ValidReturnCode()
{
RemoteExecutor.Invoke(async () =>
Expand Down