@@ -194,6 +194,60 @@ public void TestBasicChannelRecoveryOnServerRestart()
194
194
Assert . True ( _channel . IsOpen ) ;
195
195
}
196
196
197
+ // https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/1086
198
+ [ Fact ]
199
+ public async Task TestChannelAfterDispose_GH1086 ( )
200
+ {
201
+ TaskCompletionSource < bool > sawChannelShutdownTcs = new TaskCompletionSource < bool > ( ) ;
202
+
203
+ void _channel_ChannelShutdown ( object sender , ShutdownEventArgs e )
204
+ {
205
+ sawChannelShutdownTcs . SetResult ( true ) ;
206
+ }
207
+
208
+ _channel . ChannelShutdown += _channel_ChannelShutdown ;
209
+
210
+ Assert . True ( _channel . IsOpen ) ;
211
+
212
+ string queueName = GenerateQueueName ( ) ;
213
+ RabbitMQ . Client . QueueDeclareOk queueDeclareOk = await _channel . QueueDeclareAsync ( queue : queueName , exclusive : false , autoDelete : false ) ;
214
+ Assert . Equal ( queueName , queueDeclareOk . QueueName ) ;
215
+
216
+ byte [ ] body = GetRandomBody ( 64 ) ;
217
+
218
+ RestartServerAndWaitForRecovery ( ) ;
219
+
220
+ Task publishTask = Task . Run ( async ( ) =>
221
+ {
222
+ while ( false == sawChannelShutdownTcs . Task . IsCompleted )
223
+ {
224
+ try
225
+ {
226
+ await _channel . BasicPublishAsync ( exchange : "" , routingKey : queueName , body : body , mandatory : true ) ;
227
+ await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
228
+ }
229
+ catch ( Exception ex )
230
+ {
231
+ _output . WriteLine ( $ "{ _testDisplayName } caught exception: { ex } ") ;
232
+ break ;
233
+ }
234
+ }
235
+ } ) ;
236
+
237
+ await Task . WhenAny ( sawChannelShutdownTcs . Task , publishTask ) ;
238
+
239
+ bool sawChannelShutdown = await sawChannelShutdownTcs . Task ;
240
+ Assert . True ( sawChannelShutdown ) ;
241
+
242
+ // This is false because the channel has been recovered
243
+ Assert . False ( _channel . IsClosed ) ;
244
+
245
+ _channel . Dispose ( ) ;
246
+ Assert . True ( _channel . IsClosed ) ;
247
+
248
+ await publishTask ;
249
+ }
250
+
197
251
[ Fact ]
198
252
public void TestBlockedListenersRecovery ( )
199
253
{
0 commit comments