Skip to content

Commit

Permalink
Try to fix flaky `TestConsumerRecoveryOnClientNamedQueueWithOneRecove…
Browse files Browse the repository at this point in the history
…ry` test
  • Loading branch information
lukebakken committed Apr 20, 2024
1 parent 8cb3f39 commit 44f84b6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 27 deletions.
8 changes: 8 additions & 0 deletions projects/Test/Common/RabbitMQCtl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,15 @@ private static ProcessStartInfo GetRabbitMqCtlStartInfo(string args)

private async Task<string> GetConnectionPidAsync(string connectionName)
{
if (Util.Verbose)
{
Util.Output.WriteLine($"GetConnectionPidAsync connectionName: {connectionName}");
}
string stdout = await ExecRabbitMQCtlAsync("list_connections --silent pid client_properties");
if (Util.Verbose)
{
Util.Output.WriteLine($"GetConnectionPidAsync stdout: {stdout}");
}
Match match = s_getConnectionProperties.Match(stdout);
while (match.Success)
{
Expand Down
5 changes: 5 additions & 0 deletions projects/Test/Common/Util.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Globalization;
using Xunit.Abstractions;

namespace Test
{
Expand All @@ -16,6 +17,10 @@ static Util()

public static bool IsWindows => s_isWindows;

public static bool Verbose;

public static ITestOutputHelper Output;

private static bool InitIsWindows()
{
PlatformID platform = Environment.OSVersion.Platform;
Expand Down
68 changes: 41 additions & 27 deletions projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,45 +149,59 @@ public async Task TestConsumerWorkServiceRecovery()
[Fact]
public async Task TestConsumerRecoveryOnClientNamedQueueWithOneRecovery()
{
const string q0 = "dotnet-client.recovery.queue1";
using (AutorecoveringConnection c = await CreateAutorecoveringConnectionAsync())
try
{
using (IChannel ch = await c.CreateChannelAsync())
// NOTE: for debugging CI issue with this test
Util.Verbose = true;
Util.Output = _output;

const string q0 = "dotnet-client.recovery.queue1";
// connection #1
using (AutorecoveringConnection c = await CreateAutorecoveringConnectionAsync())
{
string q1 = (await ch.QueueDeclareAsync(q0, false, false, false)).QueueName;
Assert.Equal(q0, q1);
using (IChannel ch = await c.CreateChannelAsync())
{
string q1 = (await ch.QueueDeclareAsync(q0, false, false, false)).QueueName;
Assert.Equal(q0, q1);

var cons = new EventingBasicConsumer(ch);
await ch.BasicConsumeAsync(q1, true, cons);
await AssertConsumerCountAsync(ch, q1, 1);
var cons = new EventingBasicConsumer(ch);
await ch.BasicConsumeAsync(q1, true, cons);
await AssertConsumerCountAsync(ch, q1, 1);

bool queueNameChangeAfterRecoveryCalled = false;
bool queueNameChangeAfterRecoveryCalled = false;
c.QueueNameChangedAfterRecovery += (source, ea) => { queueNameChangeAfterRecoveryCalled = true; };

c.QueueNameChangedAfterRecovery += (source, ea) => { queueNameChangeAfterRecoveryCalled = true; };
// connection #2
await CloseAndWaitForRecoveryAsync(c);
await AssertConsumerCountAsync(ch, q1, 1);
Assert.False(queueNameChangeAfterRecoveryCalled);

await CloseAndWaitForRecoveryAsync(c);
await AssertConsumerCountAsync(ch, q1, 1);
Assert.False(queueNameChangeAfterRecoveryCalled);
// connection #3
await CloseAndWaitForRecoveryAsync(c);
await AssertConsumerCountAsync(ch, q1, 1);
Assert.False(queueNameChangeAfterRecoveryCalled);

await CloseAndWaitForRecoveryAsync(c);
await AssertConsumerCountAsync(ch, q1, 1);
Assert.False(queueNameChangeAfterRecoveryCalled);
// connection #4
await CloseAndWaitForRecoveryAsync(c);
await AssertConsumerCountAsync(ch, q1, 1);
Assert.False(queueNameChangeAfterRecoveryCalled);

await CloseAndWaitForRecoveryAsync(c);
await AssertConsumerCountAsync(ch, q1, 1);
Assert.False(queueNameChangeAfterRecoveryCalled);
var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
cons.Received += (s, args) => tcs.SetResult(true);

var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
cons.Received += (s, args) => tcs.SetResult(true);
await ch.BasicPublishAsync("", q1, _encoding.GetBytes("msg"));
await WaitAsync(tcs, "received event");

await ch.BasicPublishAsync("", q1, _encoding.GetBytes("msg"));
await WaitAsync(tcs, "received event");
await ch.QueueDeleteAsync(q1);
await ch.CloseAsync();
}

await ch.QueueDeleteAsync(q1);
await ch.CloseAsync();
await c.CloseAsync();
}

await c.CloseAsync();
}
finally
{
Util.Verbose = false;
}
}

Expand Down

0 comments on commit 44f84b6

Please sign in to comment.