Skip to content

Commit 3d8a322

Browse files
authored
Fix issue with checking if session file available
Change to check length of sessionPath file and only if file exists test passes. Update to use CodeBase which is the original location of the file under bin dir. Location is in the temp dir when run under xUnit.
1 parent 9921019 commit 3d8a322

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

test/PowerShellEditorServices.Test.Host/ServerTestsBase.cs

+11-9
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
using System.Collections.Concurrent;
1111
using System.Diagnostics;
1212
using System.IO;
13-
#if CoreCLR
1413
using System.Reflection;
15-
#endif
1614
using System.Text;
1715
using System.Threading;
1816
using System.Threading.Tasks;
@@ -21,6 +19,7 @@ namespace Microsoft.PowerShell.EditorServices.Test.Host
2119
{
2220
public class ServerTestsBase
2321
{
22+
private static int sessionCounter;
2423
private Process serviceProcess;
2524
protected IMessageSender messageSender;
2625
protected IMessageHandlers messageHandlers;
@@ -39,15 +38,18 @@ protected async Task<Tuple<int, int>> LaunchService(
3938
string scriptPath = Path.Combine(modulePath, "Start-EditorServices.ps1");
4039

4140
#if CoreCLR
42-
string assemblyPath = this.GetType().GetTypeInfo().Assembly.Location;
43-
FileVersionInfo fileVersionInfo =
44-
FileVersionInfo.GetVersionInfo(assemblyPath);
41+
Assembly assembly = this.GetType().GetTypeInfo().Assembly;
4542
#else
46-
string assemblyPath = this.GetType().Assembly.Location;
43+
Assembly assembly = this.GetType().Assembly;
44+
#endif
45+
46+
string assemblyPath = new Uri(assembly.CodeBase).LocalPath;
4747
FileVersionInfo fileVersionInfo =
4848
FileVersionInfo.GetVersionInfo(assemblyPath);
49-
#endif
50-
string sessionPath = Path.Combine(Path.GetDirectoryName(assemblyPath), "session.json");
49+
50+
string sessionPath =
51+
Path.Combine(
52+
Path.GetDirectoryName(assemblyPath), $"session-{++sessionCounter}.json");
5153

5254
string editorServicesModuleVersion =
5355
string.Format(
@@ -105,7 +107,7 @@ protected async Task<Tuple<int, int>> LaunchService(
105107
this.serviceProcess.Start();
106108

107109
// Wait for the server to finish initializing
108-
while(!File.Exists(sessionPath) && new FileInfo(assemblyPath).Length > 0)
110+
while (!File.Exists(sessionPath) || (new FileInfo(sessionPath).Length == 0))
109111
{
110112
Thread.Sleep(100);
111113
}

0 commit comments

Comments
 (0)