File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
tests/SocketIOClient.UnitTests/V2 Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -65,10 +65,16 @@ private Uri ServerUri
6565 public event EventHandler < Exception > OnReconnectError ;
6666
6767 public async Task ConnectAsync ( )
68+ {
69+ await ConnectAsync ( CancellationToken . None ) ;
70+ }
71+
72+ public async Task ConnectAsync ( CancellationToken cancellationToken )
6873 {
6974 var attempts = Options . Reconnection ? Options . ReconnectionAttempts : 1 ;
7075 for ( int i = 0 ; i < attempts ; i ++ )
7176 {
77+ cancellationToken . ThrowIfCancellationRequested ( ) ;
7278 // TODO: IDisposable
7379 var session = SessionFactory . New ( Options . EIO ) ;
7480 using var cts = new CancellationTokenSource ( Options . ConnectionTimeout ) ;
Original file line number Diff line number Diff line change @@ -127,6 +127,22 @@ public async Task ConnectAsync_ConnectedMessageReceived_ConnectedIsTrueIdHasValu
127127 _io . Id . Should ( ) . Be ( "123" ) ;
128128 }
129129
130+ [ Fact ]
131+ public async Task ConnectAsyncCancellationToken_GivenACanceledToken_ThrowConnectionException ( )
132+ {
133+ _session . ConnectAsync ( Arg . Any < CancellationToken > ( ) ) . ThrowsAsync ( new Exception ( "Test" ) ) ;
134+
135+ await _io
136+ . Invoking ( async x =>
137+ {
138+ using var cts = new CancellationTokenSource ( ) ;
139+ await cts . CancelAsync ( ) ;
140+ await x . ConnectAsync ( cts . Token ) ;
141+ } )
142+ . Should ( )
143+ . ThrowAsync < OperationCanceledException > ( ) ;
144+ }
145+
130146 [ Fact ]
131147 public async Task EmitAsync_AckEventAction_PacketIdIncrementBy1 ( )
132148 {
You can’t perform that action at this time.
0 commit comments