Make sure read is async first before cancelling. (#9832)

This commit is contained in:
Justin Kotalik 2019-04-30 08:49:45 -07:00 committed by GitHub
parent caf4374f83
commit ba1f86d5bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 7 deletions

View File

@ -138,7 +138,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
}
[ConditionalFact]
public async Task WriterThrowsCancelledException()
public async Task WriterThrowsCanceledException()
{
var requestStartedCompletionSource = CreateTaskCompletionSource();
var requestCompletedCompletionSource = CreateTaskCompletionSource();
@ -179,10 +179,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
}
[ConditionalFact]
[Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/1798", FlakyOn.All)]
public async Task ReaderThrowsCancelledException()
[Repeat]
public async Task ReaderThrowsCanceledException()
{
var requestStartedCompletionSource = CreateTaskCompletionSource();
var readIsAsyncCompletionSource = CreateTaskCompletionSource();
var requestCompletedCompletionSource = CreateTaskCompletionSource();
Exception exception = null;
@ -191,10 +191,11 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
var data = new byte[1024];
using (var testServer = await TestServer.Create(async ctx =>
{
requestStartedCompletionSource.SetResult(true);
try
{
await ctx.Request.Body.ReadAsync(data, cancellationTokenSource.Token);
var task = ctx.Request.Body.ReadAsync(data, cancellationTokenSource.Token);
readIsAsyncCompletionSource.SetResult(true);
await task;
}
catch (Exception e)
{
@ -207,7 +208,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
using (var connection = testServer.CreateConnection())
{
await SendContentLength1Post(connection);
await requestStartedCompletionSource.Task.DefaultTimeout();
await readIsAsyncCompletionSource.Task.DefaultTimeout();
cancellationTokenSource.Cancel();
await requestCompletedCompletionSource.Task.DefaultTimeout();
}