Skip to content

Commit 2ef965b

Browse files
authored
Merge pull request #1460 from rabbitmq/rabbitmq-dotnet-client-1035
Add test to prove bindings are restored by topology recovery
2 parents 317a633 + 8840859 commit 2ef965b

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

projects/Test/Common/IntegrationFixtureBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ protected static string GetUniqueString(ushort length)
479479
return Convert.ToBase64String(bytes);
480480
}
481481

482-
protected static byte[] GetRandomBody(ushort size)
482+
protected static byte[] GetRandomBody(ushort size = 1024)
483483
{
484484
var body = new byte[size];
485485
#if NET6_0_OR_GREATER

projects/Test/SequentialIntegration/TestConnectionRecovery.cs

+59
Original file line numberDiff line numberDiff line change
@@ -882,5 +882,64 @@ public void TestUnblockedListenersRecovery()
882882
Unblock();
883883
Wait(latch, "connection unblocked");
884884
}
885+
886+
[Fact]
887+
public void TestBindingRecovery_GH1035()
888+
{
889+
const string routingKey = "unused";
890+
byte[] body = GetRandomBody();
891+
892+
using var receivedMessageEvent = new AutoResetEvent(initialState: false);
893+
894+
void MessageReceived(object sender, BasicDeliverEventArgs e)
895+
{
896+
receivedMessageEvent.Set();
897+
}
898+
899+
string exchangeName = $"ex-gh-1035-{Guid.NewGuid()}";
900+
string queueName = $"q-gh-1035-{Guid.NewGuid()}";
901+
902+
_channel.ExchangeDeclare(exchange: exchangeName,
903+
type: "fanout", durable: false, autoDelete: true,
904+
arguments: null);
905+
906+
RabbitMQ.Client.QueueDeclareOk q0 = _channel.QueueDeclare(queue: queueName, exclusive: true);
907+
Assert.Equal(queueName, q0);
908+
909+
_channel.QueueBind(queue: queueName, exchange: exchangeName, routingKey: routingKey);
910+
911+
_channel.Dispose();
912+
913+
_channel = _conn.CreateChannel();
914+
915+
_channel.ExchangeDeclare(exchange: exchangeName,
916+
type: "fanout", durable: false, autoDelete: true,
917+
arguments: null);
918+
919+
RabbitMQ.Client.QueueDeclareOk q1 = _channel.QueueDeclare(queue: queueName, exclusive: true);
920+
Assert.Equal(queueName, q1.QueueName);
921+
922+
_channel.QueueBind(queue: queueName, exchange: exchangeName, routingKey: routingKey);
923+
924+
var c = new EventingBasicConsumer(_channel);
925+
c.Received += MessageReceived;
926+
_channel.BasicConsume(queue: queueName, autoAck: true, consumer: c);
927+
928+
using (IChannel pubCh = _conn.CreateChannel())
929+
{
930+
pubCh.BasicPublish(exchange: exchangeName, routingKey: routingKey, body: body);
931+
}
932+
933+
Assert.True(receivedMessageEvent.WaitOne(WaitSpan));
934+
935+
CloseAndWaitForRecovery();
936+
937+
using (IChannel pubCh = _conn.CreateChannel())
938+
{
939+
pubCh.BasicPublish(exchange: exchangeName, routingKey: "unused", body: body);
940+
}
941+
942+
Assert.True(receivedMessageEvent.WaitOne(WaitSpan));
943+
}
885944
}
886945
}

0 commit comments

Comments
 (0)