Skip to content

Commit

Permalink
Increase delay between listing connections via HTTP API, to a maximum…
Browse files Browse the repository at this point in the history
… interval of 10 seconds
  • Loading branch information
lukebakken committed Apr 22, 2024
1 parent 5c9caed commit bf86447
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions projects/Test/Common/Util.cs
Expand Up @@ -10,7 +10,6 @@ namespace Test
{
public static class Util
{
private static readonly TimeSpan s_closeConnectionDelay = TimeSpan.FromSeconds(2);
private static readonly ManagementClient s_managementClient;
private static readonly bool s_isWindows = false;

Expand Down Expand Up @@ -45,7 +44,7 @@ private static bool InitIsWindows()

public static async Task CloseConnectionAsync(IConnection conn)
{
ushort tries = 30; // 60 seconds
ushort tries = 1;
EasyNetQ.Management.Client.Model.Connection connectionToClose = null;
do
{
Expand All @@ -54,7 +53,14 @@ public static async Task CloseConnectionAsync(IConnection conn)
{
do
{
await Task.Delay(s_closeConnectionDelay);
ushort delaySeconds = (ushort)(tries * 2);
if (delaySeconds > 10)
{
delaySeconds = 10;
}

await Task.Delay(TimeSpan.FromSeconds(delaySeconds));

connections = await s_managementClient.GetConnectionsAsync();
} while (connections.Count == 0);

Expand All @@ -64,7 +70,7 @@ public static async Task CloseConnectionAsync(IConnection conn)

if (connectionToClose == null)
{
tries--;
tries++;
}
else
{
Expand All @@ -74,18 +80,13 @@ public static async Task CloseConnectionAsync(IConnection conn)
catch (ArgumentNullException)
{
// Sometimes we see this in GitHub CI
tries--;
tries++;
}
} while (tries > 0);

if (tries == 0)
{
throw new InvalidOperationException($"Could not delete connection: '{conn.ClientProvidedName}'");
}
} while (tries <= 30);

if (connectionToClose == null)
{
throw new InvalidOperationException($"connectionToClose should not be null here");
throw new InvalidOperationException($"Could not delete connection: '{conn.ClientProvidedName}'");
}

await s_managementClient.CloseConnectionAsync(connectionToClose);
Expand Down

0 comments on commit bf86447

Please sign in to comment.