Skip to content

Commit

Permalink
Rework Connect_fails_if_listener_is_disposed test (#4104)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone authored Nov 14, 2024
1 parent e585581 commit 9917416
Showing 1 changed file with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransportConnectionInformation> connectTask;
IDuplexConnection clientConnection;
var connections = new List<IDuplexConnection>();
while (true)
{
IDuplexConnection? connection = clientTransport.CreateConnection(
listener.ServerAddress,
provider.GetService<IOptions<DuplexConnectionOptions>>()?.Value ?? new(),
clientAuthenticationOptions: provider.GetService<SslClientAuthenticationOptions>());
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;
}
}

Expand All @@ -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]
Expand Down

0 comments on commit 9917416

Please sign in to comment.