Added CanCancelStartingConnectionAfterNegotiate (#10432)
This commit is contained in:
parent
c288baf967
commit
9bb59b2ec6
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.IO.Pipelines;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Http.Connections;
|
||||
|
|
@ -380,6 +381,52 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CanCancelStartingConnectionAfterNegotiate()
|
||||
{
|
||||
using (StartVerifiableLog())
|
||||
{
|
||||
// Set up a SyncPoint within Negotiate, so we can verify
|
||||
// that the call has gotten that far
|
||||
var negotiateSyncPoint = new SyncPoint();
|
||||
var testHttpHandler = new TestHttpMessageHandler(autoNegotiate: false);
|
||||
testHttpHandler.OnNegotiate(async (request, cancellationToken) =>
|
||||
{
|
||||
// Wait here for the test code to cancel the "outer" token
|
||||
await negotiateSyncPoint.WaitToContinue();
|
||||
|
||||
// Cancel
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
return ResponseUtils.CreateResponse(HttpStatusCode.OK);
|
||||
});
|
||||
|
||||
await WithConnectionAsync(
|
||||
CreateConnection(testHttpHandler),
|
||||
async (connection) =>
|
||||
{
|
||||
// Kick off StartAsync, but don't wait for it
|
||||
var cts = new CancellationTokenSource();
|
||||
var startTask = connection.StartAsync(cts.Token);
|
||||
|
||||
// Wait for the connection to get to the "WaitToContinue" call above,
|
||||
// which means it has gotten to Negotiate
|
||||
await negotiateSyncPoint.WaitForSyncPoint();
|
||||
|
||||
// Assert that StartAsync has not yet been cancelled
|
||||
Assert.False(startTask.IsCanceled);
|
||||
|
||||
// Cancel StartAsync, then "release" the SyncPoint
|
||||
// so the negotiate handler can keep going
|
||||
cts.Cancel();
|
||||
negotiateSyncPoint.Continue();
|
||||
|
||||
// Assert that StartAsync was cancelled
|
||||
await Assert.ThrowsAsync<OperationCanceledException>(() => startTask);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task AssertDisposedAsync(HttpConnection connection)
|
||||
{
|
||||
var exception =
|
||||
|
|
|
|||
Loading…
Reference in New Issue