Cleanup ClientCancellationAbortsRequest Internal/2771 (#12248)
This commit is contained in:
parent
45d3e69073
commit
4f638f8e11
|
|
@ -366,7 +366,7 @@ namespace Microsoft.AspNetCore.TestHost
|
||||||
public async Task ClientDisposalAbortsRequest()
|
public async Task ClientDisposalAbortsRequest()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
var tcs = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
RequestDelegate appDelegate = async ctx =>
|
RequestDelegate appDelegate = async ctx =>
|
||||||
{
|
{
|
||||||
// Write Headers
|
// Write Headers
|
||||||
|
|
@ -399,30 +399,26 @@ namespace Microsoft.AspNetCore.TestHost
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ClientCancellationAbortsRequest()
|
public async Task ClientCancellationAbortsRequest()
|
||||||
{
|
{
|
||||||
// Arrange
|
var tcs = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
var builder = new WebHostBuilder().Configure(app => app.Run(async ctx =>
|
||||||
RequestDelegate appDelegate = async ctx =>
|
|
||||||
{
|
{
|
||||||
var sem = new SemaphoreSlim(0);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await sem.WaitAsync(ctx.RequestAborted);
|
await Task.Delay(TimeSpan.FromSeconds(30), ctx.RequestAborted);
|
||||||
|
tcs.SetResult(0);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
tcs.SetException(e);
|
tcs.SetException(e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
};
|
throw new InvalidOperationException("The request was not aborted");
|
||||||
|
}));
|
||||||
// Act
|
using var server = new TestServer(builder);
|
||||||
var builder = new WebHostBuilder().Configure(app => app.Run(appDelegate));
|
using var client = server.CreateClient();
|
||||||
var server = new TestServer(builder);
|
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1));
|
||||||
var client = server.CreateClient();
|
|
||||||
var cts = new CancellationTokenSource();
|
|
||||||
cts.CancelAfter(500);
|
|
||||||
var response = await Assert.ThrowsAnyAsync<OperationCanceledException>(() => client.GetAsync("http://localhost:12345", cts.Token));
|
var response = await Assert.ThrowsAnyAsync<OperationCanceledException>(() => client.GetAsync("http://localhost:12345", cts.Token));
|
||||||
|
|
||||||
// Assert
|
|
||||||
var exception = await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await tcs.Task);
|
var exception = await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await tcs.Task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue