Skip to content

Commit 9d4ca49

Browse files
committed
no exception should be thrown when a close message is received
1 parent 1bf28ba commit 9d4ca49

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

src/SocketIOClient/Protocol/WebSocket/WebSocketAdapter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ private async Task ReceiveAsync(CancellationToken cancellationToken)
3737
protocolMessage.Type = ProtocolMessageType.Bytes;
3838
protocolMessage.Bytes = message.Bytes;
3939
break;
40+
case WebSocketMessageType.Close:
41+
return;
4042
}
4143

4244
await OnNextAsync(protocolMessage).ConfigureAwait(false);

tests/SocketIOClient.UnitTests/Protocol/WebSocket/WebSocketAdapterTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ public async Task ReceiveAsync_ExceptionOccurred_OnDisconnectInvoked()
178178
[Fact]
179179
public async Task ReceiveAsync_CloseMessage_OnDisconnectNotInvoked()
180180
{
181+
var observer = Substitute.For<IMyObserver<ProtocolMessage>>();
182+
_wsAdapter.Subscribe(observer);
181183
_clientAdapter.ReceiveAsync(Arg.Any<CancellationToken>())
182184
.Returns(async _ =>
183185
{
@@ -192,6 +194,7 @@ public async Task ReceiveAsync_CloseMessage_OnDisconnectNotInvoked()
192194

193195
await Task.Delay(200).ConfigureAwait(false);
194196
_onDisconnect.DidNotReceive().Invoke();
197+
await observer.DidNotReceive().OnNextAsync(Arg.Any<ProtocolMessage>());
195198
}
196199

197200
[Fact]

0 commit comments

Comments
 (0)