Improve gRPC interop test failure logging (#22856)
This commit is contained in:
parent
348d69558a
commit
3dc39cc2dc
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<object> _startTcs;
|
||||
private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: .*:(?<port>\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<object>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) =>
|
||||
|
|
|
|||
Loading…
Reference in New Issue