From bf86447ade9d7c934c5d7623f120fb975c7b18a5 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Mon, 22 Apr 2024 15:12:35 -0700 Subject: [PATCH] Increase delay between listing connections via HTTP API, to a maximum interval of 10 seconds --- projects/Test/Common/Util.cs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/projects/Test/Common/Util.cs b/projects/Test/Common/Util.cs index 9282281f96..a206744ca9 100644 --- a/projects/Test/Common/Util.cs +++ b/projects/Test/Common/Util.cs @@ -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; @@ -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 { @@ -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); @@ -64,7 +70,7 @@ public static async Task CloseConnectionAsync(IConnection conn) if (connectionToClose == null) { - tries--; + tries++; } else { @@ -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);