From eaa1562c6183a045d16cfb42f29c2ee9da21ae2d Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Wed, 9 Aug 2023 14:30:59 +0200 Subject: [PATCH 1/2] Fix SocketsHttpHandler metrics test on Android --- .../System.Net.Http/tests/FunctionalTests/MetricsTest.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs index bdca584723a2ea..53a998ec1622c7 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs @@ -974,6 +974,12 @@ public void AllSocketsHttpHandlerCounters_Success_Recorded() using HttpMetricsTest_DefaultMeter test = new(null); await test.LoopbackServerFactory.CreateClientAndServerAsync(async uri => { + if (PlatformDetection.IsMobile) + { + // Force the test to use SocketsHttpHandler + AppContext.SetSwitch("System.Net.Http.UseNativeHttpHandler", false); + } + using MultiInstrumentRecorder recorder = new(); using (HttpClient client = test.CreateHttpClient()) From 30b88daba4079738864e74ce41aa30918ee3c6b7 Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Wed, 9 Aug 2023 15:07:41 +0200 Subject: [PATCH 2/2] Move to start of RemoteExecutor callback --- .../tests/FunctionalTests/MetricsTest.cs | 12 ++++++------ 1 file changed, 6 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 53a998ec1622c7..e0d9a3c2e42964 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs @@ -969,17 +969,17 @@ public void AllSocketsHttpHandlerCounters_Success_Recorded() { RemoteExecutor.Invoke(static async Task () => { + if (PlatformDetection.IsMobile) + { + // Force the test to use SocketsHttpHandler + AppContext.SetSwitch("System.Net.Http.UseNativeHttpHandler", false); + } + TaskCompletionSource clientWaitingTcs = new(TaskCreationOptions.RunContinuationsAsynchronously); using HttpMetricsTest_DefaultMeter test = new(null); await test.LoopbackServerFactory.CreateClientAndServerAsync(async uri => { - if (PlatformDetection.IsMobile) - { - // Force the test to use SocketsHttpHandler - AppContext.SetSwitch("System.Net.Http.UseNativeHttpHandler", false); - } - using MultiInstrumentRecorder recorder = new(); using (HttpClient client = test.CreateHttpClient())