@@ -49,51 +49,15 @@ public async Task<int> RunAsync()
49
49
Logger . LogTrace ( $ "Starting test process with command '{ processStartInfo . FileName } ' and arguments '{ processStartInfo . Arguments } '.") ;
50
50
51
51
using var process = Process . Start ( processStartInfo ) ! ;
52
- var standardOutput = process . StandardOutput ;
53
- var standardError = process . StandardError ;
54
-
55
- var tcsStdOutput = new TaskCompletionSource < string > ( ) ;
56
- var tcsStdError = new TaskCompletionSource < string > ( ) ;
57
52
58
53
// Reading from process stdout/stderr is done on separate threads to avoid blocking IO on the threadpool.
59
54
// Note: even with 'process.StandardOutput.ReadToEndAsync()' or 'process.BeginOutputReadLine()', we ended up with
60
55
// many TP threads just doing synchronous IO, slowing down the progress of the test run.
61
56
// We want to read requests coming through the pipe and sending responses back to the test app as fast as possible.
62
- var tStdOut = new Thread ( ( ) =>
63
- {
64
- StringBuilder ? builder = null ;
65
- while ( true )
66
- {
67
- if ( standardOutput . ReadLine ( ) is not { } line )
68
- {
69
- tcsStdOutput . SetResult ( builder ? . ToString ( ) ?? string . Empty ) ;
70
- return ;
71
- }
72
-
73
- ( builder ??= new ( ) ) . AppendLine ( line ) ;
74
- }
75
- } ) ;
76
- tStdOut . Name = "TestApp StdOut read" ;
77
- tStdOut . Start ( ) ;
78
-
79
- var tStdErr = new Thread ( ( ) =>
80
- {
81
- StringBuilder ? builder = null ;
82
- while ( true )
83
- {
84
- if ( standardError . ReadLine ( ) is not { } line )
85
- {
86
- tcsStdError . SetResult ( builder ? . ToString ( ) ?? string . Empty ) ;
87
- return ;
88
- }
89
-
90
- ( builder ??= new ( ) ) . AppendLine ( line ) ;
91
- }
92
- } ) ;
93
- tStdErr . Name = "TestApp StdErr read" ;
94
- tStdErr . Start ( ) ;
57
+ var stdOutTask = Task . Factory . StartNew ( static standardOutput => ( ( StreamReader ) standardOutput ! ) . ReadToEnd ( ) , process . StandardOutput , TaskCreationOptions . LongRunning ) ;
58
+ var stdErrTask = Task . Factory . StartNew ( static standardError => ( ( StreamReader ) standardError ! ) . ReadToEnd ( ) , process . StandardError , TaskCreationOptions . LongRunning ) ;
95
59
96
- var outputAndError = await Task . WhenAll ( tcsStdOutput . Task , tcsStdError . Task ) ;
60
+ var outputAndError = await Task . WhenAll ( stdOutTask , stdErrTask ) ;
97
61
await process . WaitForExitAsync ( ) ;
98
62
99
63
_handler . OnTestProcessExited ( process . ExitCode , outputAndError [ 0 ] , outputAndError [ 1 ] ) ;
0 commit comments