Skip to content

Commit

Permalink
Fix draining response in metrics test (#93379)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManickaP authored Oct 12, 2023
1 parent 0a77fd4 commit b331f23
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -347,7 +347,7 @@ public Task RequestDuration_CustomTags_Recorded()
{
ctx.AddCustomTag("route", "/test");
});

using HttpResponseMessage response = await SendAsync(client, request);

Measurement<double> m = Assert.Single(recorder.GetMeasurements());
Expand Down Expand Up @@ -455,6 +455,21 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
using InstrumentRecorder<double> recorder = SetupInstrumentRecorder<double>(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<double> m = Assert.Single(recorder.GetMeasurements());
VerifyRequestDuration(m, uri, UseVersion, 200); ;
Expand Down Expand Up @@ -790,7 +805,7 @@ await Assert.ThrowsAsync<HttpRequestException>(async () =>
using HttpResponseMessage response = await SendAsync(client, request);
});
}

Measurement<double> m = Assert.Single(recorder.GetMeasurements());
VerifyRequestDuration(m, uri, UseVersion, 200);
Assert.Equal("before!", m.Tags.ToArray().Single(t => t.Key == "before").Value);
Expand Down

0 comments on commit b331f23

Please sign in to comment.