Skip to content
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
10 changes: 8 additions & 2 deletions projects/RabbitMQ.Client/client/impl/ModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,10 @@ public void HandleBasicCancelOk(string consumerTag)
k.m_consumer = DefaultConsumer;
}

ConsumerDispatcher.HandleBasicCancelOk(k.m_consumer, consumerTag);
if (!(k.m_consumer is null))
{
ConsumerDispatcher.HandleBasicCancelOk(k.m_consumer, consumerTag);
}

k.HandleCommand(IncomingCommand.Empty); // release the continuation.
}
Expand Down Expand Up @@ -1073,7 +1076,10 @@ public void BasicCancel(string consumerTag)
_consumers.Remove(consumerTag);
}

ModelShutdown -= k.m_consumer.HandleModelShutdown;
if (!(k.m_consumer is null))
{
ModelShutdown -= k.m_consumer.HandleModelShutdown;
}
}

public void BasicCancelNoWait(string consumerTag)
Expand Down
37 changes: 37 additions & 0 deletions projects/Unit/TestBasicCancelAnyConsumer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Threading;
using NUnit.Framework;
using RabbitMQ.Client.Events;

namespace RabbitMQ.Client.Unit
{
[TestFixture]
public class TestBasicCancelAnyConsumer : IntegrationFixture
{
[Test]
public void TestBasicCancelWithQueueDelete()
{
// Arrange
Exception modelException = null;
Model.CallbackException += HandleCallbackException;
Model.QueueDeclare(TestContext.CurrentContext.Test.Name, false, false, false);
string consumerTag = Model.BasicConsume(TestContext.CurrentContext.Test.Name, false, new VoidConsumer());

// Act
WithTemporaryModel(m => m.QueueDelete(TestContext.CurrentContext.Test.Name));
TestDelegate act = () => Model.BasicCancel(consumerTag);

// Assert
Assert.DoesNotThrow(act);
SpinWait.SpinUntil(() => !(modelException is null), TimingFixture.TestTimeout);
Assert.IsNull(modelException, "The model has thrown an exception when cancelling a consumer after the queue has been deleted. This exception comes from the scheduling of CancelOk Action.");

// Cleanup
Model.CallbackException -= HandleCallbackException;

void HandleCallbackException(object sender, CallbackExceptionEventArgs e) => modelException = e.Exception;
}

private sealed class VoidConsumer : DefaultBasicConsumer{}
}
}
Loading