Skip to content

Cleanup ClientCancellationAbortsRequest #12248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/Hosting/TestHost/test/TestClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public async Task WebSocketTinyReceiveGeneratesEndOfMessage()
public async Task ClientDisposalAbortsRequest()
{
// Arrange
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
var tcs = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
RequestDelegate appDelegate = async ctx =>
{
// Write Headers
Expand Down Expand Up @@ -399,30 +399,26 @@ public async Task ClientDisposalAbortsRequest()
[Fact]
public async Task ClientCancellationAbortsRequest()
{
// Arrange
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
RequestDelegate appDelegate = async ctx =>
var tcs = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
var builder = new WebHostBuilder().Configure(app => app.Run(async ctx =>
{
var sem = new SemaphoreSlim(0);
try
{
await sem.WaitAsync(ctx.RequestAborted);
await Task.Delay(TimeSpan.FromSeconds(30), ctx.RequestAborted);
tcs.SetResult(0);
}
catch (Exception e)
{
tcs.SetException(e);
return;
}
};

// Act
var builder = new WebHostBuilder().Configure(app => app.Run(appDelegate));
var server = new TestServer(builder);
var client = server.CreateClient();
var cts = new CancellationTokenSource();
cts.CancelAfter(500);
throw new InvalidOperationException("The request was not aborted");
}));
using var server = new TestServer(builder);
using var client = server.CreateClient();
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1));
var response = await Assert.ThrowsAnyAsync<OperationCanceledException>(() => client.GetAsync("http://localhost:12345", cts.Token));

// Assert
var exception = await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await tcs.Task);
}

Expand Down