@@ -44,10 +44,8 @@ public void Reset()
44
44
public int CurrentAttempt => 1 ;
45
45
}
46
46
47
- public class ConnectionRecoveryTests ( ITestOutputHelper testOutputHelper )
47
+ public class ConnectionRecoveryTests ( ITestOutputHelper testOutputHelper ) : IntegrationTest ( testOutputHelper )
48
48
{
49
- private readonly ITestOutputHelper _testOutputHelper = testOutputHelper ;
50
-
51
49
/// <summary>
52
50
/// The normal close the status should be correct and error null
53
51
/// The test records the status change when the connection is closed normally.
@@ -59,12 +57,13 @@ public class ConnectionRecoveryTests(ITestOutputHelper testOutputHelper)
59
57
[ InlineData ( false ) ]
60
58
public async Task NormalCloseTheStatusShouldBeCorrectAndErrorNull ( bool activeRecovery )
61
59
{
62
- string containerId = Guid . NewGuid ( ) . ToString ( ) ;
60
+ string localContainerId = $ "{ _containerId } _normal-close-connection-name";
61
+
63
62
IConnection connection = await AmqpConnection . CreateAsync (
64
- ConnectionSettingBuilder . Create ( ) . ContainerId ( containerId ) . RecoveryConfiguration (
63
+ ConnectionSettingBuilder . Create ( ) . ContainerId ( localContainerId ) . RecoveryConfiguration (
65
64
RecoveryConfiguration . Create ( ) . Activated ( activeRecovery ) . Topology ( false ) ) . Build ( ) ) ;
66
65
67
- TaskCompletionSource < bool > connectionClosedStateTcs = CreateTaskCompletionSource ( ) ;
66
+ TaskCompletionSource < bool > connectionClosedStateTcs = CreateTaskCompletionSource < bool > ( ) ;
68
67
var listFromStatus = new List < State > ( ) ;
69
68
var listToStatus = new List < State > ( ) ;
70
69
var listError = new List < Error ? > ( ) ;
@@ -105,14 +104,16 @@ public async Task NormalCloseTheStatusShouldBeCorrectAndErrorNull(bool activeRec
105
104
[ Fact ]
106
105
public async Task UnexpectedCloseTheStatusShouldBeCorrectAndErrorNotNull ( )
107
106
{
108
- const string containerId = "unexpected-close-connection-name" ;
107
+
108
+ string localContainerId = $ "{ _containerId } _unexpected-close-connection-name";
109
+
109
110
IConnection connection = await AmqpConnection . CreateAsync (
110
- ConnectionSettingBuilder . Create ( ) . ContainerId ( containerId ) . RecoveryConfiguration (
111
+ ConnectionSettingBuilder . Create ( ) . ContainerId ( localContainerId ) . RecoveryConfiguration (
111
112
RecoveryConfiguration . Create ( ) . Activated ( true ) . Topology ( false )
112
113
. BackOffDelayPolicy ( new FakeFastBackOffDelay ( ) ) ) . Build ( ) ) ;
113
114
114
- TaskCompletionSource < bool > listErrorCountGreaterThanOrEqualToTwoTcs = CreateTaskCompletionSource ( ) ;
115
- TaskCompletionSource < bool > listErrorCountGreaterThanOrEqualToFourTcs = CreateTaskCompletionSource ( ) ;
115
+ TaskCompletionSource < bool > listErrorCountGreaterThanOrEqualToTwoTcs = CreateTaskCompletionSource < bool > ( ) ;
116
+ TaskCompletionSource < bool > listErrorCountGreaterThanOrEqualToFourTcs = CreateTaskCompletionSource < bool > ( ) ;
116
117
117
118
var listFromStatus = new List < State > ( ) ;
118
119
var listToStatus = new List < State > ( ) ;
@@ -129,6 +130,7 @@ public async Task UnexpectedCloseTheStatusShouldBeCorrectAndErrorNotNull()
129
130
// Note: must use try since it'll be called again
130
131
listErrorCountGreaterThanOrEqualToTwoTcs . TrySetResult ( true ) ;
131
132
}
133
+
132
134
if ( listError . Count >= 4 )
133
135
{
134
136
listErrorCountGreaterThanOrEqualToFourTcs . SetResult ( true ) ;
@@ -142,7 +144,7 @@ public async Task UnexpectedCloseTheStatusShouldBeCorrectAndErrorNotNull()
142
144
} ;
143
145
144
146
Assert . Equal ( State . Open , connection . State ) ;
145
- await SystemUtils . WaitUntilConnectionIsKilled ( containerId ) ;
147
+ await SystemUtils . WaitUntilConnectionIsKilled ( localContainerId ) ;
146
148
await listErrorCountGreaterThanOrEqualToTwoTcs . Task . WaitAsync ( TimeSpan . FromSeconds ( 5 ) ) ;
147
149
148
150
Assert . Equal ( State . Open , listFromStatus [ 0 ] ) ;
@@ -175,15 +177,16 @@ public async Task UnexpectedCloseTheStatusShouldBeCorrectAndErrorNotNull()
175
177
[ Fact ]
176
178
public async Task OverrideTheBackOffWithBackOffDisabled ( )
177
179
{
178
- string containerId = Guid . NewGuid ( ) . ToString ( ) ;
180
+
181
+ string localContainerId = $ "{ _containerId } _override-backoff-disabled-connection-name";
179
182
IConnection connection = await AmqpConnection . CreateAsync (
180
- ConnectionSettingBuilder . Create ( ) . ContainerId ( containerId ) . RecoveryConfiguration (
183
+ ConnectionSettingBuilder . Create ( ) . ContainerId ( localContainerId ) . RecoveryConfiguration (
181
184
RecoveryConfiguration . Create ( ) . Activated ( true ) . Topology ( false ) . BackOffDelayPolicy (
182
185
new FakeBackOffDelayPolicyDisabled ( ) ) ) . Build ( ) ) ;
183
186
184
187
var listFromStatus = new List < State > ( ) ;
185
- TaskCompletionSource < bool > listFromStatusCountGreaterOrEqualToTwo = CreateTaskCompletionSource ( ) ;
186
- TaskCompletionSource < bool > listErrorCountGreaterOrEqualToTwo = CreateTaskCompletionSource ( ) ;
188
+ TaskCompletionSource < bool > listFromStatusCountGreaterOrEqualToTwo = CreateTaskCompletionSource < bool > ( ) ;
189
+ TaskCompletionSource < bool > listErrorCountGreaterOrEqualToTwo = CreateTaskCompletionSource < bool > ( ) ;
187
190
188
191
var listToStatus = new List < State > ( ) ;
189
192
var listError = new List < Error > ( ) ;
@@ -195,18 +198,20 @@ public async Task OverrideTheBackOffWithBackOffDisabled()
195
198
{
196
199
listError . Add ( error ) ;
197
200
}
201
+
198
202
if ( listFromStatus . Count >= 2 )
199
203
{
200
204
listFromStatusCountGreaterOrEqualToTwo . TrySetResult ( true ) ;
201
205
}
206
+
202
207
if ( listError . Count >= 2 )
203
208
{
204
209
listErrorCountGreaterOrEqualToTwo . SetResult ( true ) ;
205
210
}
206
211
} ;
207
212
208
213
Assert . Equal ( State . Open , connection . State ) ;
209
- await SystemUtils . WaitUntilConnectionIsKilled ( containerId ) ;
214
+ await SystemUtils . WaitUntilConnectionIsKilled ( localContainerId ) ;
210
215
211
216
await listFromStatusCountGreaterOrEqualToTwo . Task . WaitAsync ( TimeSpan . FromSeconds ( 5 ) ) ;
212
217
@@ -234,16 +239,16 @@ public async Task OverrideTheBackOffWithBackOffDisabled()
234
239
[ Fact ]
235
240
public async Task RecoveryTopologyShouldRecoverTheTempQueues ( )
236
241
{
242
+ string localContainerId = $ "{ _containerId } _temp-queue-should-recover-connection-name";
237
243
string queueName = $ "temp-queue-should-recover-{ true } ";
238
- const string containerId = "temp-queue-should-recover-connection-name" ;
239
244
var connection = await AmqpConnection . CreateAsync (
240
245
ConnectionSettingBuilder . Create ( )
241
246
. RecoveryConfiguration ( RecoveryConfiguration . Create ( )
242
247
. BackOffDelayPolicy ( new FakeFastBackOffDelay ( ) )
243
248
. Topology ( true ) )
244
- . ContainerId ( containerId )
249
+ . ContainerId ( localContainerId )
245
250
. Build ( ) ) ;
246
- TaskCompletionSource < bool > twoRecoveryEventsSeenTcs = CreateTaskCompletionSource ( ) ;
251
+ TaskCompletionSource < bool > twoRecoveryEventsSeenTcs = CreateTaskCompletionSource < bool > ( ) ;
247
252
int recoveryEvents = 0 ;
248
253
connection . ChangeState += ( sender , from , to , error ) =>
249
254
{
@@ -257,7 +262,7 @@ public async Task RecoveryTopologyShouldRecoverTheTempQueues()
257
262
await management . Queue ( ) . Name ( queueName ) . AutoDelete ( true ) . Exclusive ( true ) . DeclareAsync ( ) ;
258
263
Assert . Equal ( 1 , topologyListener . QueueCount ( ) ) ;
259
264
260
- await SystemUtils . WaitUntilConnectionIsKilled ( containerId ) ;
265
+ await SystemUtils . WaitUntilConnectionIsKilled ( localContainerId ) ;
261
266
await twoRecoveryEventsSeenTcs . Task . WaitAsync ( TimeSpan . FromSeconds ( 10 ) ) ;
262
267
await SystemUtils . WaitUntilFuncAsync ( ( ) => recoveryEvents == 2 ) ;
263
268
@@ -281,15 +286,15 @@ public async Task RecoveryTopologyShouldRecoverTheTempQueues()
281
286
public async Task RecoveryTopologyShouldNotRecoverTheTempQueues ( )
282
287
{
283
288
string queueName = $ "temp-queue-should-recover-{ false } ";
284
- const string containerId = "temp -queue-should-not-recover-connection-name";
289
+ string localContainerId = $ " { _containerId } _temp -queue-should-not-recover-connection-name";
285
290
var connection = await AmqpConnection . CreateAsync (
286
291
ConnectionSettingBuilder . Create ( )
287
292
. RecoveryConfiguration ( RecoveryConfiguration . Create ( )
288
293
. BackOffDelayPolicy ( new FakeFastBackOffDelay ( ) )
289
294
. Topology ( false ) )
290
- . ContainerId ( containerId )
295
+ . ContainerId ( localContainerId )
291
296
. Build ( ) ) ;
292
- TaskCompletionSource < bool > oneRecoveryEventSeenTcs = CreateTaskCompletionSource ( ) ;
297
+ TaskCompletionSource < bool > oneRecoveryEventSeenTcs = CreateTaskCompletionSource < bool > ( ) ;
293
298
int recoveryEvents = 0 ;
294
299
connection . ChangeState += ( sender , from , to , error ) =>
295
300
{
@@ -303,7 +308,7 @@ public async Task RecoveryTopologyShouldNotRecoverTheTempQueues()
303
308
await management . Queue ( ) . Name ( queueName ) . AutoDelete ( true ) . Exclusive ( true ) . DeclareAsync ( ) ;
304
309
Assert . Equal ( 1 , topologyListener . QueueCount ( ) ) ;
305
310
306
- await SystemUtils . WaitUntilConnectionIsKilled ( containerId ) ;
311
+ await SystemUtils . WaitUntilConnectionIsKilled ( localContainerId ) ;
307
312
await oneRecoveryEventSeenTcs . Task . WaitAsync ( TimeSpan . FromSeconds ( 10 ) ) ;
308
313
309
314
await SystemUtils . WaitUntilQueueDeletedAsync ( queueName ) ;
@@ -318,15 +323,15 @@ public async Task RecoveryTopologyShouldNotRecoverTheTempQueues()
318
323
public async Task RecoveryTopologyShouldRecoverExchanges ( bool topologyEnabled )
319
324
{
320
325
const string exchangeName = "exchange-should-recover" ;
321
- const string containerId = nameof ( RecoveryTopologyShouldRecoverExchanges ) ;
326
+ string localContainerId = $ " { _containerId } _exchange-should-recover-connection-name" ;
322
327
IConnection connection = await AmqpConnection . CreateAsync (
323
328
ConnectionSettingBuilder . Create ( )
324
329
. RecoveryConfiguration ( RecoveryConfiguration . Create ( )
325
330
. BackOffDelayPolicy ( new FakeFastBackOffDelay ( ) )
326
331
. Topology ( topologyEnabled ) )
327
- . ContainerId ( containerId )
332
+ . ContainerId ( localContainerId )
328
333
. Build ( ) ) ;
329
- TaskCompletionSource < bool > twoRecoveryEventsSeenTcs = CreateTaskCompletionSource ( ) ;
334
+ TaskCompletionSource < bool > twoRecoveryEventsSeenTcs = CreateTaskCompletionSource < bool > ( ) ;
330
335
int recoveryEvents = 0 ;
331
336
connection . ChangeState += ( sender , from , to , error ) =>
332
337
{
@@ -346,7 +351,7 @@ public async Task RecoveryTopologyShouldRecoverExchanges(bool topologyEnabled)
346
351
// the exchange is recovered.
347
352
await SystemUtils . DeleteExchangeAsync ( "exchange-should-recover" ) ;
348
353
349
- await SystemUtils . WaitUntilConnectionIsKilled ( containerId ) ;
354
+ await SystemUtils . WaitUntilConnectionIsKilled ( localContainerId ) ;
350
355
351
356
await twoRecoveryEventsSeenTcs . Task . WaitAsync ( TimeSpan . FromSeconds ( 10 ) ) ;
352
357
@@ -374,15 +379,15 @@ public async Task RecoveryTopologyShouldRecoverExchanges(bool topologyEnabled)
374
379
[ InlineData ( false ) ]
375
380
public async Task RecoveryTopologyShouldRecoverBindings ( bool topologyEnabled )
376
381
{
377
- const string containerId = "binding -should-recover-connection-name";
382
+ string localContainerId = $ " { _containerId } _binding -should-recover-connection-name";
378
383
var connection = await AmqpConnection . CreateAsync (
379
384
ConnectionSettingBuilder . Create ( )
380
385
. RecoveryConfiguration ( RecoveryConfiguration . Create ( )
381
386
. BackOffDelayPolicy ( new FakeFastBackOffDelay ( ) )
382
387
. Topology ( topologyEnabled ) )
383
- . ContainerId ( containerId )
388
+ . ContainerId ( localContainerId )
384
389
. Build ( ) ) ;
385
- TaskCompletionSource < bool > twoRecoveryEventsSeenTcs = CreateTaskCompletionSource ( ) ;
390
+ TaskCompletionSource < bool > twoRecoveryEventsSeenTcs = CreateTaskCompletionSource < bool > ( ) ;
386
391
int recoveryEvents = 0 ;
387
392
connection . ChangeState += ( sender , from , to , error ) =>
388
393
{
@@ -410,7 +415,7 @@ public async Task RecoveryTopologyShouldRecoverBindings(bool topologyEnabled)
410
415
await SystemUtils . DeleteExchangeAsync ( "exchange-should-recover-binding" ) ;
411
416
412
417
// The queue will be deleted due of the auto-delete flag
413
- await SystemUtils . WaitUntilConnectionIsKilled ( containerId ) ;
418
+ await SystemUtils . WaitUntilConnectionIsKilled ( localContainerId ) ;
414
419
await twoRecoveryEventsSeenTcs . Task . WaitAsync ( TimeSpan . FromSeconds ( 10 ) ) ;
415
420
416
421
if ( topologyEnabled )
@@ -453,13 +458,14 @@ await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueDontExistAsync("exchan
453
458
[ Fact ]
454
459
public async Task RemoveAQueueShouldRemoveTheBindings ( )
455
460
{
456
- const string containerId = nameof ( RemoveAQueueShouldRemoveTheBindings ) ;
461
+ string localContainerId = $ "{ _containerId } _remove-queue-should-remove-binding-connection-name";
462
+
457
463
IConnection connection = await AmqpConnection . CreateAsync (
458
464
ConnectionSettingBuilder . Create ( )
459
465
. RecoveryConfiguration ( RecoveryConfiguration . Create ( )
460
466
. BackOffDelayPolicy ( new FakeFastBackOffDelay ( ) )
461
467
. Topology ( true ) )
462
- . ContainerId ( containerId )
468
+ . ContainerId ( localContainerId )
463
469
. Build ( ) ) ;
464
470
465
471
IManagement management = connection . Management ( ) ;
@@ -513,13 +519,13 @@ await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueDontExistAsync("e-remo
513
519
[ Fact ]
514
520
public async Task RemoveAnExchangeShouldRemoveTheBindings ( )
515
521
{
516
- const string containerId = "remove -exchange-should-remove-binding-connection-name";
522
+ string localContainerId = $ " { _containerId } _remove -exchange-should-remove-binding-connection-name";
517
523
var connection = await AmqpConnection . CreateAsync (
518
524
ConnectionSettingBuilder . Create ( )
519
525
. RecoveryConfiguration ( RecoveryConfiguration . Create ( )
520
526
. BackOffDelayPolicy ( new FakeFastBackOffDelay ( ) )
521
527
. Topology ( true ) )
522
- . ContainerId ( containerId )
528
+ . ContainerId ( localContainerId )
523
529
. Build ( ) ) ;
524
530
525
531
IManagement management = connection . Management ( ) ;
@@ -578,13 +584,13 @@ await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueDontExistAsync(
578
584
[ Fact ]
579
585
public async Task RemoveAnExchangeBoundToAnotherExchangeShouldRemoveTheBindings ( )
580
586
{
581
- const string containerId = nameof ( RemoveAnExchangeBoundToAnotherExchangeShouldRemoveTheBindings ) ;
587
+ string localContainerId = $ " { _containerId } _remove-exchange-bound-to-another-exchange-should-remove-binding-connection-name" ;
582
588
var connection = await AmqpConnection . CreateAsync (
583
589
ConnectionSettingBuilder . Create ( )
584
590
. RecoveryConfiguration ( RecoveryConfiguration . Create ( )
585
591
. BackOffDelayPolicy ( new FakeFastBackOffDelay ( ) )
586
592
. Topology ( true ) )
587
- . ContainerId ( containerId )
593
+ . ContainerId ( localContainerId )
588
594
. Build ( ) ) ;
589
595
590
596
IManagement management = connection . Management ( ) ;
@@ -595,7 +601,8 @@ public async Task RemoveAnExchangeBoundToAnotherExchangeShouldRemoveTheBindings(
595
601
596
602
await exSpec . DeclareAsync ( ) ;
597
603
598
- var exSpecDestination = management . Exchange ( ) . Name ( "e-remove-exchange-bound-to-another-exchange-should-remove-binding-destination" )
604
+ var exSpecDestination = management . Exchange ( )
605
+ . Name ( "e-remove-exchange-bound-to-another-exchange-should-remove-binding-destination" )
599
606
. Type ( ExchangeType . DIRECT ) ;
600
607
601
608
await exSpecDestination . DeclareAsync ( ) ;
@@ -606,7 +613,8 @@ await management.Binding().SourceExchange(exSpec)
606
613
. DestinationExchange ( exSpecDestination ) . Key ( $ "key_{ i } ") . BindAsync ( ) ;
607
614
}
608
615
609
- await SystemUtils . WaitUntilBindingsBetweenExchangeAndExchangeExistAsync ( "e-remove-exchange-bound-to-another-exchange-should-remove-binding" ,
616
+ await SystemUtils . WaitUntilBindingsBetweenExchangeAndExchangeExistAsync (
617
+ "e-remove-exchange-bound-to-another-exchange-should-remove-binding" ,
610
618
"e-remove-exchange-bound-to-another-exchange-should-remove-binding-destination" ) ;
611
619
612
620
Assert . Equal ( 10 , topologyListener . BindingCount ( ) ) ;
@@ -616,16 +624,12 @@ await SystemUtils.WaitUntilBindingsBetweenExchangeAndExchangeExistAsync("e-remov
616
624
617
625
await exSpec . DeleteAsync ( ) ;
618
626
619
- await SystemUtils . WaitUntilBindingsBetweenExchangeAndExchangeDontExistAsync ( "e-remove-exchange-bound-to-another-exchange-should-remove-binding" ,
627
+ await SystemUtils . WaitUntilBindingsBetweenExchangeAndExchangeDontExistAsync (
628
+ "e-remove-exchange-bound-to-another-exchange-should-remove-binding" ,
620
629
"e-remove-exchange-bound-to-another-exchange-should-remove-binding-destination" ) ;
621
630
622
631
Assert . Equal ( 0 , topologyListener . ExchangeCount ( ) ) ;
623
632
624
633
await connection . CloseAsync ( ) ;
625
634
}
626
-
627
- private static TaskCompletionSource < bool > CreateTaskCompletionSource ( )
628
- {
629
- return new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
630
- }
631
635
}
0 commit comments