Skip to content

Commit e4a5061

Browse files
More recovery tests
1 parent 251c40f commit e4a5061

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

projects/client/Unit/src/unit/TestConnectionRecovery.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,35 @@ public void TestBasicConnectionRecovery()
7373
Assert.IsTrue(Conn.IsOpen);
7474
}
7575

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+
76105
[Test]
77106
public void TestShutdownEventHandlersRecoveryOnConnection()
78107
{
@@ -151,6 +180,14 @@ public void TestBasicModelRecovery()
151180
Assert.IsTrue(Model.IsOpen);
152181
}
153182

183+
[Test]
184+
public void TestBasicModelRecoveryOnServerRestart()
185+
{
186+
Assert.IsTrue(Model.IsOpen);
187+
RestartServerAndWaitForRecovery();
188+
Assert.IsTrue(Model.IsOpen);
189+
}
190+
154191
[Test]
155192
public void TestShutdownEventHandlersRecoveryOnModel()
156193
{
@@ -268,6 +305,17 @@ public void TestClientNamedQueueRecovery()
268305
}, s);
269306
}
270307

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+
271319
[Test]
272320
public void TestClientNamedQueueRecoveryNoWait()
273321
{
@@ -802,6 +850,35 @@ protected void CloseAndWaitForShutdown(AutorecoveringConnection conn)
802850
Wait(sl);
803851
}
804852

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+
805882
protected void WaitForShutdown(IConnection conn)
806883
{
807884
Wait(PrepareForShutdown(conn));

0 commit comments

Comments
 (0)