Don't start stream if already canceled (#2764)

This commit is contained in:
BrennanConroy 2018-08-08 14:04:05 -07:00 committed by GitHub
parent 186a85b7e0
commit 2265acde78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 12 deletions

View File

@ -420,6 +420,7 @@ namespace Microsoft.AspNetCore.SignalR.Client
{
CheckDisposed();
CheckConnectionActive(nameof(StreamAsChannelCoreAsync));
cancellationToken.ThrowIfCancellationRequested();
var irq = InvocationRequest.Stream(cancellationToken, returnType, _connectionState.GetNextId(), _loggerFactory, this, out channel);
await InvokeStreamCore(methodName, irq, args, cancellationToken);

View File

@ -398,15 +398,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
public async Task StreamDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path)
{
bool ExpectedErrors(WriteContext writeContext)
{
return (writeContext.LoggerName == nameof(Http.Connections.Client.Internal.ServerSentEventsTransport) ||
writeContext.LoggerName == nameof(Http.Connections.Client.Internal.LongPollingTransport)) &&
writeContext.EventId.Name == "ErrorSending";
}
var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(StreamDoesNotStartIfTokenAlreadyCanceled)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(StreamDoesNotStartIfTokenAlreadyCanceled)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
{
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory);
try
@ -416,10 +409,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
var cts = new CancellationTokenSource();
cts.Cancel();
var channel = await connection.StreamAsChannelAsync<int>("Stream", 5, cts.Token).OrTimeout();
await Assert.ThrowsAnyAsync<OperationCanceledException>(() =>
channel.WaitToReadAsync().AsTask().OrTimeout());
await Assert.ThrowsAnyAsync<OperationCanceledException>(() =>connection.StreamAsChannelAsync<int>("Stream", 5, cts.Token).OrTimeout());
}
catch (Exception ex)
{