Skip to content

Commit fb0bd1f

Browse files
committed
Add more gRPC interop test logging
1 parent b80c0c4 commit fb0bd1f

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public ClientProcess(ITestOutputHelper output, string path, string serverPort, s
3131
_process.EnableRaisingEvents = true;
3232
_process.OutputDataReceived += Process_OutputDataReceived;
3333
_process.ErrorDataReceived += Process_ErrorDataReceived;
34+
35+
output.WriteLine($"Starting process: {ProcessDebugHelper.GetDebugCommand(_process.StartInfo)}");
3436
_process.Start();
3537

3638
_processEx = new ProcessEx(output, _process, timeout: Timeout.InfiniteTimeSpan);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics;
5+
6+
namespace InteropTests.Helpers;
7+
8+
public static class ProcessDebugHelper
9+
{
10+
public static string GetDebugCommand(ProcessStartInfo psi)
11+
{
12+
// Quote the file name if it contains spaces or special characters
13+
string fileName = QuoteIfNeeded(psi.FileName);
14+
15+
// Arguments are typically already passed as a single string
16+
string arguments = psi.Arguments;
17+
18+
return $"{fileName} {arguments}".Trim();
19+
}
20+
21+
private static string QuoteIfNeeded(string value)
22+
{
23+
if (string.IsNullOrWhiteSpace(value)) return "\"\"";
24+
25+
// Add quotes if value contains spaces or special characters
26+
if (value.Contains(" ") || value.Contains("\""))
27+
{
28+
return $"\"{value.Replace("\"", "\\\"")}\"";
29+
}
30+
31+
return value;
32+
}
33+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public WebsiteProcess(string path, ITestOutputHelper output)
3636
_process.EnableRaisingEvents = true;
3737
_process.OutputDataReceived += Process_OutputDataReceived;
3838
_process.ErrorDataReceived += Process_ErrorDataReceived;
39+
40+
output.WriteLine($"Starting process: {ProcessDebugHelper.GetDebugCommand(_process.StartInfo)}");
3941
_process.Start();
4042

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

src/Grpc/Interop/test/InteropTests/InteropTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ public InteropTests(ITestOutputHelper output)
8383

8484
private async Task InteropTestCase(string name)
8585
{
86+
_output.WriteLine($"Starting {nameof(WebsiteProcess)}.");
8687
using (var serverProcess = new WebsiteProcess(_serverPath, _output))
8788
{
8889
try
8990
{
91+
_output.WriteLine($"Waiting for {nameof(WebsiteProcess)} to be ready.");
9092
await serverProcess.WaitForReady().TimeoutAfter(DefaultTimeout);
9193
}
9294
catch (Exception ex)
@@ -102,12 +104,15 @@ private async Task InteropTestCase(string name)
102104
throw new InvalidOperationException(errorMessage, ex);
103105
}
104106

107+
_output.WriteLine($"Starting {nameof(ClientProcess)}.");
105108
using (var clientProcess = new ClientProcess(_output, _clientPath, serverProcess.ServerPort, name))
106109
{
107110
try
108111
{
112+
_output.WriteLine($"Waiting for {nameof(ClientProcess)} to be ready.");
109113
await clientProcess.WaitForReadyAsync().TimeoutAfter(DefaultTimeout);
110114

115+
_output.WriteLine($"Waiting for {nameof(ClientProcess)} to exit.");
111116
await clientProcess.WaitForExitAsync().TimeoutAfter(DefaultTimeout);
112117

113118
Assert.Equal(0, clientProcess.ExitCode);

0 commit comments

Comments
 (0)