@@ -108,7 +108,7 @@ public void TestSubscriptionNack()
108
108
Assert . AreEqual ( 0 , ok . MessageCount ) ;
109
109
}
110
110
111
- private class SubscriptionDrainer
111
+ protected class SubscriptionDrainer
112
112
{
113
113
protected Subscription m_subscription ;
114
114
protected bool m_ack ;
@@ -132,23 +132,25 @@ public void Drain()
132
132
#pragma warning disable 0168
133
133
try
134
134
{
135
- while ( ! shouldStop )
135
+ for ( int i = 0 ; i < 1000 ; i ++ )
136
136
{
137
137
BasicDeliverEventArgs ea = m_subscription . Next ( ) ;
138
138
if ( ea != null )
139
139
{
140
140
Assert . That ( ea , Is . TypeOf ( typeof ( BasicDeliverEventArgs ) ) ) ;
141
141
PostProcess ( ) ;
142
142
} else
143
- {
144
- shouldStop = true ;
145
- }
143
+ {
144
+ break ;
145
+ }
146
146
}
147
147
} catch ( AlreadyClosedException ace )
148
148
{
149
- shouldStop = true ;
149
+ // expected
150
150
}
151
151
#pragma warning restore
152
+
153
+ m_subscription . Close ( ) ;
152
154
}
153
155
154
156
protected void PostProcess ( )
@@ -166,24 +168,16 @@ protected void PostProcess()
166
168
[ Test ]
167
169
public void TestConcurrentIterationAndAck ( )
168
170
{
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 ) ;
174
- Subscription sub = new Subscription ( Model , q , false ) ;
175
-
176
- PreparedQueue ( q ) ;
177
- for ( int i = 0 ; i < 10 ; i ++ )
178
- {
179
- SubscriptionDrainer drainer = new SubscriptionDrainer ( sub , true ) ;
180
- Thread t = new Thread ( drainer . Drain ) ;
181
- t . Start ( ) ;
182
- }
171
+ TestConcurrentIterationWithDrainer ( true ) ;
183
172
}
184
173
185
174
[ Test ]
186
175
public void TestConcurrentIterationAndNack ( )
176
+ {
177
+ TestConcurrentIterationWithDrainer ( false ) ;
178
+ }
179
+
180
+ protected void TestConcurrentIterationWithDrainer ( bool ack )
187
181
{
188
182
IDictionary < string , object > args = new Dictionary < string , object >
189
183
{
@@ -193,12 +187,20 @@ public void TestConcurrentIterationAndNack()
193
187
Subscription sub = new Subscription ( Model , q , false ) ;
194
188
195
189
PreparedQueue ( q ) ;
190
+
191
+ List < Thread > ts = new List < Thread > ( ) ;
196
192
for ( int i = 0 ; i < 10 ; i ++ )
197
193
{
198
- SubscriptionDrainer drainer = new SubscriptionDrainer ( sub , false ) ;
194
+ SubscriptionDrainer drainer = new SubscriptionDrainer ( sub , ack ) ;
199
195
Thread t = new Thread ( drainer . Drain ) ;
196
+ ts . Add ( t ) ;
200
197
t . Start ( ) ;
201
198
}
199
+
200
+ foreach ( Thread t in ts )
201
+ {
202
+ t . Join ( ) ;
203
+ }
202
204
}
203
205
204
206
private void PreparedQueue ( string q )
0 commit comments