Merge branch 'release/2.1' into release/2.2

This commit is contained in:
Nate McMaster 2019-01-08 10:57:08 -08:00
commit ce548479e1
No known key found for this signature in database
GPG Key ID: A778D9601BD78810
4 changed files with 25 additions and 11 deletions

View File

@ -60,6 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
public async Task RequestBodyReadAsyncCanBeCancelled() public async Task RequestBodyReadAsyncCanBeCancelled()
{ {
var helloTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously); var helloTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
var readTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
using (var server = new TestServer(async context => using (var server = new TestServer(async context =>
@ -81,7 +82,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
try try
{ {
await context.Request.Body.ReadAsync(buffer, 0, 1, cts.Token).DefaultTimeout(); var task = context.Request.Body.ReadAsync(buffer, 0, buffer.Length, cts.Token);
readTcs.TrySetResult(null);
await task;
context.Response.ContentLength = 12; context.Response.ContentLength = 12;
await context.Response.WriteAsync("Read success"); await context.Response.WriteAsync("Read success");
@ -107,12 +110,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
await connection.Send("Hello "); await connection.Send("Hello ");
await helloTcs.Task; await helloTcs.Task;
await readTcs.Task;
// Cancel the body after hello is read // Cancel the body after hello is read
cts.Cancel(); cts.Cancel();
await connection.Send("World");
await connection.Receive($"HTTP/1.1 200 OK", await connection.Receive($"HTTP/1.1 200 OK",
$"Date: {server.Context.DateHeaderValue}", $"Date: {server.Context.DateHeaderValue}",
"Content-Length: 14", "Content-Length: 14",

View File

@ -104,10 +104,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
public async Task ResponseBodyWriteAsyncCanBeCancelled() public async Task ResponseBodyWriteAsyncCanBeCancelled()
{ {
var serviceContext = new TestServiceContext(LoggerFactory); var serviceContext = new TestServiceContext(LoggerFactory);
serviceContext.ServerOptions.Limits.MaxResponseBufferSize = 5;
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
var appTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously); var appTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
var writeStartedTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously); var writeBlockedTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
using (var server = new TestServer(async context => using (var server = new TestServer(async context =>
{ {
@ -115,21 +114,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
{ {
await context.Response.WriteAsync("hello", cts.Token).DefaultTimeout(); await context.Response.WriteAsync("hello", cts.Token).DefaultTimeout();
var task = context.Response.WriteAsync("world", cts.Token); var data = new byte[1024 * 1024 * 10];
Assert.False(task.IsCompleted);
writeStartedTcs.TrySetResult(null); var timerTask = Task.Delay(TimeSpan.FromSeconds(1));
var writeTask = context.Response.Body.WriteAsync(data, 0, data.Length, cts.Token).DefaultTimeout();
var completedTask = await Task.WhenAny(writeTask, timerTask);
await task.DefaultTimeout(); while (completedTask == writeTask)
{
await writeTask;
timerTask = Task.Delay(TimeSpan.FromSeconds(1));
writeTask = context.Response.Body.WriteAsync(data, 0, data.Length, cts.Token).DefaultTimeout();
completedTask = await Task.WhenAny(writeTask, timerTask);
}
writeBlockedTcs.TrySetResult(null);
await writeTask;
} }
catch (Exception ex) catch (Exception ex)
{ {
appTcs.TrySetException(ex); appTcs.TrySetException(ex);
writeBlockedTcs.TrySetException(ex);
} }
finally finally
{ {
appTcs.TrySetResult(null); appTcs.TrySetResult(null);
writeStartedTcs.TrySetCanceled();
} }
}, serviceContext)) }, serviceContext))
{ {
@ -148,7 +158,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
"5", "5",
"hello"); "hello");
await writeStartedTcs.Task.DefaultTimeout(); await writeBlockedTcs.Task.DefaultTimeout();
cts.Cancel(); cts.Cancel();

View File

@ -21,6 +21,7 @@
<Reference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" /> <Reference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" />
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" /> <Reference Include="Microsoft.AspNetCore.Server.Kestrel" />
<Reference Include="Microsoft.Internal.AspNetCore.H2Spec.All" /> <Reference Include="Microsoft.Internal.AspNetCore.H2Spec.All" />
<Reference Include="Microsoft.AspNetCore.Server.Kestrel.Core" />
<Reference Include="Newtonsoft.Json" /> <Reference Include="Newtonsoft.Json" />
<Reference Include="System.Net.Http.WinHttpHandler" /> <Reference Include="System.Net.Http.WinHttpHandler" />
</ItemGroup> </ItemGroup>

View File

@ -19,6 +19,7 @@
<Reference Include="Microsoft.AspNetCore.Server.Kestrel.Https" /> <Reference Include="Microsoft.AspNetCore.Server.Kestrel.Https" />
<Reference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets" /> <Reference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets" />
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" /> <Reference Include="Microsoft.AspNetCore.Server.Kestrel" />
<Reference Include="Microsoft.AspNetCore.Server.Kestrel.Core" />
<Reference Include="Newtonsoft.Json" /> <Reference Include="Newtonsoft.Json" />
<Reference Include="System.Net.Http.WinHttpHandler" /> <Reference Include="System.Net.Http.WinHttpHandler" />
</ItemGroup> </ItemGroup>