Skip to content

Commit 36e4bc0

Browse files
committed
Fix Concourse CI
Fix required due to the changes in this PR: rabbitmq/tls-gen#37 Ensure that RMQ is always restarted
1 parent 93921e6 commit 36e4bc0

File tree

7 files changed

+108
-85
lines changed

7 files changed

+108
-85
lines changed

_site

Submodule _site updated 152 files

projects/Unit/TestBasicPublish.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace RabbitMQ.Client.Unit
1010
{
11-
1211
public class TestBasicPublish
1312
{
1413
[Fact]

projects/Unit/TestConnectionRecovery.cs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,22 @@ public void TestBasicConnectionRecoveryStopsAfterManualClose()
236236
AutorecoveringConnection c = CreateAutorecoveringConnection();
237237
var latch = new AutoResetEvent(false);
238238
c.ConnectionRecoveryError += (o, args) => latch.Set();
239-
StopRabbitMQ();
240-
latch.WaitOne(30000); // we got the failed reconnection event.
241-
bool triedRecoveryAfterClose = false;
242-
c.Close();
243-
Thread.Sleep(5000);
244-
c.ConnectionRecoveryError += (o, args) => triedRecoveryAfterClose = true;
245-
Thread.Sleep(10000);
246-
Assert.False(triedRecoveryAfterClose);
247-
StartRabbitMQ();
239+
240+
try
241+
{
242+
StopRabbitMQ();
243+
latch.WaitOne(30000); // we got the failed reconnection event.
244+
bool triedRecoveryAfterClose = false;
245+
c.Close();
246+
Thread.Sleep(5000);
247+
c.ConnectionRecoveryError += (o, args) => triedRecoveryAfterClose = true;
248+
Thread.Sleep(10000);
249+
Assert.False(triedRecoveryAfterClose);
250+
}
251+
finally
252+
{
253+
StartRabbitMQ();
254+
}
248255
}
249256

250257
[Fact]
@@ -775,14 +782,21 @@ public void TestShutdownEventHandlersRecoveryOnConnectionAfterDelayedServerResta
775782
ManualResetEventSlim recoveryLatch = PrepareForRecovery((AutorecoveringConnection)_conn);
776783

777784
Assert.True(_conn.IsOpen);
778-
StopRabbitMQ();
779-
Console.WriteLine("Stopped RabbitMQ. About to sleep for multiple recovery intervals...");
780-
Thread.Sleep(7000);
781-
StartRabbitMQ();
785+
786+
try
787+
{
788+
StopRabbitMQ();
789+
Console.WriteLine("Stopped RabbitMQ. About to sleep for multiple recovery intervals...");
790+
Thread.Sleep(7000);
791+
}
792+
finally
793+
{
794+
StartRabbitMQ();
795+
}
796+
782797
Wait(shutdownLatch, TimeSpan.FromSeconds(30));
783798
Wait(recoveryLatch, TimeSpan.FromSeconds(30));
784799
Assert.True(_conn.IsOpen);
785-
786800
Assert.True(counter >= 1);
787801
}
788802

projects/Unit/TestFloodPublishing.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,22 @@
3838
using RabbitMQ.Client.Events;
3939

4040
using Xunit;
41+
using Xunit.Abstractions;
4142

4243
namespace RabbitMQ.Client.Unit
4344
{
44-
45+
[Collection("IntegrationFixture")]
4546
public class TestFloodPublishing
4647
{
48+
private readonly ITestOutputHelper _output;
4749
private readonly byte[] _body = new byte[2048];
4850
private readonly TimeSpan _tenSeconds = TimeSpan.FromSeconds(10);
4951

52+
public TestFloodPublishing(ITestOutputHelper output)
53+
{
54+
_output = output;
55+
}
56+
5057
[Fact]
5158
public void TestUnthrottledFloodPublishing()
5259
{
@@ -89,15 +96,15 @@ public void TestUnthrottledFloodPublishing()
8996
finally
9097
{
9198
stopwatch.Stop();
92-
Console.WriteLine($"sent {i}, done in {stopwatch.Elapsed.TotalMilliseconds} ms");
99+
_output.WriteLine($"sent {i}, done in {stopwatch.Elapsed.TotalMilliseconds} ms");
93100
}
94101

95102
Assert.True(conn.IsOpen);
96103
closeWatch.Start();
97104
}
98105
}
99106
closeWatch.Stop();
100-
Console.WriteLine($"Closing took {closeWatch.Elapsed.TotalMilliseconds} ms");
107+
_output.WriteLine($"Closing took {closeWatch.Elapsed.TotalMilliseconds} ms");
101108
}
102109

