diff --git a/src/Grpc/test/InteropTests/Helpers/ClientProcess.cs b/src/Grpc/test/InteropTests/Helpers/ClientProcess.cs index 9d3e982661..ec095eb3f8 100644 --- a/src/Grpc/test/InteropTests/Helpers/ClientProcess.cs +++ b/src/Grpc/test/InteropTests/Helpers/ClientProcess.cs @@ -44,6 +44,7 @@ namespace InteropTests.Helpers public Task WaitForReadyAsync() => _startTcs.Task; public Task WaitForExitAsync() => _processEx.Exited; public int ExitCode => _process.ExitCode; + public bool IsReady => _startTcs.Task.IsCompletedSuccessfully; public string GetOutput() { @@ -77,7 +78,7 @@ namespace InteropTests.Helpers { lock (_outputLock) { - _output.AppendLine(data); + _output.AppendLine("ERROR: " + data); } } } diff --git a/src/Grpc/test/InteropTests/Helpers/WebsiteProcess.cs b/src/Grpc/test/InteropTests/Helpers/WebsiteProcess.cs index 7b0386df2a..7018fb5bdc 100644 --- a/src/Grpc/test/InteropTests/Helpers/WebsiteProcess.cs +++ b/src/Grpc/test/InteropTests/Helpers/WebsiteProcess.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -17,11 +18,16 @@ namespace InteropTests.Helpers private readonly ProcessEx _processEx; private readonly TaskCompletionSource _startTcs; private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: .*:(?\d*)$"); + private readonly StringBuilder _output; + private readonly object _outputLock = new object(); public string ServerPort { get; private set; } + public bool IsReady => _startTcs.Task.IsCompletedSuccessfully; public WebsiteProcess(string path, ITestOutputHelper output) { + _output = new StringBuilder(); + _process = new Process(); _process.StartInfo = new ProcessStartInfo { @@ -32,6 +38,7 @@ namespace InteropTests.Helpers }; _process.EnableRaisingEvents = true; _process.OutputDataReceived += Process_OutputDataReceived; + _process.ErrorDataReceived += Process_ErrorDataReceived; _process.Start(); _processEx = new ProcessEx(output, _process, Timeout.InfiniteTimeSpan); @@ -39,6 +46,14 @@ namespace InteropTests.Helpers _startTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); } + public string GetOutput() + { + lock (_outputLock) + { + return _output.ToString(); + } + } + public Task WaitForReady() { if (_processEx.HasExited) @@ -64,6 +79,23 @@ namespace InteropTests.Helpers { _startTcs.TrySetResult(null); } + + lock (_outputLock) + { + _output.AppendLine(data); + } + } + } + + private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e) + { + var data = e.Data; + if (data != null) + { + lock (_outputLock) + { + _output.AppendLine("ERROR: " + data); + } } } diff --git a/src/Grpc/test/InteropTests/InteropTests.cs b/src/Grpc/test/InteropTests/InteropTests.cs index 957fa3676d..802c7006d9 100644 --- a/src/Grpc/test/InteropTests/InteropTests.cs +++ b/src/Grpc/test/InteropTests/InteropTests.cs @@ -103,10 +103,20 @@ namespace InteropTests } catch (Exception ex) { - var clientOutput = clientProcess.GetOutput(); - var errorMessage = $@"Error while running client process. Process output: + var errorMessage = $@"Error while running client process. + +Server ready: {serverProcess.IsReady} +Client ready: {clientProcess.IsReady} + +Server process output: ====================================== -{clientOutput}"; +{serverProcess.GetOutput()} +====================================== + +Client process output: +====================================== +{clientProcess.GetOutput()} +======================================"; throw new InvalidOperationException(errorMessage, ex); } } diff --git a/src/Grpc/test/testassets/InteropWebsite/Program.cs b/src/Grpc/test/testassets/InteropWebsite/Program.cs index fffaf75c55..e160254f5d 100644 --- a/src/Grpc/test/testassets/InteropWebsite/Program.cs +++ b/src/Grpc/test/testassets/InteropWebsite/Program.cs @@ -22,6 +22,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; namespace InteropTestsWebsite { @@ -34,6 +35,11 @@ namespace InteropTestsWebsite public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) + .ConfigureLogging(builder => + { + builder.AddConsole(); + builder.SetMinimumLevel(LogLevel.Trace); + }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.ConfigureKestrel((context, options) =>