diff --git a/tests/IceRpc.Conformance.Tests/Transports/DuplexListenerConformanceTests.cs b/tests/IceRpc.Conformance.Tests/Transports/DuplexListenerConformanceTests.cs index 73b3a198b..35d37d1cf 100644 --- a/tests/IceRpc.Conformance.Tests/Transports/DuplexListenerConformanceTests.cs +++ b/tests/IceRpc.Conformance.Tests/Transports/DuplexListenerConformanceTests.cs @@ -123,31 +123,19 @@ public async Task Connect_fails_if_listener_is_disposed() // A duplex transport listener might use a backlog to accept client connections (e.g.: TCP). So we need to // create and establish client connections until a connection establishment blocks to test cancellation. Task connectTask; - IDuplexConnection clientConnection; + var connections = new List(); while (true) { IDuplexConnection? connection = clientTransport.CreateConnection( listener.ServerAddress, provider.GetService>()?.Value ?? new(), clientAuthenticationOptions: provider.GetService()); - try + connections.Add(connection); + connectTask = connection.ConnectAsync(default); + await Task.WhenAny(connectTask, Task.Delay(TimeSpan.FromMilliseconds(250))); + if (!connectTask.IsCompleted) { - connectTask = connection.ConnectAsync(default); - await Task.Delay(TimeSpan.FromMilliseconds(100)); - if (connectTask.IsCompleted) - { - await connectTask; - } - else - { - clientConnection = connection; - connection = null; - break; - } - } - finally - { - connection?.Dispose(); + break; } } @@ -163,7 +151,11 @@ public async Task Connect_fails_if_listener_is_disposed() exception!.IceRpcError, Is.EqualTo(IceRpcError.ConnectionRefused).Or.EqualTo(IceRpcError.ConnectionAborted), $"The test failed with an unexpected IceRpcError {exception}"); - clientConnection.Dispose(); + + foreach (IDuplexConnection connection in connections) + { + connection.Dispose(); + } } [Test]