File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
tests/SocketIOClient.UnitTests/V2 Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ private Uri ServerUri
5959 private readonly Dictionary < int , Action < IAckMessage > > _ackHandlers = new ( ) ;
6060 private readonly Dictionary < int , Func < IAckMessage , Task > > _funcHandlers = new ( ) ;
6161 private TaskCompletionSource < Exception > _connCompletionSource = new ( ) ;
62+ private TaskCompletionSource < Exception > _connCompletionSource ;
6263 public SocketIOOptions Options { get ; }
6364 public event EventHandler < Exception > OnReconnectError ;
6465 public event EventHandler OnPing ;
@@ -71,6 +72,7 @@ public async Task ConnectAsync()
7172
7273 public async Task ConnectAsync ( CancellationToken cancellationToken )
7374 {
75+ _connCompletionSource = new TaskCompletionSource < Exception > ( ) ;
7476 _ = ConnectCoreAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
7577 var task = Task . Run ( async ( ) => await _connCompletionSource . Task . ConfigureAwait ( false ) , cancellationToken ) ;
7678 var ex = await task . ConfigureAwait ( false ) ;
Original file line number Diff line number Diff line change @@ -294,4 +294,31 @@ public async Task DisconnectAsync_EverConnected_ClearStatefulData()
294294 _io . Id . Should ( ) . BeNull ( ) ;
295295 _session . Received ( 1 ) . Dispose ( ) ;
296296 }
297+
298+ [ Fact ]
299+ public async Task ConnectAsync_FirstFailedThenSuccess_ConnectedIsTrue ( )
300+ {
301+ _session . ConnectAsync ( Arg . Any < CancellationToken > ( ) ) . ThrowsAsync ( new Exception ( "Test" ) ) ;
302+ await _io
303+ . Invoking ( async x => await x . ConnectAsync ( ) )
304+ . Should ( )
305+ . ThrowAsync < ConnectionException > ( ) ;
306+
307+ _session . ConnectAsync ( Arg . Any < CancellationToken > ( ) ) . Returns ( Task . CompletedTask ) ;
308+ await ConnectAsync ( ) ;
309+
310+ _io . Connected . Should ( ) . BeTrue ( ) ;
311+ }
312+
313+ [ Fact ]
314+ public async Task ConnectAsync_FirstSuccessThenFailed_ThrowConnectionException ( )
315+ {
316+ await ConnectAsync ( ) ;
317+
318+ _session . ConnectAsync ( Arg . Any < CancellationToken > ( ) ) . ThrowsAsync ( new Exception ( "Test" ) ) ;
319+ await _io
320+ . Invoking ( async x => await x . ConnectAsync ( ) )
321+ . Should ( )
322+ . ThrowAsync < ConnectionException > ( ) ;
323+ }
297324}
You can’t perform that action at this time.
0 commit comments