File tree Expand file tree Collapse file tree 12 files changed +117
-24
lines changed
SocketIOClient.Test/SocketIOTests Expand file tree Collapse file tree 12 files changed +117
-24
lines changed Original file line number Diff line number Diff line change 11using SocketIOClient . ConnectInterval ;
22using System ;
3- using System . Collections . Generic ;
4- using System . Text ;
53
64namespace SocketIOClient . Sample
75{
@@ -14,15 +12,15 @@ public MyConnectInterval()
1412
1513 double delay ;
1614
17- public int GetDelay ( )
15+ public double GetDelay ( )
1816 {
1917 Console . WriteLine ( "GetDelay: " + delay ) ;
20- return ( int ) delay ;
18+ return delay ;
2119 }
2220
23- public double NextDealy ( )
21+ public double NextDelay ( )
2422 {
25- Console . WriteLine ( "NextDealy : " + ( delay + 1000 ) ) ;
23+ Console . WriteLine ( "NextDelay : " + ( delay + 1000 ) ) ;
2624 return delay += 1000 ;
2725 }
2826 }
Original file line number Diff line number Diff line change @@ -130,6 +130,36 @@ public virtual async Task ReconnectingTest()
130130 Assert . AreEqual ( 1 , attempt ) ;
131131 }
132132
133+ public virtual async Task ReconnectionAttemptsExceededTest ( )
134+ {
135+ var client = SocketIOCreator . Create ( ) ;
136+ client . ServerUri = new System . Uri ( "http://localhost:11011" ) ;
137+ client . Options . AllowedRetryFirstConnection = true ;
138+ client . Options . ReconnectionAttempts = 5 ;
139+
140+ int reconnectingCount = 0 ;
141+ int attempt = 0 ;
142+ int reconnectionErrorCount = 0 ;
143+
144+ client . OnReconnecting += ( sender , e ) =>
145+ {
146+ reconnectingCount ++ ;
147+ attempt = e ;
148+ } ;
149+
150+ client . OnReconnectFailed += ( sender , e ) =>
151+ {
152+ reconnectionErrorCount ++ ;
153+ } ;
154+
155+ await client . ConnectAsync ( ) ;
156+
157+ Assert . AreEqual ( reconnectingCount , 5 ) ;
158+ Assert . AreEqual ( reconnectionErrorCount , 1 ) ;
159+ Assert . AreEqual ( attempt , 5 ) ;
160+ }
161+
162+
133163 [ Timeout ( 30000 ) ]
134164 public virtual async Task ManuallyReconnectionTest ( )
135165 {
Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ public override async Task ReconnectingTest()
3131 await base . ReconnectingTest ( ) ;
3232 }
3333
34+ [ TestMethod ]
35+ public override async Task ReconnectionAttemptsExceededTest ( )
36+ {
37+ await base . ReconnectionAttemptsExceededTest ( ) ;
38+ }
39+
3440 [ TestMethod ]
3541 public override async Task ManuallyReconnectionTest ( )
3642 {
Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ public override async Task ReconnectingTest()
3131 await base . ReconnectingTest ( ) ;
3232 }
3333
34+ [ TestMethod ]
35+ public override async Task ReconnectionAttemptsExceededTest ( )
36+ {
37+ await base . ReconnectionAttemptsExceededTest ( ) ;
38+ }
39+
3440 [ TestMethod ]
3541 public override async Task ManuallyReconnectionTest ( )
3642 {
Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ public override async Task ReconnectingTest()
3131 await base . ReconnectingTest ( ) ;
3232 }
3333
34+ [ TestMethod ]
35+ public override async Task ReconnectionAttemptsExceededTest ( )
36+ {
37+ await base . ReconnectionAttemptsExceededTest ( ) ;
38+ }
39+
3440 [ TestMethod ]
3541 public override async Task ManuallyReconnectionTest ( )
3642 {
Original file line number Diff line number Diff line change @@ -19,6 +19,12 @@ public override async Task ReconnectionTrueTest()
1919 await base . ReconnectionTrueTest ( ) ;
2020 }
2121
22+ [ TestMethod ]
23+ public override async Task ReconnectionAttemptsExceededTest ( )
24+ {
25+ await base . ReconnectionAttemptsExceededTest ( ) ;
26+ }
27+
2228 [ TestMethod ]
2329 public override async Task ReconnectionFalseTest ( )
2430 {
Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ public override async Task ReconnectingTest()
3131 await base . ReconnectingTest ( ) ;
3232 }
3333
34+ [ TestMethod ]
35+ public override async Task ReconnectionAttemptsExceededTest ( )
36+ {
37+ await base . ReconnectionAttemptsExceededTest ( ) ;
38+ }
39+
3440 [ TestMethod ]
3541 public override async Task ManuallyReconnectionTest ( )
3642 {
Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ public override async Task ReconnectingTest()
3131 await base . ReconnectingTest ( ) ;
3232 }
3333
34+ [ TestMethod ]
35+ public override async Task ReconnectionAttemptsExceededTest ( )
36+ {
37+ await base . ReconnectionAttemptsExceededTest ( ) ;
38+ }
39+
3440 [ TestMethod ]
3541 public override async Task ManuallyReconnectionTest ( )
3642 {
Original file line number Diff line number Diff line change 1- namespace SocketIOClient . ConnectInterval
1+ using System ;
2+
3+ namespace SocketIOClient . ConnectInterval
24{
35 class DefaultConnectInterval : IConnectInterval
46 {
57 public DefaultConnectInterval ( SocketIOOptions options )
68 {
79 this . options = options ;
8- delayDouble = options . ReconnectionDelay ;
10+ this . delay = options . ReconnectionDelay ;
911 }
1012
1113 readonly SocketIOOptions options ;
12- double delayDouble ;
14+ private double delay ;
15+ private int attempts = 0 ;
1316
14- public int GetDelay ( )
17+ public double GetDelay ( )
1518 {
16- return ( int ) delayDouble ;
19+ return this . delay ;
1720 }
1821
19- public double NextDealy ( )
22+ public double NextDelay ( )
2023 {
21- delayDouble += 2 * options . RandomizationFactor ;
22- return delayDouble ;
24+ this . delay = options . ReconnectionDelay * ( long ) Math . Pow ( 2 , attempts ++ ) ;
25+
26+ if ( this . options . RandomizationFactor > 0 )
27+ {
28+ Random random = new Random ( ) ;
29+ var deviation = ( long ) Math . Floor ( random . NextDouble ( ) * this . options . RandomizationFactor * options . ReconnectionDelay ) ;
30+ this . delay = ( ( long ) Math . Floor ( random . NextDouble ( ) * 10 ) & 1 ) == 0 ? this . delay - deviation : this . delay + deviation ;
31+ }
32+
33+ return this . delay ;
2334 }
2435 }
2536}
Original file line number Diff line number Diff line change 22{
33 public interface IConnectInterval
44 {
5- int GetDelay ( ) ;
6- double NextDealy ( ) ;
5+ double GetDelay ( ) ;
6+ double NextDelay ( ) ;
77 }
88}
You can’t perform that action at this time.
0 commit comments