Skip to content

Commit 07fb743

Browse files
committed
TEMP: Testing again...
1 parent 2581eb0 commit 07fb743

File tree

2 files changed

+67
-58
lines changed

2 files changed

+67
-58
lines changed

test/PowerShellEditorServices.Test.Host/LanguageServerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,6 @@ await requestContext.SendResult(
538538
ResponseText = "John"
539539
});
540540

541-
// Wait for execution to complete
542-
await evaluateTask;
543-
544541
// Skip the initial script lines (4 script lines plus 2 blank lines)
545542
string[] scriptLines = await outputReader.ReadLines(6);
546543

@@ -563,6 +560,9 @@ await requestContext.SendResult(
563560
Assert.Equal("Key Value", outputLines[1]);
564561
Assert.Equal("--- -----", outputLines[2]);
565562
Assert.Equal("Name John ", outputLines[3]);
563+
564+
// Wait for execution to complete
565+
await evaluateTask;
566566
}
567567

568568
private async Task SendOpenFileEvent(string filePath, bool waitForDiagnostics = true)

test/PowerShellEditorServices.Test.Host/OutputReader.cs

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -32,71 +32,80 @@ public OutputReader(ProtocolEndpoint protocolClient)
3232

3333
public async Task<string> ReadLine(string expectedOutputCategory = "stdout")
3434
{
35-
bool lineHasNewLine = false;
36-
string[] outputLines = null;
37-
string nextOutputString = string.Empty;
35+
try
36+
{
37+
bool lineHasNewLine = false;
38+
string[] outputLines = null;
39+
string nextOutputString = string.Empty;
3840

39-
// Wait no longer than 5 seconds for output to come back
40-
CancellationTokenSource cancellationSource = new CancellationTokenSource(5000);
41+
// Wait no longer than 7 seconds for output to come back
42+
CancellationTokenSource cancellationSource = new CancellationTokenSource(7000);
4143

42-
if (this.bufferedOutput.Count > 0)
43-
{
44-
Assert.Equal(expectedOutputCategory, this.currentOutputCategory);
44+
// Any lines in the buffer?
45+
if (this.bufferedOutput.Count > 0)
46+
{
47+
Assert.Equal(expectedOutputCategory, this.currentOutputCategory);
4548

46-
// Return the first buffered line
47-
var lineTuple = this.bufferedOutput.Dequeue();
48-
nextOutputString = lineTuple.Item1;
49-
lineHasNewLine = lineTuple.Item2;
50-
}
49+
// Return the first buffered line
50+
var lineTuple = this.bufferedOutput.Dequeue();
51+
nextOutputString = lineTuple.Item1;
52+
lineHasNewLine = lineTuple.Item2;
53+
}
5154

52-
// Loop until we get a full line of output
53-
while (!lineHasNewLine)
54-
{
55-
// Execution reaches this point if a buffered line wasn't available
56-
OutputEventBody nextOutputEvent =
57-
await this.outputQueue.DequeueAsync(
58-
cancellationSource.Token);
59-
60-
// Verify that the output is of the expected type
61-
Assert.Equal(expectedOutputCategory, nextOutputEvent.Category);
62-
this.currentOutputCategory = nextOutputEvent.Category;
63-
64-
// Split up the output into multiple lines
65-
outputLines =
66-
nextOutputEvent.Output.Split(
67-
new string[] { "\n", "\r\n" },
68-
StringSplitOptions.None);
69-
70-
// Add the first bit of output to the existing string
71-
nextOutputString += outputLines[0];
72-
73-
// Have we found a newline now?
74-
lineHasNewLine =
75-
outputLines.Length > 1 ||
76-
nextOutputEvent.Output.EndsWith("\n");
77-
78-
// Buffer any remaining lines for future reads
79-
if (outputLines.Length > 1)
55+
// Loop until we get a full line of output
56+
while (!lineHasNewLine)
8057
{
81-
for (int i = 1; i < outputLines.Length; i++)
58+
// Execution reaches this point if a buffered line wasn't available
59+
Task<OutputEventBody> outputTask =
60+
this.outputQueue.DequeueAsync(
61+
cancellationSource.Token);
62+
OutputEventBody nextOutputEvent = await outputTask;
63+
64+
// Verify that the output is of the expected type
65+
Assert.Equal(expectedOutputCategory, nextOutputEvent.Category);
66+
this.currentOutputCategory = nextOutputEvent.Category;
67+
68+
// Split up the output into multiple lines
69+
outputLines =
70+
nextOutputEvent.Output.Split(
71+
new string[] { "\n", "\r\n" },
72+
StringSplitOptions.None);
73+
74+
// Add the first bit of output to the existing string
75+
nextOutputString += outputLines[0];
76+
77+
// Have we found a newline now?
78+
lineHasNewLine =
79+
outputLines.Length > 1 ||
80+
nextOutputEvent.Output.EndsWith("\n");
81+
82+
// Buffer any remaining lines for future reads
83+
if (outputLines.Length > 1)
8284
{
83-
this.bufferedOutput.Enqueue(
84-
new Tuple<string, bool>(
85-
outputLines[i],
86-
87-
// The line has a newline if it's not the last segment or
88-
// if the current output string ends with a newline
89-
i < outputLines.Length - 1 ||
90-
nextOutputEvent.Output.EndsWith("\n")));
85+
for (int i = 1; i < outputLines.Length; i++)
86+
{
87+
this.bufferedOutput.Enqueue(
88+
new Tuple<string, bool>(
89+
outputLines[i],
90+
91+
// The line has a newline if it's not the last segment or
92+
// if the current output string ends with a newline
93+
i < outputLines.Length - 1 ||
94+
nextOutputEvent.Output.EndsWith("\n")));
95+
}
9196
}
97+
98+
// At this point, the state of lineHasNewLine will determine
99+
// whether the loop continues to wait for another output
100+
// event that completes the current line.
92101
}
93102

94-
// At this point, the state of lineHasNewLine will determine
95-
// whether the loop continues to wait for another output
96-
// event that completes the current line.
103+
return nextOutputString;
104+
}
105+
catch (TaskCanceledException)
106+
{
107+
throw new TimeoutException("Timed out waiting for an input line.");
97108
}
98-
99-
return nextOutputString;
100109
}
101110

102111
public async Task<string[]> ReadLines(int lineCount, string expectedOutputCategory = "stdout")

0 commit comments

Comments
 (0)