From cfc16c6a47d25afb4c319b2a1bd5f50ee2ed0163 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Tue, 24 Nov 2026 10:05:06 -0600 Subject: [PATCH] [release/10.0] Preserve original failures in HTTP metrics and QUIC test diagnostics Backport of #137472 (a9ffa6f8b33). Test-only. The QuicTestBase serverTask logging hunk is omitted because that block does not exist on release/10.0. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../System.Net.Http/tests/FunctionalTests/MetricsTest.cs | 7 +++++-- .../System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs index 4317736c5d4043..0422d8a353fcd0 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs @@ -531,15 +531,17 @@ await RemoteExecutor.Invoke(static async (testClassName, eventNameInner) => private async Task RequestDuration_CustomTags_DiagnosticListener_Recorded_Core(string eventName) { + HttpResponseMessage? enrichmentResponse = null; + FakeDiagnosticListenerObserver diagnosticListenerObserver = new(kv => { if (kv.Key == eventName) { HttpRequestMessage request = GetProperty(kv.Value, "Request"); - HttpMetricsEnrichmentContext.AddCallback(request, static ctx => + HttpMetricsEnrichmentContext.AddCallback(request, ctx => { ctx.AddCustomTag("observed?", "observed!"); - Assert.NotNull(ctx.Response); + enrichmentResponse = ctx.Response; }); } }); @@ -558,6 +560,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri => }); using HttpResponseMessage response = await SendAsync(client, request); + Assert.Same(response, enrichmentResponse); Measurement m = Assert.Single(recorder.GetMeasurements()); VerifyRequestDuration(m, uri, UseVersion, 200); diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs b/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs index ca6ba2ea846765..3023b24b020603 100644 --- a/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs +++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs @@ -78,7 +78,7 @@ public bool RemoteCertificateValidationCallback(object sender, X509Certificate? public async Task AssertThrowsQuicExceptionAsync(QuicError expectedError, Func testCode) { QuicException ex = await Assert.ThrowsAsync(testCode); - _output.WriteLine(ex.ToString()); + _output?.WriteLine(ex.ToString()); Assert.Equal(expectedError, ex.QuicError); return ex; } @@ -226,7 +226,7 @@ internal ValueTask CreateQuicListener(IPEndPoint endpoint, Action< } catch (QuicException ex) when (ex.HResult == (int)SocketError.ConnectionRefused) { - _output.WriteLine($"ConnectAsync to {clientOptions.RemoteEndPoint} failed with {ex.Message}"); + _output?.WriteLine($"ConnectAsync to {clientOptions.RemoteEndPoint} failed with {ex.Message}"); await Task.Delay(delay); delay *= 2; @@ -323,7 +323,7 @@ await new[] } catch (ObjectDisposedException ex) { - _output.WriteLine(ex.ToString()); + _output?.WriteLine(ex.ToString()); } try { @@ -331,7 +331,7 @@ await new[] } catch (ObjectDisposedException ex) { - _output.WriteLine(ex.ToString()); + _output?.WriteLine(ex.ToString()); } } }