Skip to content

Commit 3dc39cc

Browse files
authored
Improve gRPC interop test failure logging (#22856)
1 parent 348d695 commit 3dc39cc

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

src/Grpc/test/InteropTests/Helpers/ClientProcess.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public ClientProcess(ITestOutputHelper output, string path, string serverPort, s
4444
public Task WaitForReadyAsync() => _startTcs.Task;
4545
public Task WaitForExitAsync() => _processEx.Exited;
4646
public int ExitCode => _process.ExitCode;
47+
public bool IsReady => _startTcs.Task.IsCompletedSuccessfully;
4748

4849
public string GetOutput()
4950
{
@@ -77,7 +78,7 @@ private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
7778
{
7879
lock (_outputLock)
7980
{
80-
_output.AppendLine(data);
81+
_output.AppendLine("ERROR: " + data);
8182
}
8283
}
8384
}

src/Grpc/test/InteropTests/Helpers/WebsiteProcess.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics;
6+
using System.Text;
67
using System.Text.RegularExpressions;
78
using System.Threading;
89
using System.Threading.Tasks;
@@ -17,11 +18,16 @@ public class WebsiteProcess : IDisposable
1718
private readonly ProcessEx _processEx;
1819
private readonly TaskCompletionSource<object> _startTcs;
1920
private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: .*:(?<port>\d*)$");
21+
private readonly StringBuilder _output;
22+
private readonly object _outputLock = new object();
2023

2124
public string ServerPort { get; private set; }
25+
public bool IsReady => _startTcs.Task.IsCompletedSuccessfully;
2226

2327
public WebsiteProcess(string path, ITestOutputHelper output)
2428
{
29+
_output = new StringBuilder();
30+
2531
_process = new Process();
2632
_process.StartInfo = new ProcessStartInfo
2733
{
@@ -32,13 +38,22 @@ public WebsiteProcess(string path, ITestOutputHelper output)
3238
};
3339
_process.EnableRaisingEvents = true;
3440
_process.OutputDataReceived += Process_OutputDataReceived;
41+
_process.ErrorDataReceived += Process_ErrorDataReceived;
3542
_process.Start();
3643

3744
_processEx = new ProcessEx(output, _process, Timeout.InfiniteTimeSpan);
3845

3946
_startTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
4047
}
4148

49+
public string GetOutput()
50+
{
51+
lock (_outputLock)
52+
{
53+
return _output.ToString();
54+
}
55+
}
56+
4257
public Task WaitForReady()
4358
{
4459
if (_processEx.HasExited)
@@ -64,6 +79,23 @@ private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
6479
{
6580
_startTcs.TrySetResult(null);
6681
}
82+
83+
lock (_outputLock)
84+
{
85+
_output.AppendLine(data);
86+
}
87+
}
88+
}
89+
90+
private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
91+
{
92+
var data = e.Data;
93+
if (data != null)
94+
{
95+
lock (_outputLock)
96+
{
97+
_output.AppendLine("ERROR: " + data);
98+
}
6799
}
68100
}
69101

src/Grpc/test/InteropTests/InteropTests.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,20 @@ private async Task InteropTestCase(string name)
103103
}
104104
catch (Exception ex)
105105
{
106-
var clientOutput = clientProcess.GetOutput();
107-
var errorMessage = $@"Error while running client process. Process output:
106+
var errorMessage = $@"Error while running client process.
107+
108+
Server ready: {serverProcess.IsReady}
109+
Client ready: {clientProcess.IsReady}
110+
111+
Server process output:
112+
======================================
113+
{serverProcess.GetOutput()}
114+
======================================
115+
116+
Client process output:
108117
======================================
109-
{clientOutput}";
118+
{clientProcess.GetOutput()}
119+
======================================";
110120
throw new InvalidOperationException(errorMessage, ex);
111121
}
112122
}

src/Grpc/test/testassets/InteropWebsite/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Microsoft.AspNetCore.Server.Kestrel.Core;
2323
using Microsoft.Extensions.Configuration;
2424
using Microsoft.Extensions.Hosting;
25+
using Microsoft.Extensions.Logging;
2526

2627
namespace InteropTestsWebsite
2728
{
@@ -34,6 +35,11 @@ public static void Main(string[] args)
3435

3536
public static IHostBuilder CreateHostBuilder(string[] args) =>
3637
Host.CreateDefaultBuilder(args)
38+
.ConfigureLogging(builder =>
39+
{
40+
builder.AddConsole();
41+
builder.SetMinimumLevel(LogLevel.Trace);
42+
})
3743
.ConfigureWebHostDefaults(webBuilder =>
3844
{
3945
webBuilder.ConfigureKestrel((context, options) =>

0 commit comments

Comments
 (0)