Skip to content

Commit 642e57b

Browse files
Add timeout to this test
1 parent f14257d commit 642e57b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
using System;
4444
using System.Text;
4545
using System.Threading;
46+
using System.Collections.Generic;
47+
using System.Timers;
4648

4749
using RabbitMQ.Client.Exceptions;
4850
using RabbitMQ.Client.Events;
@@ -110,16 +112,23 @@ private class SubscriptionDrainer
110112
{
111113
protected Subscription m_subscription;
112114
protected bool m_ack;
115+
protected System.Timers.Timer m_timer;
116+
protected volatile bool shouldStop = false;
113117

114118
public SubscriptionDrainer(Subscription sub, bool ack)
115119
{
116120
m_subscription = sub;
117121
m_ack = ack;
122+
m_timer = new System.Timers.Timer(5000);
123+
m_timer.Elapsed += delegate (object o, ElapsedEventArgs args)
124+
{
125+
shouldStop = true;
126+
};
127+
m_timer.Enabled = true;
118128
}
119129

120130
public void Drain()
121131
{
122-
bool shouldStop = false;
123132
#pragma warning disable 0168
124133
try
125134
{
@@ -157,7 +166,11 @@ protected void PostProcess()
157166
[Test]
158167
public void TestConcurrentIterationAndAck()
159168
{
160-
string q = Model.QueueDeclare();
169+
IDictionary<string, object> args = new Dictionary<string, object>
170+
{
171+
{"x-message-ttl", 5000}
172+
};
173+
string q = Model.QueueDeclare("", false, true, false, args);
161174
Subscription sub = new Subscription(Model, q, false);
162175

163176
PreparedQueue(q);
@@ -172,7 +185,11 @@ public void TestConcurrentIterationAndAck()
172185
[Test]
173186
public void TestConcurrentIterationAndNack()
174187
{
175-
string q = Model.QueueDeclare();
188+
IDictionary<string, object> args = new Dictionary<string, object>
189+
{
190+
{"x-message-ttl", 5000}
191+
};
192+
string q = Model.QueueDeclare("", false, true, false, args);
176193
Subscription sub = new Subscription(Model, q, false);
177194

178195
PreparedQueue(q);

0 commit comments

Comments
 (0)