@@ -45,14 +45,11 @@ namespace RabbitMQ.Client.Unit
45
45
public class TestPublisherConfirms : IntegrationFixture
46
46
{
47
47
private const string QueueName = "RabbitMQ.Client.Unit.TestPublisherConfirms" ;
48
- private readonly byte [ ] _body ;
48
+ private readonly byte [ ] _body = new byte [ 4096 ] ;
49
49
50
50
public TestPublisherConfirms ( ITestOutputHelper output ) : base ( output )
51
51
{
52
- var rnd = new Random ( ) ;
53
- _body = new byte [ 4096 ] ;
54
- rnd . NextBytes ( _body ) ;
55
-
52
+ Random . Shared . NextBytes ( _body ) ;
56
53
}
57
54
58
55
[ Fact ]
@@ -77,15 +74,30 @@ public void TestWaitForConfirmsWithTimeout()
77
74
}
78
75
79
76
[ Fact ]
80
- public void TestWaitForConfirmsWithTimeout_AllMessagesAcked_WaitingHasTimedout_ReturnTrue ( )
77
+ public void TestWaitForConfirmsWithTimeout_MightThrowTaskCanceledException ( )
81
78
{
79
+ bool waitResult = false ;
80
+ bool sawTaskCanceled = false ;
81
+
82
82
TestWaitForConfirms ( 10000 , ( ch ) =>
83
83
{
84
84
using ( var cts = new CancellationTokenSource ( TimeSpan . FromMilliseconds ( 1 ) ) )
85
85
{
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
+ }
87
94
}
88
95
} ) ;
96
+
97
+ if ( waitResult == false && sawTaskCanceled == false )
98
+ {
99
+ Assert . Fail ( "test failed, both waitResult and sawTaskCanceled are still false" ) ;
100
+ }
89
101
}
90
102
91
103
[ Fact ]
@@ -147,12 +159,14 @@ protected void TestWaitForConfirms(int numberOfMessagesToPublish, Action<IChanne
147
159
{
148
160
using ( IChannel ch = _conn . CreateChannel ( ) )
149
161
{
162
+ var props = new BasicProperties { Persistent = true } ;
163
+
150
164
ch . ConfirmSelect ( ) ;
151
165
ch . QueueDeclare ( QueueName ) ;
152
166
153
167
for ( int i = 0 ; i < numberOfMessagesToPublish ; i ++ )
154
168
{
155
- ch . BasicPublish ( "" , QueueName , _body ) ;
169
+ ch . BasicPublish ( exchange : "" , routingKey : QueueName , body : _body , mandatory : true , basicProperties : props ) ;
156
170
}
157
171
158
172
try
0 commit comments