@@ -73,6 +73,35 @@ public void TestBasicConnectionRecovery()
73
73
Assert . IsTrue ( Conn . IsOpen ) ;
74
74
}
75
75
76
+ [ Test ]
77
+ public void TestBasicConnectionRecoveryOnBrokerRestart ( )
78
+ {
79
+ Assert . IsTrue ( Conn . IsOpen ) ;
80
+ RestartServerAndWaitForRecovery ( ) ;
81
+ Assert . IsTrue ( Conn . IsOpen ) ;
82
+ }
83
+
84
+ [ Test ]
85
+ public void TestShutdownEventHandlersRecoveryOnConnectionAfterDelayedServerRestart ( )
86
+ {
87
+ Int32 counter = 0 ;
88
+ Conn . ConnectionShutdown += ( c , args ) =>
89
+ {
90
+ Interlocked . Increment ( ref counter ) ;
91
+ } ;
92
+
93
+ Assert . IsTrue ( Conn . IsOpen ) ;
94
+ StopRabbitMQ ( ) ;
95
+ Console . WriteLine ( "About to sleep for 9 seconds..." ) ;
96
+ Thread . Sleep ( 9000 ) ;
97
+ StartRabbitMQ ( ) ;
98
+ WaitForShutdown ( ) ;
99
+ WaitForRecovery ( ) ;
100
+ Assert . IsTrue ( Conn . IsOpen ) ;
101
+
102
+ Assert . IsTrue ( counter >= 1 ) ;
103
+ }
104
+
76
105
[ Test ]
77
106
public void TestShutdownEventHandlersRecoveryOnConnection ( )
78
107
{
@@ -151,6 +180,14 @@ public void TestBasicModelRecovery()
151
180
Assert . IsTrue ( Model . IsOpen ) ;
152
181
}
153
182
183
+ [ Test ]
184
+ public void TestBasicModelRecoveryOnServerRestart ( )
185
+ {
186
+ Assert . IsTrue ( Model . IsOpen ) ;
187
+ RestartServerAndWaitForRecovery ( ) ;
188
+ Assert . IsTrue ( Model . IsOpen ) ;
189
+ }
190
+
154
191
[ Test ]
155
192
public void TestShutdownEventHandlersRecoveryOnModel ( )
156
193
{
@@ -268,6 +305,17 @@ public void TestClientNamedQueueRecovery()
268
305
} , s ) ;
269
306
}
270
307
308
+ [ Test ]
309
+ public void TestClientNamedQueueRecoveryOnServerRestart ( )
310
+ {
311
+ string s = "dotnet-client.test.recovery.q1" ;
312
+ WithTemporaryNonExclusiveQueue ( Model , ( m , q ) => {
313
+ RestartServerAndWaitForRecovery ( ) ;
314
+ AssertQueueRecovery ( m , q , false ) ;
315
+ Model . QueueDelete ( q ) ;
316
+ } , s ) ;
317
+ }
318
+
271
319
[ Test ]
272
320
public void TestClientNamedQueueRecoveryNoWait ( )
273
321
{
@@ -802,6 +850,35 @@ protected void CloseAndWaitForShutdown(AutorecoveringConnection conn)
802
850
Wait ( sl ) ;
803
851
}
804
852
853
+ protected void RestartServerAndWaitForRecovery ( )
854
+ {
855
+ RestartServerAndWaitForRecovery ( ( AutorecoveringConnection ) this . Conn ) ;
856
+ }
857
+
858
+ protected void RestartServerAndWaitForRecovery ( AutorecoveringConnection conn )
859
+ {
860
+ var sl = PrepareForShutdown ( conn ) ;
861
+ var rl = PrepareForRecovery ( conn ) ;
862
+ RestartRabbitMQ ( ) ;
863
+ Wait ( sl ) ;
864
+ Wait ( rl ) ;
865
+ }
866
+
867
+ protected void WaitForRecovery ( )
868
+ {
869
+ Wait ( PrepareForRecovery ( ( AutorecoveringConnection ) this . Conn ) ) ;
870
+ }
871
+
872
+ protected void WaitForRecovery ( AutorecoveringConnection conn )
873
+ {
874
+ Wait ( PrepareForRecovery ( conn ) ) ;
875
+ }
876
+
877
+ protected void WaitForShutdown ( )
878
+ {
879
+ Wait ( PrepareForShutdown ( this . Conn ) ) ;
880
+ }
881
+
805
882
protected void WaitForShutdown ( IConnection conn )
806
883
{
807
884
Wait ( PrepareForShutdown ( conn ) ) ;
0 commit comments