Skip to content

Commit

Permalink
Merge pull request #1148 from rabbitmq/rabbitmq-dotnet-client-1140
Browse files Browse the repository at this point in the history
Fix flaky connection recovery tests.

(cherry picked from commit 2d04378)
  • Loading branch information
michaelklishin authored and lukebakken committed Feb 23, 2022
1 parent bcf4e59 commit 6152045
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
9 changes: 8 additions & 1 deletion projects/RabbitMQ.Client/client/impl/AutorecoveringModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,19 @@ public void AutomaticallyRecover(AutorecoveringConnection conn, bool recoverCons
newModel.TxSelect();
}

/*
* https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/1140
* If this assignment is not done before recovering consumers, there is a good
* chance that an invalid Model will be used to handle a basic.deliver frame,
* with the resulting basic.ack never getting sent out.
*/
_delegate = newModel;

if (recoverConsumers)
{
_connection.RecoverConsumers(this, newModel);
}

_delegate = newModel;
RunRecoveryEventHandlers();
}

Expand Down
1 change: 1 addition & 0 deletions projects/Unit/Fixtures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ internal void StopRabbitMQ()
internal void StartRabbitMQ()
{
ExecRabbitMQCtl("start_app");
ExecRabbitMQCtl("await_startup");
}

//
Expand Down
14 changes: 5 additions & 9 deletions projects/Unit/TestConnectionRecovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public void CleanUp()
}

[Test]
[Ignore("TODO flaky")]
public void TestBasicAckAfterChannelRecovery()
{
var allMessagesSeenLatch = new ManualResetEventSlim(false);
Expand All @@ -98,7 +97,6 @@ public void TestBasicAckAfterChannelRecovery()
}

[Test]
[Ignore("TODO flaky")]
public void TestBasicNackAfterChannelRecovery()
{
var allMessagesSeenLatch = new ManualResetEventSlim(false);
Expand All @@ -121,7 +119,6 @@ public void TestBasicNackAfterChannelRecovery()
}

[Test]
[Ignore("TODO flaky")]
public void TestBasicRejectAfterChannelRecovery()
{
var allMessagesSeenLatch = new ManualResetEventSlim(false);
Expand Down Expand Up @@ -839,23 +836,23 @@ public void TestPublishRpcRightAfterReconnect()
var properties = Model.CreateBasicProperties();
properties.ReplyTo = "amq.rabbitmq.reply-to";

bool done = false;
TimeSpan doneSpan = TimeSpan.FromMilliseconds(100);
var done = new ManualResetEventSlim(false);
var t = new Thread(() =>
{
try
{
CloseAndWaitForRecovery();
Thread.Sleep(100);
}
finally
{
done = true;
done.Set();
}
});
t.Start();

while (!done)
while (!done.IsSet)
{
try
{
Expand All @@ -869,9 +866,8 @@ public void TestPublishRpcRightAfterReconnect()
Assert.AreNotEqual(406, a.ShutdownReason.ReplyCode);
}
}
Thread.Sleep(1);
done.Wait(doneSpan);
}

t.Join();
}

Expand Down

0 comments on commit 6152045

Please sign in to comment.