Skip to content
代码片段 群组 项目
未验证 提交 9e635724 编辑于 作者: Brennan's avatar Brennan 提交者: GitHub
浏览文件

StopAsync resets state on inactive connection (#20083) (#23962)

上级 b8a0fa74
No related branches found
No related tags found
无相关合并请求
......@@ -501,6 +501,11 @@ namespace Microsoft.AspNetCore.SignalR.Client
{
connectionState.Stopping = true;
}
else
{
// Reset StopCts if there isn't an active connection so that the next StartAsync wont immediately fail due to the token being canceled
_state.StopCts = new CancellationTokenSource();
}
if (disposing)
{
......
......@@ -334,6 +334,26 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
});
}
[Fact]
public async Task StopAsyncOnInactiveConnectionDoesNotAffectNextStartAsync()
{
// Regression test:
// If there wasn't an active underlying connection, StopAsync would leave a CTS canceled which would cause the next StartAsync to fail
var testConnection = new TestConnection();
await AsyncUsing(CreateHubConnection(testConnection), async connection =>
{
Assert.Equal(HubConnectionState.Disconnected, connection.State);
await connection.StopAsync().OrTimeout();
Assert.False(testConnection.Disposed.IsCompleted);
Assert.Equal(HubConnectionState.Disconnected, connection.State);
await connection.StartAsync().OrTimeout();
Assert.True(testConnection.Started.IsCompleted);
Assert.Equal(HubConnectionState.Connected, connection.State);
});
}
[Fact]
public async Task CompletingTheTransportSideMarksConnectionAsClosed()
{
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册