Skip to content

Commit 220b4cf

Browse files
committed
Add debugging statements
Fix flaky test by executing action and setting latch sooner. Prior to this change the connection could be closed before enough messages are published to have the latch set in HandleBasicDeliver
1 parent 053afec commit 220b4cf

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

projects/Unit/Fixtures.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,17 +528,24 @@ internal Process ExecCommand(string ctl, string args, string changeDirTo)
528528
}
529529

530530
try {
531+
System.Console.WriteLine("@@@@@@@@ ExecCommand FileName: {0}", cmd);
531532
proc.StartInfo.FileName = cmd;
533+
534+
System.Console.WriteLine("@@@@@@@@ ExecCommand Arguments: {0}", args);
532535
proc.StartInfo.Arguments = args;
536+
533537
proc.StartInfo.RedirectStandardError = true;
534538
proc.StartInfo.RedirectStandardOutput = true;
535539

540+
System.Console.WriteLine("@@@@@@@@ ExecCommand Start()");
536541
proc.Start();
537-
string stderr = proc.StandardError.ReadToEnd();
542+
System.Console.WriteLine("@@@@@@@@ ExecCommand WaitForExit()");
538543
proc.WaitForExit();
544+
string stderr = proc.StandardError.ReadToEnd();
545+
System.Console.WriteLine("@@@@@@@@ ExecCommand WaitForExit() DONE ExitCode: {0} stderr: {1}", proc.ExitCode, stderr);
539546
if (stderr.Length > 0 || proc.ExitCode > 0)
540547
{
541-
string stdout = proc.StandardOutput.ReadToEnd();
548+
string stdout = proc.StandardOutput.ReadToEnd();
542549
ReportExecFailure(cmd, args, $"{stderr}\n{stdout}");
543550
}
544551

@@ -649,21 +656,21 @@ internal List<ConnectionInfo> ListConnections()
649656
internal void CloseConnection(IConnection conn)
650657
{
651658
ConnectionInfo ci = ListConnections().First(x => conn.ClientProvidedName == x.Name);
652-
CloseConnection(ci.Pid);
659+
CloseConnection(conn.ClientProvidedName, ci.Pid);
653660
}
654661

655662
internal void CloseAllConnections()
656663
{
657664
List<ConnectionInfo> cs = ListConnections();
658665
foreach(ConnectionInfo c in cs)
659666
{
660-
CloseConnection(c.Pid);
667+
CloseConnection(c.Name, c.Pid);
661668
}
662669
}
663670

664-
internal void CloseConnection(string pid)
671+
internal void CloseConnection(string name, string pid)
665672
{
666-
ExecRabbitMQCtl($"close_connection \"{pid}\" \"Closed via rabbitmqctl\"");
673+
ExecRabbitMQCtl($"close_connection \"{pid}\" \"{name} {pid} closed via rabbitmqctl\"");
667674
}
668675

669676
internal void RestartRabbitMQ()

projects/Unit/TestConnectionRecovery.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public void TestBasicAckEventHandlerRecovery()
114114
CloseAndWaitForRecovery();
115115
Assert.IsTrue(Model.IsOpen);
116116

117-
WithTemporaryNonExclusiveQueue(Model, (m, q) => m.BasicPublish("", q, null, encoding.GetBytes("")));
117+
byte[] mb = RandomMessageBody();
118+
WithTemporaryNonExclusiveQueue(Model, (m, q) => m.BasicPublish("", q, null, mb));
118119
Wait(latch);
119120
}
120121

@@ -989,7 +990,8 @@ internal void AssertQueueRecovery(IModel m, string q, bool exclusive)
989990
m.QueueDeclarePassive(q);
990991
QueueDeclareOk ok1 = m.QueueDeclare(q, false, exclusive, false, null);
991992
Assert.AreEqual(ok1.MessageCount, 0);
992-
m.BasicPublish("", q, null, encoding.GetBytes(""));
993+
byte[] mb = RandomMessageBody();
994+
m.BasicPublish("", q, null, mb);
993995
Assert.IsTrue(WaitForConfirms(m));
994996
QueueDeclareOk ok2 = m.QueueDeclare(q, false, exclusive, false, null);
995997
Assert.AreEqual(ok2.MessageCount, 1);
@@ -1024,11 +1026,20 @@ internal void CloseAndWaitForRecovery()
10241026

10251027
internal void CloseAndWaitForRecovery(AutorecoveringConnection conn)
10261028
{
1029+
System.Console.WriteLine("@@@@@@@@ CloseAndWaitForRecovery START");
10271030
ManualResetEventSlim sl = PrepareForShutdown(conn);
10281031
ManualResetEventSlim rl = PrepareForRecovery(conn);
1032+
System.Console.WriteLine("@@@@@@@@ CloseAndWaitForRecovery Closing Connection START");
10291033
CloseConnection(conn);
1034+
System.Console.WriteLine("@@@@@@@@ CloseAndWaitForRecovery Closing Connection DONE");
1035+
1036+
System.Console.WriteLine("@@@@@@@@ CloseAndWaitForRecovery Shutdown Wait START");
10301037
Wait(sl);
1038+
System.Console.WriteLine("@@@@@@@@ CloseAndWaitForRecovery Shutdown Wait DONE");
1039+
1040+
System.Console.WriteLine("@@@@@@@@ CloseAndWaitForRecovery Recovery Wait START");
10311041
Wait(rl);
1042+
System.Console.WriteLine("@@@@@@@@ CloseAndWaitForRecovery Recovery Wait DONE");
10321043
}
10331044

10341045
internal void CloseAndWaitForShutdown(AutorecoveringConnection conn)
@@ -1083,9 +1094,10 @@ internal void TestDelayedBasicAckNackAfterChannelRecovery(TestBasicConsumer1 con
10831094
AutorecoveringConnection publishingConn = CreateAutorecoveringConnection();
10841095
IModel publishingModel = publishingConn.CreateModel();
10851096

1097+
byte[] mb = RandomMessageBody();
10861098
for (int i = 0; i < n; i++)
10871099
{
1088-
publishingModel.BasicPublish("", q, null, encoding.GetBytes(""));
1100+
publishingModel.BasicPublish("", q, null, mb);
10891101
}
10901102

10911103
Wait(latch, TimeSpan.FromSeconds(20));
@@ -1157,7 +1169,6 @@ public class TestBasicConsumer1 : DefaultBasicConsumer
11571169
{
11581170
private readonly Action _action;
11591171
private readonly ManualResetEventSlim _latch;
1160-
private ushort _counter = 0;
11611172

11621173
public TestBasicConsumer1(IModel model, ManualResetEventSlim latch, Action fn)
11631174
: base(model)
@@ -1176,19 +1187,21 @@ public override void HandleBasicDeliver(string consumerTag,
11761187
{
11771188
try
11781189
{
1179-
if (deliveryTag == 7 && _counter < 10)
1190+
System.Console.WriteLine("@@@@@@@@ HandleBasicDeliver deliveryTag: {0}", deliveryTag);
1191+
1192+
if (deliveryTag == 5)
11801193
{
11811194
_action();
11821195
}
1183-
if (_counter == 9)
1196+
1197+
if (deliveryTag == 6)
11841198
{
11851199
_latch.Set();
11861200
}
1187-
PostHandleDelivery(deliveryTag);
11881201
}
11891202
finally
11901203
{
1191-
_counter += 1;
1204+
PostHandleDelivery(deliveryTag);
11921205
}
11931206
}
11941207

0 commit comments

Comments
 (0)