Skip to content

Commit be10c36

Browse files
read session data from file
1 parent b876e30 commit be10c36

File tree

1 file changed

+17
-33
lines changed

1 file changed

+17
-33
lines changed

test/PowerShellEditorServices.Test.Host/ServerTestsBase.cs

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Diagnostics;
1212
using System.IO;
1313
using System.Text;
14+
using System.Threading;
1415
using System.Threading.Tasks;
1516

1617
namespace Microsoft.PowerShell.EditorServices.Test.Host
@@ -35,12 +36,15 @@ protected async Task<Tuple<int, int>> LaunchService(
3536
string scriptPath = Path.Combine(modulePath, "Start-EditorServices.ps1");
3637

3738
#if CoreCLR
39+
string assemblyPath = this.GetType().GetTypeInfo().Assembly.Location;
3840
FileVersionInfo fileVersionInfo =
39-
FileVersionInfo.GetVersionInfo(this.GetType().GetTypeInfo().Assembly.Location);
41+
FileVersionInfo.GetVersionInfo(assemblyPath);
4042
#else
43+
string assemblyPath = this.GetType().Assembly.Location;
4144
FileVersionInfo fileVersionInfo =
42-
FileVersionInfo.GetVersionInfo(this.GetType().Assembly.Location);
45+
FileVersionInfo.GetVersionInfo(assemblyPath);
4346
#endif
47+
string sessionPath = Path.Combine(Path.GetDirectoryName(assemblyPath), "session.json");
4448

4549
string editorServicesModuleVersion =
4650
string.Format(
@@ -59,7 +63,7 @@ protected async Task<Tuple<int, int>> LaunchService(
5963
"-BundledModulesPath \\\"" + modulePath + "\\\" " +
6064
"-LogLevel \"Verbose\" " +
6165
"-LogPath \"" + logPath + "\" " +
62-
"-SessionDetailsPath \".\\sessionDetails\" " +
66+
"-SessionDetailsPath \"" + sessionPath + "\" " +
6367
"-FeatureFlags @() " +
6468
"-AdditionalModules @() ",
6569
editorServicesModuleVersion);
@@ -98,40 +102,20 @@ protected async Task<Tuple<int, int>> LaunchService(
98102
this.serviceProcess.Start();
99103

100104
// Wait for the server to finish initializing
101-
Task<string> stdoutTask = this.serviceProcess.StandardOutput.ReadLineAsync();
102-
Task<string> stderrTask = this.serviceProcess.StandardError.ReadLineAsync();
103-
Task<string> completedRead = await Task.WhenAny<string>(stdoutTask, stderrTask);
104-
105-
if (completedRead == stdoutTask)
105+
while(!File.Exists(sessionPath))
106106
{
107-
JObject result = JObject.Parse(completedRead.Result);
108-
if (result["status"].Value<string>() == "started")
109-
{
110-
return new Tuple<int, int>(
111-
result["languageServicePort"].Value<int>(),
112-
result["debugServicePort"].Value<int>());
113-
}
114-
115-
return null;
107+
Thread.Sleep(100);
116108
}
117-
else
118-
{
119-
// Must have read an error? Keep reading from error stream
120-
string errorString = completedRead.Result;
121-
Task<string> errorRead = this.serviceProcess.StandardError.ReadToEndAsync();
122109

123-
// Lets give the read operation 5 seconds to complete. Ideally, it shouldn't
124-
// take that long at all, but just in case...
125-
if (errorRead.Wait(5000))
126-
{
127-
if (!string.IsNullOrEmpty(errorRead.Result))
128-
{
129-
errorString += errorRead.Result + Environment.NewLine;
130-
}
131-
}
132-
133-
throw new Exception("Could not launch powershell.exe:\r\n\r\n" + errorString);
110+
JObject result = JObject.Parse(File.ReadAllText(sessionPath));
111+
if (result["status"].Value<string>() == "started")
112+
{
113+
return new Tuple<int, int>(
114+
result["languageServicePort"].Value<int>(),
115+
result["debugServicePort"].Value<int>());
134116
}
117+
118+
return null;
135119
}
136120

137121
protected void KillService()

0 commit comments

Comments
 (0)