@@ -45,14 +45,11 @@ namespace RabbitMQ.Client.Unit
4545 public class TestPublisherConfirms : IntegrationFixture
4646 {
4747 private const string QueueName = "RabbitMQ.Client.Unit.TestPublisherConfirms" ;
48- private readonly byte [ ] _body ;
48+ private readonly byte [ ] _body = new byte [ 4096 ] ;
4949
5050 public TestPublisherConfirms ( ITestOutputHelper output ) : base ( output )
5151 {
52- var rnd = new Random ( ) ;
53- _body = new byte [ 4096 ] ;
54- rnd . NextBytes ( _body ) ;
55-
52+ Random . Shared . NextBytes ( _body ) ;
5653 }
5754
5855 [ Fact ]
@@ -77,15 +74,30 @@ public void TestWaitForConfirmsWithTimeout()
7774 }
7875
7976 [ Fact ]
80- public void TestWaitForConfirmsWithTimeout_AllMessagesAcked_WaitingHasTimedout_ReturnTrue ( )
77+ public void TestWaitForConfirmsWithTimeout_MightThrowTaskCanceledException ( )
8178 {
79+ bool waitResult = false ;
80+ bool sawTaskCanceled = false ;
81+
8282 TestWaitForConfirms ( 10000 , ( ch ) =>
8383 {
8484 using ( var cts = new CancellationTokenSource ( TimeSpan . FromMilliseconds ( 1 ) ) )
8585 {
86- Assert . Throws < TaskCanceledException > ( ( ) => ch . WaitForConfirmsAsync ( cts . Token ) . GetAwaiter ( ) . GetResult ( ) ) ;
86+ try
87+ {
88+ waitResult = ch . WaitForConfirmsAsync ( cts . Token ) . GetAwaiter ( ) . GetResult ( ) ;
89+ }
90+ catch ( TaskCanceledException )
91+ {
92+ sawTaskCanceled = true ;
93+ }
8794 }
8895 } ) ;
96+
97+ if ( waitResult == false && sawTaskCanceled == false )
98+ {
99+ Assert . Fail ( "test failed, both waitResult and sawTaskCanceled are still false" ) ;
100+ }
89101 }
90102
91103 [ Fact ]
@@ -147,12 +159,14 @@ protected void TestWaitForConfirms(int numberOfMessagesToPublish, Action<IChanne
147159 {
148160 using ( IChannel ch = _conn . CreateChannel ( ) )
149161 {
162+ var props = new BasicProperties { Persistent = true } ;
163+
150164 ch . ConfirmSelect ( ) ;
151165 ch . QueueDeclare ( QueueName ) ;
152166
153167 for ( int i = 0 ; i < numberOfMessagesToPublish ; i ++ )
154168 {
155- ch . BasicPublish ( "" , QueueName , _body ) ;
169+ ch . BasicPublish ( exchange : "" , routingKey : QueueName , body : _body , mandatory : true , basicProperties : props ) ;
156170 }
157171
158172 try
0 commit comments