Skip to content

Commit b6e31df

Browse files
Add standard output and error when a test fails and does not display it (#7847)
## Summary of changes We get [some CI errors ](https://dev.azure.com/datadoghq/dd-trace-dotnet/_build/results?buildId=191248&view=logs&j=5635f724-ec42-5e82-7816-fb263b6cfcc0&t=e80b9b00-921f-539a-741c-f91926c040ef)in tests caused by a non 0 exit code from a sample but we get no output from the sample itself. This PR improves error reporting when tests fail due to non-zero exit codes by ensuring that process stdout and stderr are logged to the test output before assertions fail. This makes debugging CI failures significantly easier, especially for signal-related crashes (SIGABRT, SIGSEGV, etc.). ## Reason for change ## Implementation details ## Test coverage ## Other details <!-- Fixes #{issue} --> <!-- ⚠️ Note: Where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. MergeQueue is NOT enabled in this repository. If you have write access to the repo, the PR has 1-2 approvals (see above), and all of the required checks have passed, you can use the Squash and Merge button to merge the PR. If you don't have write access, or you need help, reach out in the #apm-dotnet channel in Slack. -->
1 parent c6a2350 commit b6e31df

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

profiler/test/Datadog.Profiler.IntegrationTests/Helpers/TestApplicationRunner.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,16 @@ private void RunTest(MockDatadogAgent agent)
235235
throw new XunitException("An error occured during the test. See the error output above.");
236236
}
237237

238-
Assert.True(
239-
0 == process.ExitCode,
240-
$"Exit code of \"{Path.GetFileName(process.StartInfo?.FileName ?? string.Empty)}\" should be 0 instead of {process.ExitCode} (= 0x{process.ExitCode.ToString("X")})");
238+
if (process.ExitCode != 0)
239+
{
240+
_output.WriteLine($"[TestRunner] Process exited with code {process.ExitCode} (0x{process.ExitCode:X})");
241+
_output.WriteLine($"[TestRunner] Standard output:\n{standardOutput}");
242+
_output.WriteLine($"[TestRunner] Error output:\n{errorOutput}");
243+
244+
Assert.True(
245+
false,
246+
$"Exit code of \"{Path.GetFileName(process.StartInfo?.FileName ?? string.Empty)}\" should be 0 instead of {process.ExitCode} (= 0x{process.ExitCode:X})");
247+
}
241248
}
242249

243250
private void SetEnvironmentVariables(StringDictionary environmentVariables, MockDatadogAgent agent)

tracer/test/Datadog.Trace.Debugger.IntegrationTests/Helpers/DebuggerSampleProcessHelper.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Net;
99
using System.Threading.Tasks;
1010
using Datadog.Trace.TestHelpers;
11+
using Xunit.Abstractions;
1112

1213
namespace Datadog.Trace.Debugger.IntegrationTests.Helpers
1314
{
@@ -17,12 +18,14 @@ internal class DebuggerSampleProcessHelper : ProcessHelper
1718

1819
private readonly string _stopUrl;
1920
private readonly string _runUrl;
21+
private readonly ITestOutputHelper _output;
2022

21-
public DebuggerSampleProcessHelper(string baseUrl, Process process, Action<string> onDataReceived = null)
23+
public DebuggerSampleProcessHelper(string baseUrl, Process process, ITestOutputHelper output, Action<string> onDataReceived = null)
2224
: base(process, onDataReceived)
2325
{
2426
_stopUrl = $"{baseUrl}{StopSuffix}";
2527
_runUrl = baseUrl;
28+
_output = output;
2629
}
2730

2831
internal async Task StopSample()
@@ -36,6 +39,13 @@ internal async Task StopSample()
3639
throw new InvalidOperationException($"The process did not exit after {timeout}ms");
3740
}
3841

42+
if (Process.ExitCode != 0)
43+
{
44+
_output.WriteLine($"[DebuggerSampleProcessHelper] Process exited with code {Process.ExitCode} (0x{Process.ExitCode:X})");
45+
_output.WriteLine($"[DebuggerSampleProcessHelper] Standard output:\n{StandardOutput}");
46+
_output.WriteLine($"[DebuggerSampleProcessHelper] Error output:\n{ErrorOutput}");
47+
}
48+
3949
ExitCodeException.ThrowIfNonZero(Process.ExitCode);
4050
}
4151

tracer/test/Datadog.Trace.Debugger.IntegrationTests/Helpers/DebuggerTestHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ internal static async Task<DebuggerSampleProcessHelper> StartSample(TestHelper h
6868
var listenUrl = $"{localHost}:{listenPort}/";
6969

7070
var process = await helper.StartSample(agent, $"--test-name {testName} --listen-url {listenUrl}", string.Empty, aspNetCorePort: 5000);
71-
var processHelper = new DebuggerSampleProcessHelper(listenUrl, process);
71+
var processHelper = new DebuggerSampleProcessHelper(listenUrl, process, helper.GetOutput());
7272

7373
return processHelper;
7474
}

tracer/test/Datadog.Trace.TestHelpers.AutoInstrumentation/TestHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ protected TestHelper(EnvironmentHelper environmentHelper, ITestOutputHelper outp
7171

7272
protected ITestOutputHelper Output { get; }
7373

74+
public ITestOutputHelper GetOutput() => Output;
75+
7476
public virtual void Dispose()
7577
{
7678
}

0 commit comments

Comments
 (0)