Skip to content

Commit 7e14222

Browse files
committed
Increase connection timeout for CI
1 parent cb38edc commit 7e14222

File tree

4 files changed

+11
-38
lines changed

4 files changed

+11
-38
lines changed

projects/RabbitMQ.Client/client/api/ITcpClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface ITcpClient : IDisposable
1919

2020
Socket Client { get; }
2121

22-
Task ConnectAsync(string host, int port, TimeSpan connectionTimeout, CancellationToken cancellationToken);
22+
// TODO cancellationToken should be the only parameter
2323
Task ConnectAsync(IPAddress host, int port, TimeSpan connectionTimeout, CancellationToken cancellationToken);
2424

2525
NetworkStream GetStream();

projects/RabbitMQ.Client/client/api/TcpClientAdapter.cs

+1-30
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,15 @@ public TcpClientAdapter(Socket socket)
2121
}
2222

2323
#if NET6_0_OR_GREATER
24-
public virtual async Task ConnectAsync(string host, int port, TimeSpan connectionTimeout, CancellationToken cancellationToken)
25-
{
26-
AssertSocket();
27-
IPAddress[] adds = await Dns.GetHostAddressesAsync(host)
28-
.ConfigureAwait(false);
29-
IPAddress ep = GetMatchingHost(adds, _sock.AddressFamily);
30-
if (ep == default(IPAddress))
31-
{
32-
throw new ArgumentException($"No ip address could be resolved for {host}");
33-
}
34-
35-
await ConnectAsync(ep, port, connectionTimeout, cancellationToken)
36-
.ConfigureAwait(false);
37-
}
38-
3924
public virtual Task ConnectAsync(IPAddress ep, int port, TimeSpan connectionTimeout, CancellationToken cancellationToken)
4025
{
4126
AssertSocket();
4227
return _sock.ConnectAsync(ep, port, cancellationToken).AsTask();
4328
}
4429
#else
45-
public virtual async Task ConnectAsync(string host, int port, TimeSpan connectionTimeout, CancellationToken cancellationToken)
46-
{
47-
AssertSocket();
48-
IPAddress[] adds = await Dns.GetHostAddressesAsync(host)
49-
.ConfigureAwait(false);
50-
IPAddress ep = GetMatchingHost(adds, _sock.AddressFamily);
51-
if (ep == default(IPAddress))
52-
{
53-
throw new ArgumentException($"No ip address could be resolved for {host}");
54-
}
55-
56-
await ConnectAsync(ep, port, connectionTimeout, cancellationToken)
57-
.ConfigureAwait(false);
58-
}
59-
6030
public virtual Task ConnectAsync(IPAddress ep, int port, TimeSpan connectionTimeout, CancellationToken cancellationToken)
6131
{
32+
// TODO cancellationToken should be the only parameter
6233
return _sock.ConnectAsync(ep, port).TimeoutAfter(connectionTimeout);
6334
}
6435
#endif

projects/Test/Common/IntegrationFixtureBase.cs

+9-5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public abstract class IntegrationFixtureBase : IDisposable
6565
public static readonly TimeSpan LongWaitSpan;
6666
public static readonly TimeSpan RecoveryInterval = TimeSpan.FromSeconds(2);
6767
public static readonly TimeSpan TestTimeout = TimeSpan.FromSeconds(5);
68+
public static readonly TimeSpan RequestedConnectionTimeout = TimeSpan.FromSeconds(1);
6869
public static readonly Random S_Random;
6970

7071
static IntegrationFixtureBase()
@@ -78,6 +79,7 @@ static IntegrationFixtureBase()
7879
{
7980
WaitSpan = TimeSpan.FromSeconds(60);
8081
LongWaitSpan = TimeSpan.FromSeconds(120);
82+
RequestedConnectionTimeout = TimeSpan.FromSeconds(5);
8183
}
8284
else
8385
{
@@ -196,17 +198,19 @@ protected static bool IsVerbose
196198

197199
internal AutorecoveringConnection CreateAutorecoveringConnection(IList<string> hostnames)
198200
{
199-
return CreateAutorecoveringConnection(RecoveryInterval, hostnames);
201+
202+
return CreateAutorecoveringConnection(hostnames, RequestedConnectionTimeout, RecoveryInterval);
200203
}
201204

202-
internal AutorecoveringConnection CreateAutorecoveringConnection(TimeSpan interval, IList<string> hostnames)
205+
internal AutorecoveringConnection CreateAutorecoveringConnection(IEnumerable<string> hostnames,
206+
TimeSpan requestedConnectionTimeout, TimeSpan networkRecoveryInterval)
203207
{
204-
var cf = CreateConnectionFactory();
208+
ConnectionFactory cf = CreateConnectionFactory();
205209
cf.AutomaticRecoveryEnabled = true;
206210
// tests that use this helper will likely list unreachable hosts;
207211
// make sure we time out quickly on those
208-
cf.RequestedConnectionTimeout = TimeSpan.FromMilliseconds(2500);
209-
cf.NetworkRecoveryInterval = interval;
212+
cf.RequestedConnectionTimeout = requestedConnectionTimeout;
213+
cf.NetworkRecoveryInterval = networkRecoveryInterval;
210214
return (AutorecoveringConnection)cf.CreateConnection(hostnames);
211215
}
212216

projects/Test/Unit/APIApproval.Approve.verified.txt

-2
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,6 @@ namespace RabbitMQ.Client
713713
System.TimeSpan ReceiveTimeout { get; set; }
714714
void Close();
715715
System.Threading.Tasks.Task ConnectAsync(System.Net.IPAddress host, int port, System.TimeSpan connectionTimeout, System.Threading.CancellationToken cancellationToken);
716-
System.Threading.Tasks.Task ConnectAsync(string host, int port, System.TimeSpan connectionTimeout, System.Threading.CancellationToken cancellationToken);
717716
System.Net.Sockets.NetworkStream GetStream();
718717
}
719718
public class PlainMechanism : RabbitMQ.Client.IAuthMechanism
@@ -833,7 +832,6 @@ namespace RabbitMQ.Client
833832
public virtual System.TimeSpan ReceiveTimeout { get; set; }
834833
public virtual void Close() { }
835834
public virtual System.Threading.Tasks.Task ConnectAsync(System.Net.IPAddress ep, int port, System.TimeSpan connectionTimeout, System.Threading.CancellationToken cancellationToken) { }
836-
public virtual System.Threading.Tasks.Task ConnectAsync(string host, int port, System.TimeSpan connectionTimeout, System.Threading.CancellationToken cancellationToken) { }
837835
public void Dispose() { }
838836
protected virtual void Dispose(bool disposing) { }
839837
public virtual System.Net.Sockets.NetworkStream GetStream() { }

0 commit comments

Comments
 (0)