Skip to content

Add support for running xUnit tests in VS Test Explorer #642

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

Merged
merged 1 commit into from
Mar 23, 2018
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 @@ -825,7 +825,9 @@ await this.SendRequest(
Assert.StartsWith("5.", versionDetails.Version);
Assert.StartsWith("5.", versionDetails.DisplayVersion);
Assert.Equal("Desktop", versionDetails.Edition);
Assert.Equal("x86", versionDetails.Architecture);

string expectedArchitecture = (IntPtr.Size == 8) ? "x64" : "x86";
Copy link
Member

Choose a reason for hiding this comment

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

This will eventually be a problem when we want to run the tests on Non-Windows because on macOS x64 is represented as x86_64

Copy link
Member

Choose a reason for hiding this comment

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

but that can be dealt with later. I see we have an Assert.StartsWith just a few lines up that mentions version 5 so we'll have to deal with that too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The PowerShellVersionDetails.Architecture property is an enum with only these values: Unknown, x86, x64. So I think it is OK represent a 64-bit macOS Architecture as x64. Besides the version number, the only other place this info is used is to send back to the extension. And it does get logged. Even the log chooses to represent the Architecture.x64 val as simply 64-bit:

        Version: Microsoft Windows NT 10.0.16299.0
        Arch:    64-bit

In this regard, I like the IntPtr.Size test better than looking at env vars.

Assert.Equal(expectedArchitecture, versionDetails.Architecture);
}

private async Task SendOpenFileEvent(string filePath, bool waitForDiagnostics = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageReference Include="Microsoft.PowerShell.SDK">
<Version>6.0.0-alpha13</Version>
</PackageReference>
<PackageReference Include="more.xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="xunit" Version="2.3.0-beta4-build3742" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" />
</ItemGroup>
Expand Down
35 changes: 31 additions & 4 deletions test/PowerShellEditorServices.Test.Host/ServerTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ protected async Task<Tuple<int, int>> LaunchService(
Path.Combine(
Path.GetDirectoryName(assemblyPath), $"session-{++sessionCounter}.json");

if (File.Exists(sessionPath))
{
File.Delete(sessionPath);
}

string editorServicesModuleVersion =
string.Format(
"{0}.{1}.{2}",
Expand Down Expand Up @@ -106,20 +111,42 @@ protected async Task<Tuple<int, int>> LaunchService(
// Start the process
this.serviceProcess.Start();

// Wait for the server to finish initializing
while (!File.Exists(sessionPath) || (new FileInfo(sessionPath).Length == 0))
string sessionDetailsText = string.Empty;

// Wait up to ~5 seconds for the server to finish initializing
var maxRetryAttempts = 10;
while (maxRetryAttempts-- > 0)
{
Thread.Sleep(100);
try
{
using (var stream = new FileStream(sessionPath, FileMode.Open, FileAccess.Read, FileShare.None))
using (var reader = new StreamReader(stream))
{
sessionDetailsText = reader.ReadToEnd();
break;
}
}
catch (FileNotFoundException)
{
}
catch (Exception ex)
{
Debug.WriteLine($"Session details at '{sessionPath}' not available: {ex.Message}");
}

Thread.Sleep(500);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW I timed this while loop in the debugger using VS perf tips and the time to read the file varied between about 350 ms to 1.2 secs so I figured 500 ms was a reasonable sleep time to cut down on the number of retries.

}

JObject result = JObject.Parse(File.ReadAllText(sessionPath));
JObject result = JObject.Parse(sessionDetailsText);
if (result["status"].Value<string>() == "started")
{
return new Tuple<int, int>(
result["languageServicePort"].Value<int>(),
result["debugServicePort"].Value<int>());
}

Debug.WriteLine($"Failed to read session details from '{sessionPath}'");

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="more.xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Newtonsoft.Json">
<Version>9.0.1</Version>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.PowerShell.SDK">
<Version>6.0.0-alpha13</Version>
</PackageReference>
<PackageReference Include="more.xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="xunit" Version="2.3.0-beta4-build3742" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" />
</ItemGroup>
Expand Down