From 6d35d0233a3d90f2783aa60941b87c47ee003fad Mon Sep 17 00:00:00 2001 From: ManickaP Date: Thu, 12 Oct 2023 09:51:33 +0200 Subject: [PATCH] Fix draining response in metrics test --- .../tests/FunctionalTests/MetricsTest.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs index 15bb4bcbe2bb9..76b646dd21a74 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs @@ -30,7 +30,7 @@ protected static class InstrumentNames public const string ConnectionDuration = "http.client.connection.duration"; public const string TimeInQueue = "http.client.request.time_in_queue"; } - + protected HttpMetricsTestBase(ITestOutputHelper output) : base(output) { } @@ -347,7 +347,7 @@ public Task RequestDuration_CustomTags_Recorded() { ctx.AddCustomTag("route", "/test"); }); - + using HttpResponseMessage response = await SendAsync(client, request); Measurement m = Assert.Single(recorder.GetMeasurements()); @@ -455,6 +455,21 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri => using InstrumentRecorder recorder = SetupInstrumentRecorder(InstrumentNames.RequestDuration); using HttpRequestMessage request = new(HttpMethod.Get, uri) { Version = UseVersion }; using HttpResponseMessage response = await client.SendAsync(TestAsync, request, completionOption); + string responseContent = await response.Content.ReadAsStringAsync(); + + if (responseContentType == ResponseContentType.ContentLength) + { + Assert.NotNull(response.Content.Headers.ContentLength); + } + else if (responseContentType == ResponseContentType.TransferEncodingChunked) + { + Assert.NotNull(response.Headers.TransferEncodingChunked); + } + else + { + // Empty + Assert.Empty(responseContent); + } Measurement m = Assert.Single(recorder.GetMeasurements()); VerifyRequestDuration(m, uri, UseVersion, 200); ; @@ -783,7 +798,7 @@ await Assert.ThrowsAsync(async () => using HttpResponseMessage response = await SendAsync(client, request); }); } - + Measurement m = Assert.Single(recorder.GetMeasurements()); VerifyRequestDuration(m, uri, UseVersion, 200); Assert.Equal("before!", m.Tags.ToArray().Single(t => t.Key == "before").Value);