From 01fb6bdee56cbbceb0fa9f2f890b0bcb4bdacb6e Mon Sep 17 00:00:00 2001 From: Roman Konecny Date: Wed, 17 Jul 2024 17:54:42 +0200 Subject: [PATCH] Change method POST to avoid retry on server Shutdown --- .../System.Net.Http/tests/FunctionalTests/MetricsTest.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs index 19003fddfff51..374e844a50598 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs @@ -955,19 +955,20 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => { using HttpMessageInvoker client = CreateHttpMessageInvoker(); using InstrumentRecorder recorder = SetupInstrumentRecorder(InstrumentNames.RequestDuration); - using HttpRequestMessage request = new(HttpMethod.Get, uri) { Version = UseVersion }; + using HttpRequestMessage request = new(HttpMethod.Post, uri) { Version = UseVersion }; + request.Content = new StringContent("{}"); Exception ex = await Assert.ThrowsAnyAsync(async () => { - // Getting a cancellation is also good if we are unable to detect the peer shutdown. - using CancellationTokenSource cts = new CancellationTokenSource(10_000); + // To avoid unlimited blocking, lets bound it to 20 seconds. + using CancellationTokenSource cts = new CancellationTokenSource(20_000); using HttpResponseMessage response = await SendAsync(client, request, cts.Token); }); cancelServerCts.Cancel(); Assert.True(ex is HttpRequestException or TaskCanceledException); Measurement m = Assert.Single(recorder.GetMeasurements()); - VerifyRequestDuration(m, uri, acceptedErrorTypes: [typeof(TaskCanceledException).FullName, "response_ended"]); + VerifyRequestDuration(m, uri, acceptedErrorTypes: [typeof(TaskCanceledException).FullName, "response_ended"], method: "POST"); }, async server => { await IgnoreExceptions(async () =>