Skip to content

Commit ef64033

Browse files
Kapil Borledaviwil
Kapil Borle
authored andcommitted
Remove while loop used for reading error stream
Whenever EditorServices fails to start up, ServerTestsBase.LaunchService goes into a while loop where it reads from the error stream line by line in an async manner, till the end of the stream. This causes the method to wait indefinitely in certain situations. Hence, we replace it with ReadToEndAsync method and time out on the task if it takes too long. This avoids the test cases from hanging at that point.
1 parent d779553 commit ef64033

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

test/PowerShellEditorServices.Test.Host/ServerTestsBase.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,16 @@ protected async Task<Tuple<int, int>> LaunchService(
102102
{
103103
// Must have read an error? Keep reading from error stream
104104
string errorString = completedRead.Result;
105+
Task<string> errorRead = this.serviceProcess.StandardError.ReadToEndAsync();
105106

106-
while (true)
107+
// Lets give the read operation 5 seconds to complete. Ideally, it shouldn't
108+
// take that long at all, but just in case...
109+
if (errorRead.Wait(5000))
107110
{
108-
Task<string> errorRead = this.serviceProcess.StandardError.ReadLineAsync();
109-
110111
if (!string.IsNullOrEmpty(errorRead.Result))
111112
{
112113
errorString += errorRead.Result + Environment.NewLine;
113114
}
114-
else
115-
{
116-
break;
117-
}
118115
}
119116

120117
throw new Exception("Could not launch powershell.exe:\r\n\r\n" + errorString);

0 commit comments

Comments
 (0)