103110
[Fact]

projects/Unit/TestHeartbeats.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
using System;
3333
using System.Collections.Generic;
34+
using System.IO;
3435
using System.Threading;
3536

3637
using Xunit;
@@ -58,14 +59,10 @@ public void TestThatHeartbeatWriterUsesConfigurableInterval()
5859
RunSingleConnectionTest(cf);
5960
}
6061

61-
[Fact]
62+
[SkippableFact]
6263
public void TestThatHeartbeatWriterWithTLSEnabled()
6364
{
64-
if (!LongRunningTestsEnabled())
65-
{
66-
Console.WriteLine("RABBITMQ_LONG_RUNNING_TESTS is not set, skipping test");
67-
return;
68-
}
65+
Skip.IfNot(LongRunningTestsEnabled(), "RABBITMQ_LONG_RUNNING_TESTS is not set, skipping test");
6966

7067
var cf = new ConnectionFactory()
7168
{
@@ -75,15 +72,15 @@ public void TestThatHeartbeatWriterWithTLSEnabled()
7572
};
7673

7774
string sslDir = IntegrationFixture.CertificatesDirectory();
78-
if (null == sslDir)
79-
{
80-
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
81-
return;
82-
}
83-
cf.Ssl.ServerName = System.Net.Dns.GetHostName();
84-
Assert.NotNull(sslDir);
85-
cf.Ssl.CertPath = $"{sslDir}/client_key.p12";
86-
cf.Ssl.CertPassphrase = Environment.GetEnvironmentVariable("PASSWORD");
75+
string certPassphrase = Environment.GetEnvironmentVariable("PASSWORD");
76+
bool sslConfigured = Directory.Exists(sslDir) &&
77+
(false == string.IsNullOrEmpty(certPassphrase));
78+
Skip.IfNot(sslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
79+
80+
string hostName = System.Net.Dns.GetHostName();
81+
cf.Ssl.ServerName = hostName;
82+
cf.Ssl.CertPath = $"{sslDir}/client_{hostName}_key.p12";
83+
cf.Ssl.CertPassphrase = certPassphrase;
8784
cf.Ssl.Enabled = true;
8885

8986
RunSingleConnectionTest(cf);

projects/Unit/TestSsl.cs

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,48 +30,44 @@
3030
//---------------------------------------------------------------------------
3131

3232
using System;
33+
using System.IO;
3334
using System.Net.Security;
35+
using System.Reflection;
3436
using System.Security.Authentication;
3537

3638
using Xunit;
39+
using Xunit.Abstractions;
3740

3841
namespace RabbitMQ.Client.Unit
3942
{
40-
43+
[Collection("IntegrationFixture")]
4144
public class TestSsl
4245
{
43-
private void SendReceive(ConnectionFactory cf)
44-
{
45-
using (IConnection conn = cf.CreateConnection())
46-
{
47-
IModel ch = conn.CreateModel();
46+
private readonly ITestOutputHelper _output;
47+
private readonly string _testDisplayName;
48+
private readonly string _sslDir;
49+
private readonly string _certPassphrase;
50+
private readonly bool _sslConfigured;
4851

49-
ch.ExchangeDeclare("Exchange_TestSslEndPoint", ExchangeType.Direct);
50-
string qName = ch.QueueDeclare();
51-
ch.QueueBind(qName, "Exchange_TestSslEndPoint", "Key_TestSslEndpoint", null);
52-
53-
string message = "Hello C# SSL Client World";
54-
byte[] msgBytes = System.Text.Encoding.UTF8.GetBytes(message);
55-
ch.BasicPublish("Exchange_TestSslEndPoint", "Key_TestSslEndpoint", msgBytes);
52+
public TestSsl(ITestOutputHelper output)
53+
{
54+
_output = output;
55+
var type = _output.GetType();
56+
var testMember = type.GetField("test", BindingFlags.Instance | BindingFlags.NonPublic);
57+
var test = (ITest)testMember.GetValue(output);
58+
_testDisplayName = test.DisplayName;
5659

57-
bool autoAck = false;
58-
BasicGetResult result = ch.BasicGet(qName, autoAck);
59-
byte[] body = result.Body.ToArray();
60-
string resultMessage = System.Text.Encoding.UTF8.GetString(body);
60+
_sslDir = IntegrationFixture.CertificatesDirectory();
61+
_certPassphrase = Environment.GetEnvironmentVariable("PASSWORD");
6162

62-
Assert.Equal(message, resultMessage);
63-
}
63+
_sslConfigured = Directory.Exists(_sslDir) &&
64+
(false == string.IsNullOrEmpty(_certPassphrase));
6465
}
6566

66-
[Fact]
67+
[SkippableFact]
6768
public void TestServerVerifiedIgnoringNameMismatch()
6869
{
69-
string sslDir = IntegrationFixture.CertificatesDirectory();
70-
if (null == sslDir)
71-
{
72-
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
73-
return;
74-
}
70+
Skip.IfNot(_sslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
7571

7672
ConnectionFactory cf = new ConnectionFactory { Port = 5671 };
7773
cf.Ssl.ServerName = "*";
@@ -80,51 +76,36 @@ public void TestServerVerifiedIgnoringNameMismatch()
8076
SendReceive(cf);
8177
}
8278

83-
[Fact]
79+
[SkippableFact]
8480
public void TestServerVerified()
8581
{
86-
string sslDir = IntegrationFixture.CertificatesDirectory();
87-
if (null == sslDir)
88-
{
89-
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
90-
return;
91-
}
82+
Skip.IfNot(_sslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
9283

9384
ConnectionFactory cf = new ConnectionFactory { Port = 5671 };
9485
cf.Ssl.ServerName = System.Net.Dns.GetHostName();
9586
cf.Ssl.Enabled = true;
9687
SendReceive(cf);
9788
}
9889

99-
[Fact]
90+
[SkippableFact]
10091
public void TestClientAndServerVerified()
10192
{
102-
string sslDir = IntegrationFixture.CertificatesDirectory();
103-
if (null == sslDir)
104-
{
105-
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
106-
return;
107-
}
93+
Skip.IfNot(_sslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
10894

95+
string hostName = System.Net.Dns.GetHostName();
10996
ConnectionFactory cf = new ConnectionFactory { Port = 5671 };
110-
cf.Ssl.ServerName = System.Net.Dns.GetHostName();
111-
Assert.NotNull(sslDir);
112-
cf.Ssl.CertPath = $"{sslDir}/client_key.p12";
113-
cf.Ssl.CertPassphrase = Environment.GetEnvironmentVariable("PASSWORD");
97+
cf.Ssl.ServerName = hostName;
98+
cf.Ssl.CertPath = $"{_sslDir}/client_{hostName}_key.p12";
99+
cf.Ssl.CertPassphrase = _certPassphrase;
114100
cf.Ssl.Enabled = true;
115101
SendReceive(cf);
116102
}
117103

118104
// rabbitmq/rabbitmq-dotnet-client#46, also #44 and #45
119-
[Fact]
105+
[SkippableFact]
120106
public void TestNoClientCertificate()
121107
{
122-
string sslDir = IntegrationFixture.CertificatesDirectory();
123-
if (null == sslDir)
124-
{
125-
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
126-
return;
127-
}
108+
Skip.IfNot(_sslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
128109

129110
ConnectionFactory cf = new ConnectionFactory
130111
{
@@ -143,5 +124,29 @@ public void TestNoClientCertificate()
143124

144125
SendReceive(cf);
145126
}
127+
128+
private void SendReceive(ConnectionFactory cf)
129+
{
130+
using (IConnection conn = cf.CreateConnection($"{_testDisplayName}:{Guid.NewGuid()}"))
131+
{
132+
using (IModel ch = conn.CreateModel())
133+
{
134+
ch.ExchangeDeclare("Exchange_TestSslEndPoint", ExchangeType.Direct);
135+
string qName = ch.QueueDeclare();
136+
ch.QueueBind(qName, "Exchange_TestSslEndPoint", "Key_TestSslEndpoint", null);
137+
138+
string message = "Hello C# SSL Client World";
139+
byte[] msgBytes = System.Text.Encoding.UTF8.GetBytes(message);
140+
ch.BasicPublish("Exchange_TestSslEndPoint", "Key_TestSslEndpoint", msgBytes);
141+
142+
bool autoAck = false;
143+
BasicGetResult result = ch.BasicGet(qName, autoAck);
144+
byte[] body = result.Body.ToArray();
145+
string resultMessage = System.Text.Encoding.UTF8.GetString(body);
146+
147+
Assert.Equal(message, resultMessage);
148+
}
149+
}
150+
}
146151
}
147152
}

projects/Unit/Unit.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2323
</PackageReference>
2424
<PackageReference Include="Verify.Xunit" Version="11.18.2" />
25+
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
2526
</ItemGroup>
2627

2728
</Project>

0 commit comments

Comments
 (0)