Skip to content

Commit 067d222

Browse files
Refactor
Preparing to have TLS-aware tests in TestHeartbeats.
1 parent 5054cc9 commit 067d222

File tree

3 files changed

+40
-31
lines changed

3 files changed

+40
-31
lines changed

projects/client/Unit/src/unit/Fixtures.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,15 @@ protected void Wait(ManualResetEvent latch, TimeSpan timeSpan)
559559
{
560560
Assert.IsTrue(latch.WaitOne(timeSpan), "waiting on a latch timed out");
561561
}
562+
563+
//
564+
// TLS
565+
//
566+
567+
public static string CertificatesDirectory()
568+
{
569+
return Environment.GetEnvironmentVariable("SSL_CERTS_DIR");
570+
}
562571
}
563572

564573
public class TimingFixture

projects/client/Unit/src/unit/TestHeartbeats.cs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,7 @@ public void TestThatHeartbeatWriterUsesConfigurableInterval()
6565
RequestedHeartbeat = heartbeatTimeout,
6666
AutomaticRecoveryEnabled = false
6767
};
68-
var conn = cf.CreateConnection();
69-
var ch = conn.CreateModel();
70-
bool wasShutdown = false;
71-
72-
conn.ConnectionShutdown += (sender, evt) =>
73-
{
74-
lock (conn)
75-
{
76-
if (InitiatedByPeerOrLibrary(evt))
77-
{
78-
CheckInitiator(evt);
79-
wasShutdown = true;
80-
}
81-
}
82-
};
83-
SleepFor(30);
84-
85-
Assert.IsFalse(wasShutdown, "shutdown event should not have been fired");
86-
Assert.IsTrue(conn.IsOpen, "connection should be open");
87-
88-
conn.Close();
68+
RunSingleConnectionTest(cf);
8969
}
9070

9171
[Test]
@@ -122,6 +102,31 @@ public void TestHundredsOfConnectionsWithRandomHeartbeatInterval()
122102
}
123103
}
124104

105+
protected void RunSingleConnectionTest(ConnectionFactory cf)
106+
{
107+
var conn = cf.CreateConnection();
108+
var ch = conn.CreateModel();
109+
bool wasShutdown = false;
110+
111+
conn.ConnectionShutdown += (sender, evt) =>
112+
{
113+
lock (conn)
114+
{
115+
if (InitiatedByPeerOrLibrary(evt))
116+
{
117+
CheckInitiator(evt);
118+
wasShutdown = true;
119+
}
120+
}
121+
};
122+
SleepFor(30);
123+
124+
Assert.IsFalse(wasShutdown, "shutdown event should not have been fired");
125+
Assert.IsTrue(conn.IsOpen, "connection should be open");
126+
127+
conn.Close();
128+
}
129+
125130
private void CheckInitiator(ShutdownEventArgs evt)
126131
{
127132
if (InitiatedByPeerOrLibrary(evt))

projects/client/Unit/src/unit/TestSsl.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ namespace RabbitMQ.Client.Unit
5050
[TestFixture]
5151
public class TestSsl
5252
{
53-
public static string CertificatesDirectory()
54-
{
55-
return Environment.GetEnvironmentVariable("SSL_CERTS_DIR");
56-
}
57-
5853
public void SendReceive(ConnectionFactory cf)
5954
{
6055
using (IConnection conn = cf.CreateConnection())
@@ -81,7 +76,7 @@ public void SendReceive(ConnectionFactory cf)
8176
[Test]
8277
public void TestServerVerifiedIgnoringNameMismatch()
8378
{
84-
string sslDir = CertificatesDirectory();
79+
string sslDir = IntegrationFixture.CertificatesDirectory();
8580
if (null == sslDir)
8681
{
8782
Console.WriteLine("SSL_CERT_DIR is not configured, skipping test");
@@ -98,7 +93,7 @@ public void TestServerVerifiedIgnoringNameMismatch()
9893
[Test]
9994
public void TestServerVerified()
10095
{
101-
string sslDir = CertificatesDirectory();
96+
string sslDir = IntegrationFixture.CertificatesDirectory();
10297
if (null == sslDir)
10398
{
10499
Console.WriteLine("SSL_CERT_DIR is not configured, skipping test");
@@ -114,7 +109,7 @@ public void TestServerVerified()
114109
[Test]
115110
public void TestVersionVerified()
116111
{
117-
string sslDir = CertificatesDirectory();
112+
string sslDir = IntegrationFixture.CertificatesDirectory();
118113
if (null == sslDir)
119114
{
120115
Console.WriteLine("SSL_CERT_DIR is not configured, skipping test");
@@ -135,7 +130,7 @@ public void TestVersionVerified()
135130
[Test]
136131
public void TestClientAndServerVerified()
137132
{
138-
string sslDir = CertificatesDirectory();
133+
string sslDir = IntegrationFixture.CertificatesDirectory();
139134
if (null == sslDir)
140135
{
141136
Console.WriteLine("SSL_CERT_DIR is not configured, skipping test");
@@ -157,7 +152,7 @@ public void TestClientAndServerVerified()
157152
[Test]
158153
public void TestNoClientCertificate()
159154
{
160-
string sslDir = CertificatesDirectory();
155+
string sslDir = IntegrationFixture.CertificatesDirectory();
161156
if (null == sslDir)
162157
{
163158
Console.WriteLine("SSL_CERT_DIR is not configured, skipping test");

0 commit comments

Comments
 (0)