Skip to content

Fix Concourse CI #1169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _site
Submodule _site updated 152 files
1 change: 0 additions & 1 deletion projects/Unit/TestBasicPublish.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace RabbitMQ.Client.Unit
{

public class TestBasicPublish
{
[Fact]
Expand Down
42 changes: 28 additions & 14 deletions projects/Unit/TestConnectionRecovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,22 @@ public void TestBasicConnectionRecoveryStopsAfterManualClose()
AutorecoveringConnection c = CreateAutorecoveringConnection();
var latch = new AutoResetEvent(false);
c.ConnectionRecoveryError += (o, args) => latch.Set();
StopRabbitMQ();
latch.WaitOne(30000); // we got the failed reconnection event.
bool triedRecoveryAfterClose = false;
c.Close();
Thread.Sleep(5000);
c.ConnectionRecoveryError += (o, args) => triedRecoveryAfterClose = true;
Thread.Sleep(10000);
Assert.False(triedRecoveryAfterClose);
StartRabbitMQ();

try
{
StopRabbitMQ();
latch.WaitOne(30000); // we got the failed reconnection event.
bool triedRecoveryAfterClose = false;
c.Close();
Thread.Sleep(5000);
c.ConnectionRecoveryError += (o, args) => triedRecoveryAfterClose = true;
Thread.Sleep(10000);
Assert.False(triedRecoveryAfterClose);
}
finally
{
StartRabbitMQ();
}
}

[Fact]
Expand Down Expand Up @@ -775,14 +782,21 @@ public void TestShutdownEventHandlersRecoveryOnConnectionAfterDelayedServerResta
ManualResetEventSlim recoveryLatch = PrepareForRecovery((AutorecoveringConnection)_conn);

Assert.True(_conn.IsOpen);
StopRabbitMQ();
Console.WriteLine("Stopped RabbitMQ. About to sleep for multiple recovery intervals...");
Thread.Sleep(7000);
StartRabbitMQ();

try
{
StopRabbitMQ();
Console.WriteLine("Stopped RabbitMQ. About to sleep for multiple recovery intervals...");
Thread.Sleep(7000);
}
finally
{
StartRabbitMQ();
}

Wait(shutdownLatch, TimeSpan.FromSeconds(30));
Wait(recoveryLatch, TimeSpan.FromSeconds(30));
Assert.True(_conn.IsOpen);

Assert.True(counter >= 1);
}

Expand Down
13 changes: 10 additions & 3 deletions projects/Unit/TestFloodPublishing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,22 @@
using RabbitMQ.Client.Events;

using Xunit;
using Xunit.Abstractions;

namespace RabbitMQ.Client.Unit
{

[Collection("IntegrationFixture")]
public class TestFloodPublishing
{
private readonly ITestOutputHelper _output;
private readonly byte[] _body = new byte[2048];
private readonly TimeSpan _tenSeconds = TimeSpan.FromSeconds(10);

public TestFloodPublishing(ITestOutputHelper output)
{
_output = output;
}

[Fact]
public void TestUnthrottledFloodPublishing()
{
Expand Down Expand Up @@ -89,15 +96,15 @@ public void TestUnthrottledFloodPublishing()
finally
{
stopwatch.Stop();
Console.WriteLine($"sent {i}, done in {stopwatch.Elapsed.TotalMilliseconds} ms");
_output.WriteLine($"sent {i}, done in {stopwatch.Elapsed.TotalMilliseconds} ms");
}

Assert.True(conn.IsOpen);
closeWatch.Start();
}
}
closeWatch.Stop();
Console.WriteLine($"Closing took {closeWatch.Elapsed.TotalMilliseconds} ms");
_output.WriteLine($"Closing took {closeWatch.Elapsed.TotalMilliseconds} ms");
}

[Fact]
Expand Down
27 changes: 12 additions & 15 deletions projects/Unit/TestHeartbeats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;

using Xunit;
Expand Down Expand Up @@ -58,14 +59,10 @@ public void TestThatHeartbeatWriterUsesConfigurableInterval()
RunSingleConnectionTest(cf);
}

