Skip to content
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

Add test that demonstrates the current behavior of a recovered channe… #1450

Merged
merged 1 commit into from
Dec 22, 2023
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
7 changes: 0 additions & 7 deletions projects/Test/Common/RabbitMQCtl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using RabbitMQ.Client;
using Xunit.Abstractions;
Expand Down Expand Up @@ -188,12 +187,6 @@ private static bool IsRunningOnMonoOrDotNetCore()
#endif
}

private static void Publish(IConnection conn, Encoding encoding)
{
IChannel ch = conn.CreateChannel();
ch.BasicPublish("amq.fanout", "", encoding.GetBytes("message"));
}

private static Process CreateProcess(string cmd, string arguments, string workDirectory = null)
{
return new Process
Expand Down
54 changes: 54 additions & 0 deletions projects/Test/SequentialIntegration/TestConnectionRecovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,60 @@ public void TestBasicChannelRecoveryOnServerRestart()
Assert.True(_channel.IsOpen);
}

// https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/1086
[Fact]
public async Task TestChannelAfterDispose_GH1086()
{
TaskCompletionSource<bool> sawChannelShutdownTcs = new TaskCompletionSource<bool>();

void _channel_ChannelShutdown(object sender, ShutdownEventArgs e)
{
sawChannelShutdownTcs.SetResult(true);
}

_channel.ChannelShutdown += _channel_ChannelShutdown;

Assert.True(_channel.IsOpen);

string queueName = GenerateQueueName();
RabbitMQ.Client.QueueDeclareOk queueDeclareOk = await _channel.QueueDeclareAsync(queue: queueName, exclusive: false, autoDelete: false);
Assert.Equal(queueName, queueDeclareOk.QueueName);

byte[] body = GetRandomBody(64);

RestartServerAndWaitForRecovery();

Task publishTask = Task.Run(async () =>
{
while (false == sawChannelShutdownTcs.Task.IsCompleted)
{
try
{
await _channel.BasicPublishAsync(exchange: "", routingKey: queueName, body: body, mandatory: true);
await Task.Delay(TimeSpan.FromSeconds(1));
}
catch (Exception ex)
{
_output.WriteLine($"{_testDisplayName} caught exception: {ex}");
break;
}
}
});

await Task.WhenAny(sawChannelShutdownTcs.Task, publishTask);

bool sawChannelShutdown = await sawChannelShutdownTcs.Task;
Assert.True(sawChannelShutdown);

// This is false because the channel has been recovered
Assert.False(_channel.IsClosed);

_channel.Dispose();
Assert.True(_channel.IsClosed);

await publishTask;
}

[Fact]
public void TestBlockedListenersRecovery()
{
Expand Down