@@ -96,25 +96,28 @@ await _channel.ExchangeDeclareAsync(exchange: exchangeName, ExchangeType.Fanout,
9696 {
9797 async Task f ( )
9898 {
99- try
99+ using ( IChannel ch = await _conn . CreateChannelAsync ( ) )
100100 {
101- // sleep for a random amount of time to increase the chances
102- // of thread interleaving. MK.
103- await Task . Delay ( S_Random . Next ( 5 , 50 ) ) ;
104- QueueName queueName = GenerateQueueName ( ) ;
105- QueueDeclareOk r = await _channel . QueueDeclareAsync ( queue : queueName ,
106- durable : false , exclusive : true , autoDelete : false ) ;
107- Assert . Equal ( queueName , r . QueueName ) ;
108- await _channel . QueueBindAsync ( queue : queueName ,
109- exchange : exchangeName , routingKey : ( RoutingKey ) queueName ) ;
110- if ( false == queueNames . TryAdd ( queueName , true ) )
101+ try
111102 {
112- throw new InvalidOperationException ( $ "queue with name { queueName } already added!") ;
103+ // sleep for a random amount of time to increase the chances
104+ // of thread interleaving. MK.
105+ await Task . Delay ( S_Random . Next ( 5 , 50 ) ) ;
106+ QueueName queueName = GenerateQueueName ( ) ;
107+ QueueDeclareOk r = await ch . QueueDeclareAsync ( queue : queueName ,
108+ durable : false , exclusive : true , autoDelete : false ) ;
109+ Assert . Equal ( queueName , r . QueueName ) ;
110+ await ch . QueueBindAsync ( queue : queueName ,
111+ exchange : exchangeName , routingKey : ( RoutingKey ) queueName ) ;
112+ if ( false == queueNames . TryAdd ( queueName , true ) )
113+ {
114+ throw new InvalidOperationException ( $ "queue with name { queueName } already added!") ;
115+ }
116+ }
117+ catch ( NotSupportedException e )
118+ {
119+ nse = e ;
113120 }
114- }
115- catch ( NotSupportedException e )
116- {
117- nse = e ;
118121 }
119122 }
120123 var t = Task . Run ( f ) ;
@@ -131,23 +134,26 @@ await _channel.QueueBindAsync(queue: queueName,
131134 async Task f ( )
132135 {
133136 QueueName qname = q ;
134- try
137+ using ( IChannel ch = await _conn . CreateChannelAsync ( ) )
135138 {
136- await Task . Delay ( S_Random . Next ( 5 , 50 ) ) ;
139+ try
140+ {
141+ await Task . Delay ( S_Random . Next ( 5 , 50 ) ) ;
137142
138- QueueDeclareOk r = await _channel . QueueDeclarePassiveAsync ( qname ) ;
139- Assert . Equal ( qname , r . QueueName ) ;
140- Assert . Equal ( ( uint ) 0 , r . MessageCount ) ;
143+ QueueDeclareOk r = await ch . QueueDeclarePassiveAsync ( qname ) ;
144+ Assert . Equal ( qname , r . QueueName ) ;
145+ Assert . Equal ( ( uint ) 0 , r . MessageCount ) ;
141146
142- await _channel . QueueUnbindAsync ( queue : qname ,
143- exchange : exchangeName , routingKey : ( RoutingKey ) qname , null ) ;
147+ await ch . QueueUnbindAsync ( queue : qname ,
148+ exchange : exchangeName , routingKey : ( RoutingKey ) qname , null ) ;
144149
145- uint deletedMessageCount = await _channel . QueueDeleteAsync ( qname , false , false ) ;
146- Assert . Equal ( ( uint ) 0 , deletedMessageCount ) ;
147- }
148- catch ( NotSupportedException e )
149- {
150- nse = e ;
150+ uint deletedMessageCount = await ch . QueueDeleteAsync ( qname , false , false ) ;
151+ Assert . Equal ( ( uint ) 0 , deletedMessageCount ) ;
152+ }
153+ catch ( NotSupportedException e )
154+ {
155+ nse = e ;
156+ }
151157 }
152158 }
153159 var t = Task . Run ( f ) ;
@@ -169,18 +175,21 @@ public async Task TestConcurrentQueueDeclare()
169175 {
170176 var t = Task . Run ( async ( ) =>
171177 {
172- try
178+ using ( IChannel ch = await _conn . CreateChannelAsync ( ) )
173179 {
174- // sleep for a random amount of time to increase the chances
175- // of thread interleaving. MK.
176- await Task . Delay ( S_Random . Next ( 5 , 50 ) ) ;
177- QueueName q = GenerateQueueName ( ) ;
178- await _channel . QueueDeclareAsync ( q , false , false , false ) ;
179- queueNames . Add ( q ) ;
180- }
181- catch ( NotSupportedException e )
182- {
183- nse = e ;
180+ try
181+ {
182+ // sleep for a random amount of time to increase the chances
183+ // of thread interleaving. MK.
184+ await Task . Delay ( S_Random . Next ( 5 , 50 ) ) ;
185+ QueueName q = GenerateQueueName ( ) ;
186+ await ch . QueueDeclareAsync ( q , false , false , false ) ;
187+ queueNames . Add ( q ) ;
188+ }
189+ catch ( NotSupportedException e )
190+ {
191+ nse = e ;
192+ }
184193 }
185194 } ) ;
186195 tasks . Add ( t ) ;
@@ -196,14 +205,17 @@ public async Task TestConcurrentQueueDeclare()
196205 QueueName q = queueName ;
197206 var t = Task . Run ( async ( ) =>
198207 {
199- try
200- {
201- await Task . Delay ( S_Random . Next ( 5 , 50 ) ) ;
202- await _channel . QueueDeleteAsync ( queueName ) ;
203- }
204- catch ( NotSupportedException e )
208+ using ( IChannel ch = await _conn . CreateChannelAsync ( ) )
205209 {
206- nse = e ;
210+ try
211+ {
212+ await Task . Delay ( S_Random . Next ( 5 , 50 ) ) ;
213+ await ch . QueueDeleteAsync ( queueName ) ;
214+ }
215+ catch ( NotSupportedException e )
216+ {
217+ nse = e ;
218+ }
207219 }
208220 } ) ;
209221 tasks . Add ( t ) ;
0 commit comments