Repository: dotnet/runtime
File: src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs (C#)

Code before:
            int delay = 25;
            bool disposeListener = false;

            if (listener == null)
            {
                listener = CreateQuicListener();
                disposeListener = true;
            }

            clientOptions ??= CreateQuicClientOptions();
            if (clientOptions.RemoteEndPoint == null)
            {
                clientOptions.RemoteEndPoint = listener.ListenEndPoint;
            }

            QuicConnection clientConnection = null;
            ValueTask<QuicConnection> serverTask = listener.AcceptConnectionAsync();
            while (retry > 0)
            {
                clientConnection = CreateQuicConnection(clientOptions);
                retry--;
                try
                {
                    await clientConnection.ConnectAsync().ConfigureAwait(false);
                    break;
                } catch (QuicException ex) when (ex.HResult == (int)SocketError.ConnectionRefused)
                {
                    _output.WriteLine($"ConnectAsync to {clientConnection.RemoteEndPoint} failed with {ex.Message}");
                    await Task.Delay(delay);
                    delay *= 2;

                    if (retry ==0)
                    {
                        Debug.Fail($"ConnectAsync to {clientConnection.RemoteEndPoint} failed with {ex.Message}");
                    }
                }
            }

            QuicConnection serverConnection = await serverTask.ConfigureAwait(false);
            if (disposeListener)
            {
                listener.Dispose();
            }

            Assert.True(serverConnection.Connected);
            Assert.True(clientConnection.Connected);

            return (clientConnection, serverTask.Result);
        }

        internal async Task PingPong(QuicConnection client, QuicConnection server)

Review comment (suggestion):
```suggestion
                }
                catch (QuicException ex) when (ex.HResult == (int)SocketError.ConnectionRefused)
```

Code after:
            int delay = 25;
            bool disposeListener = false;

            if (listener == null)
            {
                listener = CreateQuicListener();
                disposeListener = true;
            }

            clientOptions ??= CreateQuicClientOptions();
            if (clientOptions.RemoteEndPoint == null)
            {
                clientOptions.RemoteEndPoint = listener.ListenEndPoint;
            }

            QuicConnection clientConnection = null;
            ValueTask<QuicConnection> serverTask = listener.AcceptConnectionAsync();
            while (retry > 0)
            {
                clientConnection = CreateQuicConnection(clientOptions);
                retry--;
                try
                {
                    await clientConnection.ConnectAsync().ConfigureAwait(false);
                    break;
                }
                catch (QuicException ex) when (ex.HResult == (int)SocketError.ConnectionRefused)
                {
                    _output.WriteLine($"ConnectAsync to {clientConnection.RemoteEndPoint} failed with {ex.Message}");
                    await Task.Delay(delay);
                    delay *= 2;

                    if (retry == 0)
                    {
                        Debug.Fail($"ConnectAsync to {clientConnection.RemoteEndPoint} failed with {ex.Message}");
                    }
                }
            }

            QuicConnection serverConnection = await serverTask.ConfigureAwait(false);
            if (disposeListener)
            {
                listener.Dispose();
            }

            Assert.True(serverConnection.Connected);
            Assert.True(clientConnection.Connected);

            return (clientConnection, serverTask.Result);
        }