From a963d6f1319cb134afcf9502243b407c4fd5555c Mon Sep 17 00:00:00 2001 From: Michael Render Date: Wed, 13 Nov 2024 16:47:03 -0500 Subject: [PATCH 1/2] [dotnet] Improve the debugging experience of tests Use the new `ConfigureAwait(ConfigureAwaitOptions)` method introduced in .NET 8 to avoid first-change exceptions in the test cleanup --- .../test/common/Environment/TestWebServer.cs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/dotnet/test/common/Environment/TestWebServer.cs b/dotnet/test/common/Environment/TestWebServer.cs index b47585cd3c312..2fa142ada78be 100644 --- a/dotnet/test/common/Environment/TestWebServer.cs +++ b/dotnet/test/common/Environment/TestWebServer.cs @@ -25,6 +25,7 @@ using System.Net.Http; using System.Runtime.InteropServices; using System.Text; +using System.Threading.Tasks; namespace OpenQA.Selenium.Environment { @@ -178,20 +179,7 @@ public void Stop() { if (webserverProcess != null) { - using (var httpClient = new HttpClient()) - { - try - { - using (httpClient.GetAsync(EnvironmentManager.Instance.UrlBuilder.LocalWhereIs("quitquitquit")).GetAwaiter().GetResult()) - { - - } - } - catch (HttpRequestException) - { - - } - } + QuitNoThrow().GetAwaiter().GetResult(); try { @@ -207,6 +195,19 @@ public void Stop() webserverProcess = null; } } + + static async Task QuitNoThrow() + { + using var httpClient = new HttpClient(); + + Task getTask = httpClient.GetAsync(EnvironmentManager.Instance.UrlBuilder.LocalWhereIs("quitquitquit")); + await ((Task)getTask).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing); + + if (getTask.IsCompletedSuccessfully) + { + getTask.Result.Dispose(); + } + } } } } From def2d56918d597d42a822fbf22e1b793dbe72313 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Thu, 14 Nov 2024 16:08:01 -0500 Subject: [PATCH 2/2] remove unnecessary disposal --- dotnet/test/common/Environment/TestWebServer.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/dotnet/test/common/Environment/TestWebServer.cs b/dotnet/test/common/Environment/TestWebServer.cs index 2fa142ada78be..b97415ee1b8c5 100644 --- a/dotnet/test/common/Environment/TestWebServer.cs +++ b/dotnet/test/common/Environment/TestWebServer.cs @@ -201,12 +201,8 @@ static async Task QuitNoThrow() using var httpClient = new HttpClient(); Task getTask = httpClient.GetAsync(EnvironmentManager.Instance.UrlBuilder.LocalWhereIs("quitquitquit")); - await ((Task)getTask).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing); - if (getTask.IsCompletedSuccessfully) - { - getTask.Result.Dispose(); - } + await ((Task)getTask).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing); } } }