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