Skip to content

Commit

Permalink
Implement async for simple AMQP methods
Browse files Browse the repository at this point in the history
Related to:
* #1345
* #1308
* #970
* #843
  • Loading branch information
lukebakken committed May 11, 2023
1 parent c69bf00 commit 73e3f51
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
35 changes: 34 additions & 1 deletion projects/Unit/TestExchangeDeclare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
using System;
using System.Collections.Generic;
using System.Threading;

using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -81,5 +81,38 @@ public void TestConcurrentExchangeDeclare()
Assert.Null(nse);
_channel.ExchangeDelete(x);
}

[Fact]
public async void TestConcurrentExchangeDeclareAsync()
{
string x = GenerateExchangeName();
var rnd = new Random();

var ts = new List<Task>();
NotSupportedException nse = null;
for (int i = 0; i < 256; i++)
{
async Task f()
{
try
{
// sleep for a random amount of time to increase the chances
// of thread interleaving. MK.
await Task.Delay(rnd.Next(5, 50));
await _channel.ExchangeDeclareAsync(x, "fanout", false, false, null);
}
catch (NotSupportedException e)
{
nse = e;
}
}
var t = Task.Run(f);
ts.Add(t);
}

await Task.WhenAll(ts);
Assert.Null(nse);
await _channel.ExchangeDeleteAsync(x);
}
}
}
5 changes: 2 additions & 3 deletions projects/Unit/TestQueueDeclare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public async void TestQueueDeclareAsync()
}

[Fact]
[Trait("Category", "RequireSMP")]
public void TestConcurrentQueueDeclare()
{
string q = GenerateQueueName();
Expand Down Expand Up @@ -91,7 +90,6 @@ public void TestConcurrentQueueDeclare()
}

[Fact]
[Trait("Category", "RequireSMP")]
public async void TestConcurrentQueueDeclareAsync()
{
string q = GenerateQueueName();
Expand Down Expand Up @@ -121,7 +119,8 @@ async Task f()

await Task.WhenAll(ts);
Assert.Null(nse);
_channel.QueueDelete(q);
uint c = await _channel.QueueDeleteAsync(q);
Assert.Equal(1, c);
}
}
}

0 comments on commit 73e3f51

Please sign in to comment.