Skip to content

Commit 89a9636

Browse files
One more test
1 parent 8d8c23b commit 89a9636

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

projects/client/Unit/src/unit/TestPublisherConfirms.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
using NUnit.Framework;
4242
using System;
43+
using System.Threading;
4344
using RabbitMQ.Client;
4445

4546
namespace RabbitMQ.Client.Unit
@@ -65,6 +66,43 @@ public void TestWaitForConfirmsWithTimeout()
6566
}); ;
6667
}
6768

69+
[Test]
70+
public void TestWaitForConfirmsWithEvents()
71+
{
72+
var ch = Conn.CreateModel();
73+
ch.ConfirmSelect();
74+
75+
var q = ch.QueueDeclare().QueueName;
76+
var n = 200;
77+
// number of event handler invocations
78+
var c = 0;
79+
80+
ch.BasicAcks += (_, args) =>
81+
{
82+
Interlocked.Increment(ref c);
83+
};
84+
try
85+
{
86+
for (int i = 0; i < n; i++)
87+
{
88+
ch.BasicPublish("", q, null, encoding.GetBytes("msg"));
89+
}
90+
Thread.Sleep(TimeSpan.FromSeconds(1));
91+
ch.WaitForConfirms(TimeSpan.FromSeconds(5));
92+
93+
// Note: number of event invocations is not guaranteed
94+
// to be equal to N because acks can be batched,
95+
// so we primarily care about event handlers being invoked
96+
// in this test
97+
Assert.IsTrue(c > 20);
98+
}
99+
finally
100+
{
101+
ch.QueueDelete(q);
102+
ch.Close();
103+
}
104+
}
105+
68106
protected void TestWaitForConfirms(int numberOfMessagesToPublish, Action<IModel> fn)
69107
{
70108
var ch = Conn.CreateModel();

0 commit comments

Comments
 (0)