Unskip and fix race in ConnectionClosedEvenIfAppSwallowsException (#2632)

This commit is contained in:
Stephen Halter 2018-05-31 15:39:25 -07:00 committed by GitHub
parent 7e43d35049
commit 28dad2b2b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 8 deletions

View File

@ -138,7 +138,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
Assert.Contains(TestSink.Writes, w => w.EventId.Id == 33 && w.LogLevel == LogLevel.Information); Assert.Contains(TestSink.Writes, w => w.EventId.Id == 33 && w.LogLevel == LogLevel.Information);
} }
[Fact(Skip="https://github.com/aspnet/KestrelHttpServer/issues/2464")] [Fact]
public async Task ConnectionClosedEvenIfAppSwallowsException() public async Task ConnectionClosedEvenIfAppSwallowsException()
{ {
var gracePeriod = TimeSpan.FromSeconds(5); var gracePeriod = TimeSpan.FromSeconds(5);
@ -149,23 +149,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
DateHeaderValueManager = new DateHeaderValueManager(systemClock) DateHeaderValueManager = new DateHeaderValueManager(systemClock)
}; };
var appRunningEvent = new ManualResetEventSlim(); var appRunningTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
var exceptionSwallowedEvent = new ManualResetEventSlim(); var exceptionSwallowedTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
using (var server = new TestServer(async context => using (var server = new TestServer(async context =>
{ {
context.Features.Get<IHttpMinRequestBodyDataRateFeature>().MinDataRate = context.Features.Get<IHttpMinRequestBodyDataRateFeature>().MinDataRate =
new MinDataRate(bytesPerSecond: 1, gracePeriod: gracePeriod); new MinDataRate(bytesPerSecond: 1, gracePeriod: gracePeriod);
appRunningEvent.Set(); // See comment in RequestTimesOutWhenRequestBodyNotReceivedAtSpecifiedMinimumRate for
// why we call ReadAsync before setting the appRunningEvent.
var readTask = context.Request.Body.ReadAsync(new byte[1], 0, 1);
appRunningTcs.SetResult(null);
try try
{ {
await context.Request.Body.ReadAsync(new byte[1], 0, 1); await readTask;
} }
catch (BadHttpRequestException ex) when (ex.StatusCode == 408) catch (BadHttpRequestException ex) when (ex.StatusCode == 408)
{ {
exceptionSwallowedEvent.Set(); exceptionSwallowedTcs.SetResult(null);
}
catch (Exception ex)
{
exceptionSwallowedTcs.SetException(ex);
} }
var response = "hello, world"; var response = "hello, world";
@ -182,9 +189,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
"", "",
""); "");
Assert.True(appRunningEvent.Wait(TestConstants.DefaultTimeout), "AppRunningEvent timed out."); await appRunningTcs.Task.DefaultTimeout();
systemClock.UtcNow += gracePeriod + TimeSpan.FromSeconds(1); systemClock.UtcNow += gracePeriod + TimeSpan.FromSeconds(1);
Assert.True(exceptionSwallowedEvent.Wait(TestConstants.DefaultTimeout), "ExceptionSwallowedEvent timed out."); await exceptionSwallowedTcs.Task.DefaultTimeout();
await connection.Receive( await connection.Receive(
"HTTP/1.1 200 OK", "HTTP/1.1 200 OK",