Skip to content

Commit f331ddf

Browse files
committed
Fix cancellation of RPC methods
Fixes #1750 * Start by adding a test that reproduces the error. Give a 5ms cancellation to `BasicConsumeAsync`, with a much longer delay via Toxiproxy. If running in debug mode, you will see the same `task canceled` exception, but it does not propagate to the test itself.
1 parent a2a0967 commit f331ddf

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

projects/Test/Integration/TestToxiproxy.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
using System.Threading.Tasks;
3737
using Integration;
3838
using RabbitMQ.Client;
39+
using RabbitMQ.Client.Events;
3940
using RabbitMQ.Client.Exceptions;
4041
using Toxiproxy.Net.Toxics;
4142
using Xunit;
@@ -409,6 +410,47 @@ public async Task TestPublisherConfirmationThrottling()
409410
Assert.Equal(TotalMessageCount, publishCount);
410411
}
411412

413+
[SkippableFact]
414+
[Trait("Category", "Toxiproxy")]
415+
public async Task TestBasicConsumeCancellation_GH1750()
416+
{
417+
Skip.IfNot(AreToxiproxyTestsEnabled, "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test");
418+
Assert.NotNull(_toxiproxyManager);
419+
Assert.Null(_conn);
420+
Assert.Null(_channel);
421+
422+
ConnectionFactory cf = CreateConnectionFactory();
423+
cf.AutomaticRecoveryEnabled = false;
424+
cf.TopologyRecoveryEnabled = false;
425+
426+
cf.Endpoint = new AmqpTcpEndpoint(IPAddress.Loopback.ToString(), _proxyPort);
427+
_conn = await cf.CreateConnectionAsync();
428+
_channel = await _conn.CreateChannelAsync();
429+
430+
QueueDeclareOk q = await _channel.QueueDeclareAsync();
431+
432+
var consumer = new AsyncEventingBasicConsumer(_channel);
433+
consumer.ReceivedAsync += (o, a) =>
434+
{
435+
return Task.CompletedTask;
436+
};
437+
438+
string toxicName = $"rmq-localhost-delay-{Now}-{GenerateShortUuid()}";
439+
var latencyToxic = new LatencyToxic
440+
{
441+
Name = toxicName
442+
};
443+
latencyToxic.Attributes.Latency = 500;
444+
latencyToxic.Toxicity = 1.0;
445+
latencyToxic.Stream = ToxicDirection.DownStream;
446+
447+
Task<LatencyToxic> addToxicTask = _toxiproxyManager.AddToxicAsync(latencyToxic);
448+
await addToxicTask.WaitAsync(WaitSpan);
449+
450+
using var cts = new CancellationTokenSource(5);
451+
await _channel.BasicConsumeAsync(q.QueueName, true, consumer, cts.Token);
452+
}
453+
412454
private bool AreToxiproxyTestsEnabled
413455
{
414456
get

0 commit comments

Comments
 (0)