[Fact]
[SkippableFact]
public void TestThatHeartbeatWriterWithTLSEnabled()
{
if (!LongRunningTestsEnabled())
{
Console.WriteLine("RABBITMQ_LONG_RUNNING_TESTS is not set, skipping test");
return;
}
Skip.IfNot(LongRunningTestsEnabled(), "RABBITMQ_LONG_RUNNING_TESTS is not set, skipping test");

var cf = new ConnectionFactory()
{
Expand All @@ -75,15 +72,15 @@ public void TestThatHeartbeatWriterWithTLSEnabled()
};

string sslDir = IntegrationFixture.CertificatesDirectory();
if (null == sslDir)
{
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
return;
}
cf.Ssl.ServerName = System.Net.Dns.GetHostName();
Assert.NotNull(sslDir);
cf.Ssl.CertPath = $"{sslDir}/client_key.p12";
cf.Ssl.CertPassphrase = Environment.GetEnvironmentVariable("PASSWORD");
string certPassphrase = Environment.GetEnvironmentVariable("PASSWORD");
bool sslConfigured = Directory.Exists(sslDir) &&
(false == string.IsNullOrEmpty(certPassphrase));
Skip.IfNot(sslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");

string hostName = System.Net.Dns.GetHostName();
cf.Ssl.ServerName = hostName;
cf.Ssl.CertPath = $"{sslDir}/client_{hostName}_key.p12";
cf.Ssl.CertPassphrase = certPassphrase;
cf.Ssl.Enabled = true;

RunSingleConnectionTest(cf);
Expand Down
107 changes: 56 additions & 51 deletions projects/Unit/TestSsl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,48 +30,44 @@
//---------------------------------------------------------------------------

using System;
using System.IO;
using System.Net.Security;
using System.Reflection;
using System.Security.Authentication;

using Xunit;
using Xunit.Abstractions;

namespace RabbitMQ.Client.Unit
{

[Collection("IntegrationFixture")]
public class TestSsl
{
private void SendReceive(ConnectionFactory cf)
{
using (IConnection conn = cf.CreateConnection())
{
IModel ch = conn.CreateModel();
private readonly ITestOutputHelper _output;
private readonly string _testDisplayName;
private readonly string _sslDir;
private readonly string _certPassphrase;
private readonly bool _sslConfigured;

ch.ExchangeDeclare("Exchange_TestSslEndPoint", ExchangeType.Direct);
string qName = ch.QueueDeclare();
ch.QueueBind(qName, "Exchange_TestSslEndPoint", "Key_TestSslEndpoint", null);

string message = "Hello C# SSL Client World";
byte[] msgBytes = System.Text.Encoding.UTF8.GetBytes(message);
ch.BasicPublish("Exchange_TestSslEndPoint", "Key_TestSslEndpoint", msgBytes);
public TestSsl(ITestOutputHelper output)
{
_output = output;
var type = _output.GetType();
var testMember = type.GetField("test", BindingFlags.Instance | BindingFlags.NonPublic);
var test = (ITest)testMember.GetValue(output);
_testDisplayName = test.DisplayName;

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

Assert.Equal(message, resultMessage);
}
_sslConfigured = Directory.Exists(_sslDir) &&
(false == string.IsNullOrEmpty(_certPassphrase));
}

[Fact]
[SkippableFact]
public void TestServerVerifiedIgnoringNameMismatch()
{
string sslDir = IntegrationFixture.CertificatesDirectory();
if (null == sslDir)
{
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
return;
}
Skip.IfNot(_sslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");

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

[Fact]
[SkippableFact]
public void TestServerVerified()
{
string sslDir = IntegrationFixture.CertificatesDirectory();
if (null == sslDir)
{
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
return;
}
Skip.IfNot(_sslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");

ConnectionFactory cf = new ConnectionFactory { Port = 5671 };
cf.Ssl.ServerName = System.Net.Dns.GetHostName();
cf.Ssl.Enabled = true;
SendReceive(cf);
}

[Fact]
[SkippableFact]
public void TestClientAndServerVerified()
{
string sslDir = IntegrationFixture.CertificatesDirectory();
if (null == sslDir)
{
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
return;
}
Skip.IfNot(_sslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");

string hostName = System.Net.Dns.GetHostName();
ConnectionFactory cf = new ConnectionFactory { Port = 5671 };
cf.Ssl.ServerName = System.Net.Dns.GetHostName();
Assert.NotNull(sslDir);
cf.Ssl.CertPath = $"{sslDir}/client_key.p12";
cf.Ssl.CertPassphrase = Environment.GetEnvironmentVariable("PASSWORD");
cf.Ssl.ServerName = hostName;
cf.Ssl.CertPath = $"{_sslDir}/client_{hostName}_key.p12";
cf.Ssl.CertPassphrase = _certPassphrase;
cf.Ssl.Enabled = true;
SendReceive(cf);
}

// rabbitmq/rabbitmq-dotnet-client#46, also #44 and #45
[Fact]
[SkippableFact]
public void TestNoClientCertificate()
{
string sslDir = IntegrationFixture.CertificatesDirectory();
if (null == sslDir)
{
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
return;
}
Skip.IfNot(_sslConfigured, "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");

ConnectionFactory cf = new ConnectionFactory
{
Expand All @@ -143,5 +124,29 @@ public void TestNoClientCertificate()

SendReceive(cf);
}

private void SendReceive(ConnectionFactory cf)
{
using (IConnection conn = cf.CreateConnection($"{_testDisplayName}:{Guid.NewGuid()}"))
{
using (IModel ch = conn.CreateModel())
{
ch.ExchangeDeclare("Exchange_TestSslEndPoint", ExchangeType.Direct);
string qName = ch.QueueDeclare();
ch.QueueBind(qName, "Exchange_TestSslEndPoint", "Key_TestSslEndpoint", null);

string message = "Hello C# SSL Client World";
byte[] msgBytes = System.Text.Encoding.UTF8.GetBytes(message);
ch.BasicPublish("Exchange_TestSslEndPoint", "Key_TestSslEndpoint", msgBytes);

bool autoAck = false;
BasicGetResult result = ch.BasicGet(qName, autoAck);
byte[] body = result.Body.ToArray();
string resultMessage = System.Text.Encoding.UTF8.GetString(body);

Assert.Equal(message, resultMessage);
}
}
}
}
}
1 change: 1 addition & 0 deletions projects/Unit/Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Verify.Xunit" Version="11.18.2" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
</ItemGroup>

</Project>