@@ -10,7 +10,6 @@ namespace Test
1010{
1111 public static class Util
1212 {
13- private static readonly TimeSpan s_closeConnectionDelay = TimeSpan . FromSeconds ( 2 ) ;
1413 private static readonly ManagementClient s_managementClient ;
1514 private static readonly bool s_isWindows = false ;
1615
@@ -45,7 +44,7 @@ private static bool InitIsWindows()
4544
4645 public static async Task CloseConnectionAsync ( IConnection conn )
4746 {
48- ushort tries = 30 ; // 60 seconds
47+ ushort tries = 1 ;
4948 EasyNetQ . Management . Client . Model . Connection connectionToClose = null ;
5049 do
5150 {
@@ -54,7 +53,14 @@ public static async Task CloseConnectionAsync(IConnection conn)
5453 {
5554 do
5655 {
57- await Task . Delay ( s_closeConnectionDelay ) ;
56+ ushort delaySeconds = ( ushort ) ( tries * 2 ) ;
57+ if ( delaySeconds > 10 )
58+ {
59+ delaySeconds = 10 ;
60+ }
61+
62+ await Task . Delay ( TimeSpan . FromSeconds ( delaySeconds ) ) ;
63+
5864 connections = await s_managementClient . GetConnectionsAsync ( ) ;
5965 } while ( connections . Count == 0 ) ;
6066
@@ -64,7 +70,7 @@ public static async Task CloseConnectionAsync(IConnection conn)
6470
6571 if ( connectionToClose == null )
6672 {
67- tries -- ;
73+ tries ++ ;
6874 }
6975 else
7076 {
@@ -74,18 +80,13 @@ public static async Task CloseConnectionAsync(IConnection conn)
7480 catch ( ArgumentNullException )
7581 {
7682 // Sometimes we see this in GitHub CI
77- tries -- ;
83+ tries ++ ;
7884 }
79- } while ( tries > 0 ) ;
80-
81- if ( tries == 0 )
82- {
83- throw new InvalidOperationException ( $ "Could not delete connection: '{ conn . ClientProvidedName } '") ;
84- }
85+ } while ( tries <= 30 ) ;
8586
8687 if ( connectionToClose == null )
8788 {
88- throw new InvalidOperationException ( $ "connectionToClose should not be null here ") ;
89+ throw new InvalidOperationException ( $ "Could not delete connection: ' { conn . ClientProvidedName } ' ") ;
8990 }
9091
9192 await s_managementClient . CloseConnectionAsync ( connectionToClose ) ;
0 commit comments