Skip to content

Commit

Permalink
Can't close channel from consumer dispatcher
Browse files Browse the repository at this point in the history
See #1567
  • Loading branch information
lukebakken committed May 14, 2024
1 parent bf9a35a commit d876376
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions projects/Test/Integration/TestAsyncConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,38 @@ public async Task TestDeclarationOfManyAutoDeleteQueuesWithTransientConsumer()
AssertRecordedQueues((RabbitMQ.Client.Framing.Impl.AutorecoveringConnection)_conn, 0);
}

[Fact]
public async Task TestCloseWithinEventHandler_GH1567()
{
var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);

QueueDeclareOk q = await _channel.QueueDeclareAsync();
string queueName = q.QueueName;

var consumer = new AsyncEventingBasicConsumer(_channel);
consumer.Received += async (_, eventArgs) =>
{
await _channel.BasicCancelAsync(eventArgs.ConsumerTag);
// await _channel.CloseAsync();
// _channel.Dispose();
// _channel = null;
tcs.TrySetResult(true);
};

await _channel.BasicConsumeAsync(consumer, queueName, true);

var bp = new BasicProperties();

await _channel.BasicPublishAsync(exchange: string.Empty, routingKey: queueName,
basicProperties: bp, mandatory: true, body: GetRandomBody(64));

Assert.True(await tcs.Task);

await _channel.CloseAsync();
_channel.Dispose();
_channel = null;
}

private static void SetException(Exception ex, params TaskCompletionSource<bool>[] tcsAry)
{
foreach (TaskCompletionSource<bool> tcs in tcsAry)
Expand Down

0 comments on commit d876376

Please sign in to comment.