@@ -623,9 +623,9 @@ public async Task TestCreateChannelWithinAsyncConsumerCallback_GH650()
623
623
} ) ;
624
624
} ;
625
625
626
- // queue1 -> produce click to queue2
626
+ // queue1 -> produce click to queue2
627
627
// click -> exchange
628
- // queue2 -> consume click from queue1
628
+ // queue2 -> consume click from queue1
629
629
await _channel . ExchangeDeclareAsync ( exchangeName , ExchangeType . Direct , autoDelete : true ) ;
630
630
await _channel . QueueDeclareAsync ( queue1Name ) ;
631
631
await _channel . QueueBindAsync ( queue1Name , exchangeName , queue1Name ) ;
@@ -660,6 +660,38 @@ public async Task TestCreateChannelWithinAsyncConsumerCallback_GH650()
660
660
Assert . True ( await tcs . Task ) ;
661
661
}
662
662
663
+ [ Fact ]
664
+ public async Task TestCloseWithinEventHandler_GH1567 ( )
665
+ {
666
+ var tcs = new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
667
+
668
+ QueueDeclareOk q = await _channel . QueueDeclareAsync ( ) ;
669
+ string queueName = q . QueueName ;
670
+
671
+ var consumer = new AsyncEventingBasicConsumer ( _channel ) ;
672
+ consumer . Received += async ( _ , eventArgs ) =>
673
+ {
674
+ await _channel . BasicCancelAsync ( eventArgs . ConsumerTag ) ;
675
+ #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
676
+ _channel . CloseAsync ( ) . ContinueWith ( ( _ ) =>
677
+ {
678
+ _channel . Dispose ( ) ;
679
+ _channel = null ;
680
+ } ) ;
681
+ #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
682
+ tcs . TrySetResult ( true ) ;
683
+ } ;
684
+
685
+ await _channel . BasicConsumeAsync ( consumer , queueName , true ) ;
686
+
687
+ var bp = new BasicProperties ( ) ;
688
+
689
+ await _channel . BasicPublishAsync ( exchange : string . Empty , routingKey : queueName ,
690
+ basicProperties : bp , mandatory : true , body : GetRandomBody ( 64 ) ) ;
691
+
692
+ Assert . True ( await tcs . Task ) ;
693
+ }
694
+
663
695
private static void SetException ( Exception ex , params TaskCompletionSource < bool > [ ] tcsAry )
664
696
{
665
697
foreach ( TaskCompletionSource < bool > tcs in tcsAry )
0 commit comments