Skip to content

Commit c5cb387

Browse files
committed
Retry more connections in test suite
Follow-up to #1447
1 parent 16d1744 commit c5cb387

File tree

2 files changed

+61
-61
lines changed

2 files changed

+61
-61
lines changed

projects/Test/Common/IntegrationFixtureBase.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ protected virtual void SetUp()
118118

119119
if (_conn == null)
120120
{
121-
_conn = _connFactory.CreateConnection();
121+
_conn = CreateConnectionWithRetries(_connFactory);
122122
_channel = _conn.CreateChannel();
123123
AddCallbackHandlers();
124124
}
@@ -209,27 +209,25 @@ internal AutorecoveringConnection CreateAutorecoveringConnection(IEnumerable<str
209209
internal AutorecoveringConnection CreateAutorecoveringConnection(IEnumerable<string> hostnames,
210210
TimeSpan requestedConnectionTimeout, TimeSpan networkRecoveryInterval, bool expectException = false)
211211
{
212-
ConnectionFactory ConnectionFactoryConfigurator(ConnectionFactory cf)
212+
if (hostnames is null)
213213
{
214-
cf.AutomaticRecoveryEnabled = true;
215-
// tests that use this helper will likely list unreachable hosts;
216-
// make sure we time out quickly on those
217-
cf.RequestedConnectionTimeout = requestedConnectionTimeout;
218-
cf.NetworkRecoveryInterval = networkRecoveryInterval;
219-
return cf;
214+
throw new ArgumentNullException(nameof(hostnames));
220215
}
221216

222-
return (AutorecoveringConnection)CreateConnectionWithRetries(hostnames, ConnectionFactoryConfigurator, expectException);
223-
}
217+
var cf = new ConnectionFactory
218+
{
219+
AutomaticRecoveryEnabled = true,
220+
// tests that use this helper will likely list unreachable hosts;
221+
// make sure we time out quickly on those
222+
RequestedConnectionTimeout = requestedConnectionTimeout,
223+
NetworkRecoveryInterval = networkRecoveryInterval
224+
};
224225

225-
protected IConnection CreateConnectionWithRetries(Func<ConnectionFactory, ConnectionFactory> connectionFactoryConfigurator)
226-
{
227-
var hostnames = new[] { "localhost" };
228-
return CreateConnectionWithRetries(hostnames, connectionFactoryConfigurator);
226+
return (AutorecoveringConnection)CreateConnectionWithRetries(cf, hostnames, expectException);
229227
}
230228

231-
protected IConnection CreateConnectionWithRetries(IEnumerable<string> hostnames,
232-
Func<ConnectionFactory, ConnectionFactory> connectionFactoryConfigurator, bool expectException = false)
229+
protected IConnection CreateConnectionWithRetries(ConnectionFactory connectionFactory,
230+
IEnumerable<string> hostnames = null, bool expectException = false)
233231
{
234232
bool shouldRetry = IsWindows;
235233
ushort tries = 0;
@@ -238,9 +236,12 @@ protected IConnection CreateConnectionWithRetries(IEnumerable<string> hostnames,
238236
{
239237
try
240238
{
241-
ConnectionFactory cf0 = CreateConnectionFactory();
242-
ConnectionFactory cf1 = connectionFactoryConfigurator(cf0);
243-
return cf1.CreateConnection(hostnames);
239+
if (hostnames is null)
240+
{
241+
hostnames = new[] { "localhost" };
242+
}
243+
244+
return connectionFactory.CreateConnection(hostnames);
244245
}
245246
catch (BrokerUnreachableException ex)
246247
{

projects/Test/Integration/TestSsl.cs

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
3030
//---------------------------------------------------------------------------
3131

32-
using System;
3332
using System.IO;
3433
using System.Net.Security;
3534
using System.Security.Authentication;
@@ -60,32 +59,32 @@ public void TestServerVerifiedIgnoringNameMismatch()
6059
{
6160
Skip.IfNot(_sslEnv.IsSslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
6261

63-
ConnectionFactory ConnectionFactoryConfigurator(ConnectionFactory cf)
62+
var cf = new ConnectionFactory
6463
{
65-
cf.Port = 5671;
66-
cf.Ssl.ServerName = "*";
67-
cf.Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch;
68-
cf.Ssl.Enabled = true;
69-
return cf;
70-
}
64+
Port = 5671
65+
};
66+
67+
cf.Ssl.ServerName = "*";
68+
cf.Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch;
69+
cf.Ssl.Enabled = true;
7170

72-
SendReceive(ConnectionFactoryConfigurator);
71+
SendReceive(cf);
7372
}
7473

7574
[SkippableFact]
7675
public void TestServerVerified()
7776
{
7877
Skip.IfNot(_sslEnv.IsSslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
7978

80-
ConnectionFactory ConnectionFactoryConfigurator(ConnectionFactory cf)
79+
var cf = new ConnectionFactory
8180
{
82-
cf.Port = 5671;
83-
cf.Ssl.ServerName = _sslEnv.Hostname;
84-
cf.Ssl.Enabled = true;
85-
return cf;
86-
}
81+
Port = 5671,
82+
};
8783

88-
SendReceive(ConnectionFactoryConfigurator);
84+
cf.Ssl.ServerName = _sslEnv.Hostname;
85+
cf.Ssl.Enabled = true;
86+
87+
SendReceive(cf);
8988
}
9089

9190
[SkippableFact]
@@ -96,17 +95,17 @@ public void TestClientAndServerVerified()
9695
string certPath = _sslEnv.CertPath;
9796
Assert.True(File.Exists(certPath));
9897

99-
ConnectionFactory ConnectionFactoryConfigurator(ConnectionFactory cf)
98+
var cf = new ConnectionFactory
10099
{
101-
cf.Port = 5671;
102-
cf.Ssl.ServerName = _sslEnv.Hostname;
103-
cf.Ssl.CertPath = certPath;
104-
cf.Ssl.CertPassphrase = _sslEnv.CertPassphrase;
105-
cf.Ssl.Enabled = true;
106-
return cf;
107-
}
100+
Port = 5671
101+
};
108102

109-
SendReceive(ConnectionFactoryConfigurator);
103+
cf.Ssl.ServerName = _sslEnv.Hostname;
104+
cf.Ssl.CertPath = certPath;
105+
cf.Ssl.CertPassphrase = _sslEnv.CertPassphrase;
106+
cf.Ssl.Enabled = true;
107+
108+
SendReceive(cf);
110109
}
111110

112111
// rabbitmq/rabbitmq-dotnet-client#46, also #44 and #45
@@ -115,28 +114,28 @@ public void TestNoClientCertificate()
115114
{
116115
Skip.IfNot(_sslEnv.IsSslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
117116

118-
ConnectionFactory ConnectionFactoryConfigurator(ConnectionFactory cf)
117+
var cf = new ConnectionFactory
119118
{
120-
cf.Port = 5671;
121-
cf.Ssl = new SslOption()
122-
{
123-
CertPath = null,
124-
Enabled = true,
125-
ServerName = _sslEnv.Hostname,
126-
Version = SslProtocols.None,
127-
AcceptablePolicyErrors =
128-
SslPolicyErrors.RemoteCertificateNotAvailable |
129-
SslPolicyErrors.RemoteCertificateNameMismatch
130-
};
131-
return cf;
132-
}
119+
Port = 5671
120+
};
133121

134-
SendReceive(ConnectionFactoryConfigurator);
122+
cf.Ssl = new SslOption()
123+
{
124+
CertPath = null,
125+
Enabled = true,
126+
ServerName = _sslEnv.Hostname,
127+
Version = SslProtocols.None,
128+
AcceptablePolicyErrors =
129+
SslPolicyErrors.RemoteCertificateNotAvailable |
130+
SslPolicyErrors.RemoteCertificateNameMismatch
131+
};
132+
133+
SendReceive(cf);
135134
}
136135

137-
private void SendReceive(Func<ConnectionFactory, ConnectionFactory> cfconfig)
136+
private void SendReceive(ConnectionFactory connectionFactory)
138137
{
139-
using (IConnection conn = CreateConnectionWithRetries(cfconfig))
138+
using (IConnection conn = CreateConnectionWithRetries(connectionFactory))
140139
{
141140
using (IChannel ch = conn.CreateChannel())
142141
{

0 commit comments

Comments
 (0)