Task type
Test
Description
Unit test ValidateHttpListenerRedirectUriAsync is flaky and intermittently fails with a connection refused error when attempting to send a request to localhost. This occurs because the HTTP listener is not always fully initialized before the test attempts to send a request.
Solution
-
Ensure the listener is ready before sending the request.
-
Use Task.WhenAny(listenTask, Task.Delay(5000)) to check if the listener completes within the timeout.
-
Introduce a small delay (await Task.Delay(500)) before sending the request to allow the listener to start properly.