@@ -10,7 +10,6 @@ namespace Test
10
10
{
11
11
public static class Util
12
12
{
13
- private static readonly TimeSpan s_closeConnectionDelay = TimeSpan . FromSeconds ( 2 ) ;
14
13
private static readonly ManagementClient s_managementClient ;
15
14
private static readonly bool s_isWindows = false ;
16
15
@@ -45,7 +44,7 @@ private static bool InitIsWindows()
45
44
46
45
public static async Task CloseConnectionAsync ( IConnection conn )
47
46
{
48
- ushort tries = 30 ; // 60 seconds
47
+ ushort tries = 1 ;
49
48
EasyNetQ . Management . Client . Model . Connection connectionToClose = null ;
50
49
do
51
50
{
@@ -54,7 +53,14 @@ public static async Task CloseConnectionAsync(IConnection conn)
54
53
{
55
54
do
56
55
{
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
+
58
64
connections = await s_managementClient . GetConnectionsAsync ( ) ;
59
65
} while ( connections . Count == 0 ) ;
60
66
@@ -64,7 +70,7 @@ public static async Task CloseConnectionAsync(IConnection conn)
64
70
65
71
if ( connectionToClose == null )
66
72
{
67
- tries -- ;
73
+ tries ++ ;
68
74
}
69
75
else
70
76
{
@@ -74,18 +80,13 @@ public static async Task CloseConnectionAsync(IConnection conn)
74
80
catch ( ArgumentNullException )
75
81
{
76
82
// Sometimes we see this in GitHub CI
77
- tries -- ;
83
+ tries ++ ;
78
84
}
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 ) ;
85
86
86
87
if ( connectionToClose == null )
87
88
{
88
- throw new InvalidOperationException ( $ "connectionToClose should not be null here ") ;
89
+ throw new InvalidOperationException ( $ "Could not delete connection: ' { conn . ClientProvidedName } ' ") ;
89
90
}
90
91
91
92
await s_managementClient . CloseConnectionAsync ( connectionToClose ) ;
0 commit comments